public Protocol(ProtocolSettings protocolSettings, IConverseCheckSum16 converseCheckSum = null) : base(GlobalSettings.SystemServices, null) { ProtocolSettings = protocolSettings; Type = ProtocolSettings.Type; if (converseCheckSum == null) { if (ProtocolSettings.CheckSum == "ModbusCheckSum16" || ProtocolSettings.CheckSum == "ModbusCRC16") Calculations = new Conversations.ModbusConverseCalculations(); else if (ProtocolSettings.CheckSum == "GrowattCheckSum16") Calculations = new Conversations.GrowattConverseCalculations(); else if (ProtocolSettings.CheckSum == "CRC16") Calculations = new Conversations.CRC16ConverseCalculations(); else if (ProtocolSettings.CheckSum == "CheckSum8") Calculations = new Conversations.FroniusConverseCalculations(); else Calculations = new Conversations.ConverseCalculations(); LogMessage("Protocol", "Using Calculations: " + Calculations.GetType().ToString(), LogEntryType.DetailTrace); } else Calculations = converseCheckSum; LoadConverse(); }
public Converse(IUtilityLog log, IConverseCheckSum16 calculations, int sendGap = 1200) { LastSendTime = DateTime.Today; SendGap = sendGap; UtilityLog = log; Conversations = new List<Conversation>(); Variables = new List<Variable>(); DeviceStream = null; NoTimeout = false; if (calculations == null) { Calculations = (IConverseCheckSum16)new ConverseCalculations(); // LogMessage("Converse", "Using standard Calculations: " + Calculations.GetType().ToString(), LogEntryType.DetailTrace); } else { Calculations = calculations; LogMessage("Converse", "Using custom Calculations: " + Calculations.GetType().ToString(), LogEntryType.DetailTrace); } EndianConverter16Bit = new EndianConverter16Bit(EndianConverter.BigEndian16Bit); EndianConverter32Bit = new EndianConverter32Bit(EndianConverter.BigEndian32Bit); CheckSumEndianConverter16Bit = EndianConverter16Bit; }
public UseVariable(Conversation conversation, String varName, String type = null, int? size = null, bool excludeFromChecksum = false, int messageId = 0) : base(conversation, excludeFromChecksum) { Converse session = conversation.Converse; int? variableSize; Variable = conversation.GetVariable(varName); VariableType = type; variableSize = size; Calculations = session.Calculations; IsChecksum16 = (varName.ToUpper() == "CHECKSUM16"); IsChecksum8 = (varName.ToUpper() == "CHECKSUM8"); IsChecksum = IsChecksum16 || IsChecksum8; if (Variable == null) // variable not defined if (type == null) { Variable = new StringVar(varName, conversation); session.Variables.Add(Variable); } else if (type == "BYTE") { Variable = new ByteVar(varName, variableSize, conversation); session.Variables.Add(Variable); } else if (type == "DYNAMICBYTE") { if (variableSize == null || variableSize < 1) variableSize = 10000; Variable = new DynamicByteVar(varName, variableSize.Value, conversation); session.Variables.Add(Variable); } else if (type == "STRING") { Variable = new StringVar(varName, conversation); session.Variables.Add(Variable); } else throw new Exception("Variable " + varName + " type not supported: " + type); }