using System; using System.Collections.Generic; using System.Linq; using System.Globalization; using System.Windows.Forms; using System.IO.Ports; using static GenesisZeroFlow.GenesisZeroFlow; namespace GenesisZeroFlow { public class CmdInterface { CultureInfo Culture { get; set; } public Byte Gp30LastByte { get; set; } private Byte[] GP30LastRegister { get; set; } public void SetGP30LastRegister(Byte[] data) { GP30LastRegister = data; } private Byte GP30LastPayloadLsb { get; set; } public Byte GP30LastCommand { get; set; } private Byte GP30RXPayload { get; set; } private Boolean GP30RequestStarted { get; set; } private Boolean GP30RequestFailed { get; set; } private Boolean GP30RequestGotAnswer { get; set; } private Byte Privilege { get; set; } private Byte FirstHitLevelUpPath0 { get; set; } private Byte FirstHitLevelUpPath1 { get; set; } private Byte FirstHitLevelUpPath2 { get; set; } private Byte FirstHitLevelDownPath0 { get; set; } private Byte FirstHitLevelDownPath1 { get; set; } private Byte FirstHitLevelDownPath2 { get; set; } private Byte PercentPath0 { get; set; } private Byte PercentPath1 { get; set; } private Byte PercentPath2 { get; set; } private SerialPort Port { get; set; } public Byte Subreason { get; set; } private Byte Starthit { get; set; } private Byte StoreCalibration { get; set; } private Byte Amplitude { get; set; } private Byte Samplerate { get; set; } private UInt16 CalibrationFactorPath0 { get; set; } private UInt16 CalibrationFactorPath1 { get; set; } private UInt16 CalibrationFactorPath2 { get; set; } private Int32 ZeroOffsetPath0 { get; set; } private Int32 ZeroOffsetPath1 { get; set; } private Int32 ZeroOffsetPath2 { get; set; } private Byte LedMode { get; set; } private Byte UpdatePeriode { get; set; } private Byte FirstHitShift { get; set; } private UInt32 ToFTempCalibrate { get; set; } private Int32 ToFTempOffsetPath0 { get; set; } private Int32 ToFTempOffsetPath1 { get; set; } private Int32 ToFTempOffsetPath2 { get; set; } public UInt16 MeterNumber { get; set; } public String MeterIndex { get; set; } public String MeterType { get; private set; } private Byte MeterSize { get; set; } public void Initialize(String meterType, UInt16 meterNumber, CultureInfo culture) { this.GP30LastRegister = new Byte[2] { 0, 0 }; this.GP30LastPayloadLsb = 0; this.GP30LastCommand = 0; this.GP30RXPayload = 0; this.GP30RequestStarted = false; this.GP30RequestFailed = false; this.GP30RequestGotAnswer = false; this.FirstHitLevelUpPath0 = 0; this.FirstHitLevelUpPath1 = 0; this.FirstHitLevelUpPath2 = 0; this.FirstHitLevelDownPath0 = 0; this.FirstHitLevelDownPath1 = 0; this.FirstHitLevelDownPath2 = 0; this.Starthit = 0; this.Amplitude = 0; this.Samplerate = 0; this.CalibrationFactorPath0 = 0; this.CalibrationFactorPath1 = 0; this.CalibrationFactorPath2 = 0; this.ZeroOffsetPath0 = 0; this.ZeroOffsetPath1 = 0; this.ZeroOffsetPath2 = 0; this.LedMode = 0; this.MeterNumber = meterNumber; this.MeterIndex = (meterNumber + 1).ToString(culture); this.Culture = culture; this.Gp30LastByte = 0; this.MeterType = meterType; } public void IndicatorsFailed() { Boolean temp = this.GP30RequestStarted; if (temp) { this.GP30RequestGotAnswer = true; this.GP30RequestFailed = true; this.GP30RequestStarted = false; } } public void IndicatorsReset() { Boolean temp = this.GP30RequestStarted; if (temp) { this.GP30RequestGotAnswer = false; this.GP30RequestFailed = false; this.GP30RequestStarted = false; } } public void IndicatorsOk() { Boolean temp = this.GP30RequestStarted; if (temp) { this.GP30RequestGotAnswer = true; this.GP30RequestFailed = false; this.GP30RequestStarted = false; } } public Int32 RXProcessor(UInt16 requestType) { #region Definitions and initializations UInt16 Timeoutcounter = 0; Int32 ErrCode = GP30LowLevelErrors.NoError; #endregion #region Set flags this.GP30RequestStarted = true; this.GP30RequestFailed = false; this.GP30RequestGotAnswer = false; #endregion try { #region Timeout while (!this.GP30RequestGotAnswer) { Misc.WaitNSeconds(1); Timeoutcounter++; if (Timeoutcounter >= GP30Parameters.Timeout) { // Reset flags this.IndicatorsReset(); return GP30LowLevelErrors.Timeout; // timeout occured } } #endregion #region Failure message ErrCode = GP30LowLevelErrors.NoError; // default if (this.GP30RequestFailed) { switch (requestType) { case GP30RequestType.WriteRegister: ErrCode = GP30LowLevelErrors.SerialPortWriteFailure; break; case GP30RequestType.ReadRegister: ErrCode = GP30LowLevelErrors.SerialPortReadFailure; break; case GP30RequestType.MultipleWrite: ErrCode = GP30LowLevelErrors.SerialPortWriteFailure; break; case GP30RequestType.QueryCaps: ErrCode = GP30LowLevelErrors.SerialPortReadFailure; break; default: ErrCode = GP30LowLevelErrors.Unknown; break; } } #endregion #region Reset flags this.IndicatorsReset(); #endregion } catch (Exception ex) { ErrorLog.Log(LogErrReason.Exeption, "CmdInterface.RxProcessor() failed", $"0x{ex.HResult.ToString("X", this.Culture)}", String.Empty, this.Culture); } #region Return error code return ErrCode; #endregion } public Int32 MultipleWriteRegister(Byte[] gp30Register, Byte[] gp30Data, Boolean double0x5B) { #region To avoid warning if ((gp30Register == null)||(gp30Data == null)) return GP30LowLevelErrors.Unknown; #endregion #region Definitions and initializations Int16 ErrCode = GP30LowLevelErrors.NoError; Byte FirstLevelLengthMsb = 0x00; Byte FirstLevelCrcLsb = 0x00; Byte FirstLevelCrcMsb = 0x00; Byte PasswordNumberOfWritesLsb = 0x00; Byte PasswordNumberOfWritesMsb = 0x00; Byte ZeroPadding = 0; UInt16 FirstLevelCrcResult = 0; #endregion #region Lengthcheck if (gp30Data.Length > Constants.Gp30WriteMultipleMaxLength) { ErrCode = GP30LowLevelErrors.MaxDataLength; return ErrCode; } #endregion #region Prepare and send data try { #region Prepare data #region Number of writes PasswordNumberOfWritesLsb = (Byte)((Int32)gp30Data.Length / 4); if ((gp30Data.Length % 4) != 0) PasswordNumberOfWritesLsb++; #endregion #region Zero padding (Get number of required zeros) if (((Int32)gp30Data.Length % 4) != 0) ZeroPadding = (Byte)(4 - ((Int32)gp30Data.Length % 4)); else ZeroPadding = 0; #endregion #region Prepare CRC input sequences Byte[] FirstLevelByteCrcInput = new Byte[10 + gp30Data.Length + ZeroPadding]; Byte[] FirstLevelByteTx = new Byte[FirstLevelByteCrcInput.Length + 1]; Byte FirstLevelLengthLsb = (Byte)(FirstLevelByteTx.Length - 1); Byte[] Header = new Byte[10] { FirstLevelLengthLsb, FirstLevelLengthMsb, GP30Commands.MultipleWritedata, GP30Commands.Nop, FirstLevelCrcLsb, FirstLevelCrcMsb, gp30Register[1], gp30Register[0], PasswordNumberOfWritesLsb, PasswordNumberOfWritesMsb }; Buffer.BlockCopy(Header, 0, FirstLevelByteCrcInput, 0, Header.Length); Buffer.BlockCopy(gp30Data, 0, FirstLevelByteCrcInput, Header.Length, gp30Data.Length); if (ZeroPadding > 0) { for (Int32 i = 0; i < ZeroPadding; i++) FirstLevelByteCrcInput[10 + gp30Data.Length + i] = 0; } FirstLevelByteTx[0] = GP30Commands.Startbyte; Buffer.BlockCopy(FirstLevelByteCrcInput, 0, FirstLevelByteTx, 1, FirstLevelByteCrcInput.Length); #endregion #endregion #region Calculate CRCs Crc16Ccitt crc = new Crc16Ccitt(InitialCrcValue.Nonzero1); FirstLevelCrcResult = crc.ComputeChecksum(FirstLevelByteCrcInput); FirstLevelCrcMsb = (Byte)(FirstLevelCrcResult >> 8); FirstLevelCrcLsb = (Byte)(FirstLevelCrcResult & 0xFF); FirstLevelByteTx[GP30BytePosition.CrcLsb] = FirstLevelCrcLsb; FirstLevelByteTx[GP30BytePosition.CrcMsb] = FirstLevelCrcMsb; #endregion #region Send data if (Port.IsOpen) { Int32 TotalLength = 0; #region Double 0x5B if (double0x5B) TotalLength = this.Double0x5BGetLength(FirstLevelByteTx); else TotalLength = FirstLevelByteTx.Count(); Byte[] FinalByteTx = new Byte[TotalLength]; if (double0x5B) FinalByteTx = Double0x5B(FirstLevelByteTx); else FinalByteTx = FirstLevelByteTx; #endregion #region Send data Port.Write(FinalByteTx, 0, FinalByteTx.Length); #endregion #region Command memory this.GP30LastCommand = GP30Commands.MultipleWritedata; #endregion } else { #region Error: serial port not open ErrCode = GP30LowLevelErrors.SerialPortClosed; #endregion } #endregion } catch (Exception ex) { #region Error: write to serial port failed ErrorLog.Log(LogErrReason.Exeption, "CmdInterface.MultipleWriteRegister() failed", "0x" + ex.HResult.ToString("X", this.Culture), String.Empty, this.Culture); ErrCode = GP30LowLevelErrors.SerialPortWriteFailure; #endregion } #endregion #region Return error code return ErrCode; #endregion } public Int32 WriteRegister(Byte[] gp30Register, Byte[] gp30Data, Boolean double0x5B) { #region Definitions and initializations Int32 ErrCode = GP30LowLevelErrors.NoError; #endregion #region To avoid warning CA1061 if ((Port == null) || (gp30Register == null)||(gp30Data == null)) return GP30LowLevelErrors.Unknown; #endregion if (gp30Data.Length == 4) { #region Definitions and initializations Byte[] FirstLevelByteTx = new Byte[9 + gp30Data.Length]; Byte FirstLevelLengthLsb = (Byte)(FirstLevelByteTx.Length - 1); Byte FirstLevelLengthMsb = 0x00; Byte FirstLevelCrcLsb = 0x00; Byte FirstLevelCrcMsb = 0x00; UInt16 FirstLevelCrcResult = 0; #endregion #region Prepare data try { #region Fill buffer Byte[] FirstLevelByteCrcInput = new Byte[8 + gp30Data.Length]; Byte[] Header = new Byte[8] { FirstLevelLengthLsb, FirstLevelLengthMsb, GP30Commands.WriteData, GP30Commands.Nop, FirstLevelCrcLsb, FirstLevelCrcMsb, gp30Register[1], gp30Register[0] }; Buffer.BlockCopy(Header, 0, FirstLevelByteCrcInput, 0, Header.Length); Buffer.BlockCopy(gp30Data, 0, FirstLevelByteCrcInput, Header.Length, gp30Data.Length); FirstLevelByteTx[0] = GP30Commands.Startbyte; Buffer.BlockCopy(FirstLevelByteCrcInput, 0, FirstLevelByteTx, 1, FirstLevelByteCrcInput.Length); #endregion #region Calculate CRCs (CCITT) Crc16Ccitt crc = new Crc16Ccitt(InitialCrcValue.Nonzero1); FirstLevelCrcResult = (UInt16)crc.ComputeChecksum(FirstLevelByteCrcInput); FirstLevelCrcMsb = (Byte)(FirstLevelCrcResult >> 8); FirstLevelCrcLsb = (Byte)(FirstLevelCrcResult & 0xFF); FirstLevelByteTx[GP30BytePosition.CrcLsb] = FirstLevelCrcLsb; FirstLevelByteTx[GP30BytePosition.CrcMsb] = FirstLevelCrcMsb; #endregion } catch (Exception ex) { #region Error: CRC calculation ErrorLog.Log(LogErrReason.Exeption, "CmdInterface.WriteRegister()/'Prepare data' failed", $"0x{ex.HResult.ToString("X", this.Culture)}", $"{String.Empty}\n", this.Culture); ErrCode = GP30LowLevelErrors.CrcCalcError; return ErrCode; #endregion } #endregion #region Send data try { if (Port.IsOpen) { Int32 TotalLength = 0; #region Double 0x5B if (double0x5B) TotalLength = Double0x5BGetLength(FirstLevelByteTx); else TotalLength = FirstLevelByteTx.Count(); Byte[] FinalByteTx = new Byte[TotalLength]; if (double0x5B) FinalByteTx = Double0x5B(FirstLevelByteTx); else FinalByteTx = FirstLevelByteTx; #endregion #region Command memory this.GP30LastCommand = GP30Commands.WriteData; this.GP30LastPayloadLsb = gp30Data[0]; this.GP30LastRegister = gp30Register; #endregion #region Send data Port.Write(FinalByteTx, 0, FinalByteTx.Length); #endregion } else { #region Error: serial port closed ErrCode = GP30LowLevelErrors.SerialPortClosed; #endregion } } catch (Exception ex) { #region Error: write to serial port failed ErrorLog.Log(LogErrReason.Exeption, "CmdInterface.WriteRegister()/'Send data' failed", $"0x{ex.HResult.ToString("X", this.Culture)}", String.Empty, this.Culture); ErrCode = GP30LowLevelErrors.SerialPortWriteFailure; #endregion } #endregion } else { #region Error: max. length ErrCode = GP30LowLevelErrors.MaxDataLength; #endregion } return ErrCode; } public Int32 ReadRegister(Byte[] register) { #region Definitions and initializations Int16 ErrCode = GP30LowLevelErrors.NoError; Byte[] FirstLevelByteTx = new Byte[13] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; Byte FirstLevelLengthLsb = (Byte)(FirstLevelByteTx.Length - 1); Byte FirstLevelLengthMsb = 0x00; Byte FirstLevelCrcLsb = 0x00; Byte FirstLevelCrcMsb = 0x00; UInt16 FirstLevelCrcResult = 0; #endregion #region CA1062 if (register == null) return GP30LowLevelErrors.Unknown; #endregion #region Prepare data try { #region Fill buffer Byte[] FirstLevelByteCrcInput = new Byte[12] { FirstLevelLengthLsb, FirstLevelLengthMsb, GP30Commands.ReadData, GP30Commands.Nop, FirstLevelCrcLsb, FirstLevelCrcMsb, register[1], register[0], 0, 0, 0, 0 }; FirstLevelByteTx[0] = GP30Commands.Startbyte; Buffer.BlockCopy(FirstLevelByteCrcInput, 0, FirstLevelByteTx, 1, FirstLevelByteCrcInput.Length); #endregion #region Calculate CRCs (CCITT) Crc16Ccitt crc = new Crc16Ccitt(InitialCrcValue.Nonzero1); FirstLevelCrcResult = (UInt16)crc.ComputeChecksum(FirstLevelByteCrcInput); FirstLevelCrcMsb = (Byte)(FirstLevelCrcResult >> 8); FirstLevelCrcLsb = (Byte)(FirstLevelCrcResult & 0xFF); FirstLevelByteTx[GP30BytePosition.CrcLsb] = FirstLevelCrcLsb; FirstLevelByteTx[GP30BytePosition.CrcMsb] = FirstLevelCrcMsb; #endregion } catch (Exception ex) { #region Error: CRC calculation ErrorLog.Log(LogErrReason.Exeption, "CmdInterface.ReadRegister()/ 'CRC calc' failed", $"0x{ex.HResult.ToString("X", this.Culture)}", String.Empty, this.Culture); ErrCode = GP30LowLevelErrors.CrcCalcError; return ErrCode; #endregion } #endregion #region Send data try { if (Port.IsOpen) { #region Command memory this.GP30LastCommand = GP30Commands.ReadData; this.GP30LastRegister = register; #endregion #region Send data Port.Write(FirstLevelByteTx, 0, FirstLevelByteTx.Length); #endregion } else { #region Error ErrCode = GP30LowLevelErrors.SerialPortClosed; #endregion } } catch (Exception ex) { #region Error ErrorLog.Log(LogErrReason.Exeption, "Gp30ReadRegister()/ 'Send data' failed", $"0x{ex.HResult.ToString("X", this.Culture)}", String.Empty, this.Culture); ErrCode = GP30LowLevelErrors.SerialPortWriteFailure; #endregion } #endregion #region Return error code return ErrCode; #endregion } public String LowLevelMessages(Int32 failureCode, out Boolean ok) { String Message = String.Empty; ok = false; switch (failureCode) { case GP30LowLevelErrors.NoError: Message = "Action successful"; ok = true; break; case GP30LowLevelErrors.SerialPortClosed: Message = "Serial Port is not open"; break; case GP30LowLevelErrors.SerialPortWriteFailure: Message = "Write to serial port failed"; break; case GP30LowLevelErrors.SerialPortReadFailure: Message = "Read from serial port failed"; break; case GP30LowLevelErrors.MaxDataLength: Message = "Datalength error"; break; case GP30LowLevelErrors.Exception: Message = "Internal exception"; break; case GP30LowLevelErrors.CrcCalcError: Message = "CRC error"; break; case GP30LowLevelErrors.Unknown: Message = "Unknown"; break; case GP30LowLevelErrors.Timeout: Message = "Timeout"; break; default: Message = "Unknown error code"; break; } return Message; } public String ReplyCommand(List rxStringCommandChannel) { String Data = String.Empty; try { switch (rxStringCommandChannel.ElementAt(GP30BytePosition.Cmd)) { case GP30Commands.ReadDataReply: Data = $"{Data}COMMAND CHANNEL:\t RX-Command 'READ_DATA_REPLY' at METER{this.MeterIndex}\n"; break; case GP30Commands.WriteDataReply: Data = $"{Data}COMMAND CHANNEL:\t RX-Command 'WRITE_DATA_REPLY' at METER{this.MeterIndex}\n"; break; case GP30Commands.MultipleReaddataReply: Data = $"{Data}COMMAND CHANNEL:\t RX-Command 'MULTIPLE_READ_DATA_REPLY' at METER{this.MeterIndex}\n"; break; case GP30Commands.MultipleWritedataReply: Data = $"{Data}COMMAND CHANNEL:\t RX-Command 'MULTIPLE_WRITE_DATA_REPLY at METER{this.MeterIndex}\n"; break; case GP30Commands.SetLevelreply: Data = $"{Data}COMMAND CHANNEL:\t RX-Command 'SET_LEVEL_REPLY' at METER{this.MeterIndex}\n"; break; case GP30Commands.QueryCapsReply: #region Command Data = $"COMMAND CHANNEL:\t RX-Command 'QUERY_CAPS_REPLY' at METER{this.MeterIndex}\n"; #endregion #region CRC Data = $"{Data}CRC = 0x{rxStringCommandChannel.ElementAt(4).ToString("X", this.Culture)}{rxStringCommandChannel.ElementAt(5).ToString("X", this.Culture)}\n"; #endregion #region Bitrate if ((Byte.Equals(rxStringCommandChannel.ElementAt(GP30BytePosition.CmdBitrateMsb), GP30Payload.GetBitrateMsb)) && (Byte.Equals(rxStringCommandChannel.ElementAt(GP30BytePosition.CmdBitrateLsb), GP30Payload.GetBitrateLsb))) { Data = $"{Data}\nSupported Bitrates: \n"; if ((rxStringCommandChannel.ElementAt(GP30BytePosition.BitrateLsb) & 0x01) != 0) Data = $"{Data}300kbps "; if (((rxStringCommandChannel.ElementAt(GP30BytePosition.BitrateLsb) >> 1) & 0x01) != 0) Data = $"{Data}1200kbps "; if (((rxStringCommandChannel.ElementAt(GP30BytePosition.BitrateLsb) >> 2) & 0x01) != 0) Data = $"{Data}2400kbps "; if (((rxStringCommandChannel.ElementAt(GP30BytePosition.BitrateLsb) >> 3) & 0x01) != 0) Data = $"{Data}4800kbps "; if (((rxStringCommandChannel.ElementAt(GP30BytePosition.BitrateLsb) >> 4) & 0x01) != 0) Data = $"{Data}9600kbps "; if (((rxStringCommandChannel.ElementAt(GP30BytePosition.BitrateLsb) >> 5) & 0x01) != 0) Data = $"{Data}19200kbps "; if (((rxStringCommandChannel.ElementAt(GP30BytePosition.BitrateLsb) >> 6) & 0x01) != 0) Data = $"{Data}38400kbps "; if (((rxStringCommandChannel.ElementAt(GP30BytePosition.BitrateLsb) >> 7) & 0x01) != 0) Data = $"{Data}57600kbps "; if ((rxStringCommandChannel.ElementAt(GP30BytePosition.BitrateMsb) & 0x01) != 0) Data = $"{Data}115200kbps "; if (((rxStringCommandChannel.ElementAt(GP30BytePosition.BitrateMsb) >> 1) & 0x01) != 0) Data = $"{Data}230400kbps "; if (((rxStringCommandChannel.ElementAt(GP30BytePosition.BitrateMsb) >> 2) & 0x01) != 0) Data = $"{Data}460800kbps "; if (((rxStringCommandChannel.ElementAt(GP30BytePosition.BitrateMsb) >> 3) & 0x01) != 0) Data = $"{Data}921600kbps "; } #endregion #region Packet size if ((rxStringCommandChannel.ElementAt(GP30BytePosition.CmdPacketSizeMsb) == GP30Payload.GetPacketSizesMsb) && (rxStringCommandChannel.ElementAt(GP30BytePosition.CmdPacketSizeLsb) == GP30Payload.GetPacketSizesLsb)) { Data = Data + "\nSupported Packet Sizes: \n"; if (((rxStringCommandChannel.ElementAt(GP30BytePosition.PacketSizeLsb) >> 5) & 0x01) != 0) Data = $"{Data}16 "; if (((rxStringCommandChannel.ElementAt(GP30BytePosition.PacketSizeLsb) >> 6) & 0x01) != 0) Data = $"{Data}64 "; if (((rxStringCommandChannel.ElementAt(GP30BytePosition.PacketSizeLsb) >> 7) & 0x01) != 0) Data = $"{Data}[TBD] "; // Documentation scrappy if ((rxStringCommandChannel.ElementAt(GP30BytePosition.PacketSizeMsb) & 0x01) != 0) Data = $"{Data}[TBD] "; // Documentation scrappy if (((rxStringCommandChannel.ElementAt(GP30BytePosition.PacketSizeMsb) >> 1) & 0x01) != 0) Data = $"{Data}[TBD] "; // Documentation scrappy if (((rxStringCommandChannel.ElementAt(GP30BytePosition.PacketSizeMsb) >> 2) & 0x01) != 0) Data = $"{Data}[TBD] "; // Documentation scrappy if (((rxStringCommandChannel.ElementAt(GP30BytePosition.PacketSizeMsb) >> 3) & 0x01) != 0) Data = $"{Data}[TBD] "; // Documentation scrappy if (((rxStringCommandChannel.ElementAt(GP30BytePosition.PacketSizeMsb) >> 4) & 0x01) != 0) Data = $"{Data}[TBD] "; // Documentation scrappy if (((rxStringCommandChannel.ElementAt(GP30BytePosition.PacketSizeMsb) >> 5) & 0x01) != 0) Data = $"{Data}[TBD] "; // Documentation scrappy if (((rxStringCommandChannel.ElementAt(GP30BytePosition.PacketSizeMsb) >> 6) & 0x01) != 0) Data = $"{Data}[TBD] "; // Documentation scrappy if (((rxStringCommandChannel.ElementAt(GP30BytePosition.PacketSizeMsb) >> 7) & 0x01) != 0) Data = $"{Data}32768 "; } #endregion #region Protocol version if ((rxStringCommandChannel.ElementAt(GP30BytePosition.CmdProtocolMsb) == GP30Payload.GetProtocolMsb) && (rxStringCommandChannel.ElementAt(GP30BytePosition.CmdProtocolLsb) == GP30Payload.GetProtocolLsb)) { UInt16 ProtocolBeforeDecimal = (UInt16)((rxStringCommandChannel.ElementAt(GP30BytePosition.CmdProtocolMsb + 1) << 8) + (rxStringCommandChannel.ElementAt(GP30BytePosition.CmdProtocolMsb + 2))); Double ProtocolAfterDecimal = ((Double)((rxStringCommandChannel.ElementAt(GP30BytePosition.CmdProtocolMsb + 3) << 8) + (rxStringCommandChannel.ElementAt(GP30BytePosition.CmdProtocolMsb + 4)))) / 65536; Data = $"{Data}\nProtocol version: \n"; Data = $"{Data}{ProtocolBeforeDecimal.ToString(this.Culture)}.{ProtocolAfterDecimal}"; } #endregion break; case GP30Commands.SetCapsReply: #region Command Data = $"{Data}COMMAND CHANNEL:\t RX-Command 'SET_CAPS_REPLY' at {this.MeterType}{this.MeterIndex}\n"; #endregion #region CRC Data = $"{Data}CRC = 0x{rxStringCommandChannel.ElementAt(4).ToString("X2", this.Culture)}{rxStringCommandChannel.ElementAt(5).ToString("X2", this.Culture)}\n"; #endregion #region Bitrate if ((rxStringCommandChannel.ElementAt(GP30BytePosition.CmdBitrateMsb) == GP30Payload.GetBitrateMsb) && (rxStringCommandChannel.ElementAt(GP30BytePosition.CmdBitrateLsb) == GP30Payload.GetBitrateLsb)) { Data = Data + "\nSupported Bitrates: \n"; if ((rxStringCommandChannel.ElementAt(GP30BytePosition.BitrateLsb) & 0x01) != 0) Data = Data + "300kbps "; if (((rxStringCommandChannel.ElementAt(GP30BytePosition.BitrateLsb) >> 1) & 0x01) != 0) Data = Data + "1200kbps "; if (((rxStringCommandChannel.ElementAt(GP30BytePosition.BitrateLsb) >> 2) & 0x01) != 0) Data = Data + "2400kbps "; if (((rxStringCommandChannel.ElementAt(GP30BytePosition.BitrateLsb) >> 3) & 0x01) != 0) Data = Data + "4800kbps "; if (((rxStringCommandChannel.ElementAt(GP30BytePosition.BitrateLsb) >> 4) & 0x01) != 0) Data = Data + "9600kbps "; if (((rxStringCommandChannel.ElementAt(GP30BytePosition.BitrateLsb) >> 5) & 0x01) != 0) Data = Data + "19200kbps "; if (((rxStringCommandChannel.ElementAt(GP30BytePosition.BitrateLsb) >> 6) & 0x01) != 0) Data = Data + "38400kbps "; if (((rxStringCommandChannel.ElementAt(GP30BytePosition.BitrateLsb) >> 7) & 0x01) != 0) Data = Data + "57600kbps "; if ((rxStringCommandChannel.ElementAt(GP30BytePosition.BitrateMsb) & 0x01) != 0) Data = Data + "115200kbps "; if (((rxStringCommandChannel.ElementAt(GP30BytePosition.BitrateMsb) >> 1) & 0x01) != 0) Data = Data + "230400kbps "; if (((rxStringCommandChannel.ElementAt(GP30BytePosition.BitrateMsb) >> 2) & 0x01) != 0) Data = Data + "460800kbps "; if (((rxStringCommandChannel.ElementAt(GP30BytePosition.BitrateMsb) >> 3) & 0x01) != 0) Data = Data + "921600kbps "; } #endregion #region Packet size if ((rxStringCommandChannel.ElementAt(GP30BytePosition.CmdPacketSizeMsb) == GP30Payload.GetPacketSizesMsb) && (rxStringCommandChannel.ElementAt(GP30BytePosition.CmdPacketSizeLsb) == GP30Payload.GetPacketSizesLsb)) { Data = Data + "\nSupported Packet Sizes: \n"; if (((rxStringCommandChannel.ElementAt(GP30BytePosition.PacketSizeLsb) >> 5) & 0x01) != 0) Data = Data + "16 "; if (((rxStringCommandChannel.ElementAt(GP30BytePosition.PacketSizeLsb) >> 6) & 0x01) != 0) Data = Data + "64 "; if (((rxStringCommandChannel.ElementAt(GP30BytePosition.PacketSizeLsb) >> 7) & 0x01) != 0) Data = Data + "[TBD] "; if ((rxStringCommandChannel.ElementAt(GP30BytePosition.PacketSizeMsb) & 0x01) != 0) Data = Data + "[TBD] "; if (((rxStringCommandChannel.ElementAt(GP30BytePosition.PacketSizeMsb) >> 1) & 0x01) != 0) Data = Data + "[TBD] "; if (((rxStringCommandChannel.ElementAt(GP30BytePosition.PacketSizeMsb) >> 2) & 0x01) != 0) Data = Data + "[TBD] "; if (((rxStringCommandChannel.ElementAt(GP30BytePosition.PacketSizeMsb) >> 3) & 0x01) != 0) Data = Data + "[TBD] "; if (((rxStringCommandChannel.ElementAt(GP30BytePosition.PacketSizeMsb) >> 4) & 0x01) != 0) Data = Data + "[TBD] "; if (((rxStringCommandChannel.ElementAt(GP30BytePosition.PacketSizeMsb) >> 5) & 0x01) != 0) Data = Data + "[TBD] "; if (((rxStringCommandChannel.ElementAt(GP30BytePosition.PacketSizeMsb) >> 6) & 0x01) != 0) Data = Data + "[TBD] "; if (((rxStringCommandChannel.ElementAt(GP30BytePosition.PacketSizeMsb) >> 7) & 0x01) != 0) Data = Data + "32768 "; } #endregion #region Protocol version if ((Byte.Equals(rxStringCommandChannel.ElementAt(GP30BytePosition.CmdProtocolMsb), GP30Payload.GetProtocolMsb)) && (rxStringCommandChannel.ElementAt(GP30BytePosition.CmdProtocolLsb) == GP30Payload.GetProtocolLsb)) { UInt16 ProtocolBeforeDecimal = (UInt16)((rxStringCommandChannel.ElementAt(GP30BytePosition.CmdProtocolMsb + 1) << 8) + (rxStringCommandChannel.ElementAt(GP30BytePosition.CmdProtocolMsb + 2))); Double ProtocolAfterDecimal = ((Double)((rxStringCommandChannel.ElementAt(GP30BytePosition.CmdProtocolMsb + 3) << 8) + (rxStringCommandChannel.ElementAt(GP30BytePosition.CmdProtocolMsb + 4)))) / 65536; Data = $"{Data}\nProtocol version: \n"; Data = $"{Data}{ProtocolBeforeDecimal.ToString(this.Culture)}.{ProtocolAfterDecimal}"; } #endregion break; case GP30Commands.TrainReply: Data = $"{Data}COMMAND CHANNEL:\t RX-Command 'TRAIN_REPLY' at METER{this.MeterIndex}\n"; break; case GP30Commands.RepeatLastReply: Data = $"{Data}COMMAND CHANNEL:\t RX-Command 'REPEAT_LAST_REPLY' at METER{this.MeterIndex}\n"; break; default: Data = $"{Data}COMMAND CHANNEL:\t RX-Command unexpected command: 0x{rxStringCommandChannel.ElementAt(2).ToString("X2", this.Culture)} at METER{this.MeterIndex}\n"; break; } } catch (Exception ex) { ErrorLog.Log(LogErrReason.Exeption, $"CmdInterface{this.MeterIndex}.ReplyCommand() failed", $"0x{ex.HResult.ToString("X", this.Culture)}", String.Empty, this.Culture); } return Data; } private String WriteDataResponse(List rxStringCommandChannel) { #region Definitions and initializations String Message = String.Empty; String Where = "Beginning"; #endregion try { #region Percentage PATH0 if (Enumerable.SequenceEqual(this.GP30LastRegister, GP30Registers.FirstHitLevelPercentagePath0())) { Where = "Percentage PATH0"; this.PercentPath0 = rxStringCommandChannel.ElementAt(GP30BytePosition.Reply); Message = $"COMMAND CHANNEL:\t Received response on write to 'Percentage'-register, PATH1 = {this.PercentPath0.ToString(this.Culture)} at METER{this.MeterIndex}\n"; return Message; } #endregion #region Percentage PATH1 if (Enumerable.SequenceEqual(this.GP30LastRegister, GP30Registers.FirstHitLevelPercentagePath1())) { Where = "Percentage PATH1"; this.PercentPath1 = rxStringCommandChannel.ElementAt(GP30BytePosition.Reply); Message = $"COMMAND CHANNEL:\t Received response on write to 'Percentage'-register, PATH2 = {this.PercentPath1.ToString(this.Culture)} at METER{this.MeterIndex}\n"; return Message; } #endregion #region Percentage PATH2 if (Enumerable.SequenceEqual(this.GP30LastRegister, GP30Registers.FirstHitLevelPercentagePath2())) { Where = "Percentage PATH2"; this.PercentPath2 = rxStringCommandChannel.ElementAt(GP30BytePosition.Reply); Message = $"COMMAND CHANNEL:\t Received response on write to 'Percentage'-register, PATH3 = {this.PercentPath2.ToString(this.Culture)} at METER{this.MeterIndex}\n"; return Message; } #endregion #region Privilege register if (Enumerable.SequenceEqual(this.GP30LastRegister, GP30Registers.Privilege())) { Where = "Privilege"; this.Privilege = rxStringCommandChannel.ElementAt(GP30BytePosition.Reply); Message = $"COMMAND CHANNEL:\t Received response on write to 'Privilege'-register = {this.Privilege.ToString(this.Culture)} at METER{this.MeterIndex}\n"; return Message; } #endregion #region Starthit if (Enumerable.SequenceEqual(this.GP30LastRegister, GP30Registers.StartHit())) { Where = "Starthit"; this.Starthit = rxStringCommandChannel.ElementAt(GP30BytePosition.Reply); Message = $"COMMAND CHANNEL:\t Received response on write to 'Starthit'-register = 0x{this.Starthit.ToString("X2", this.Culture)} at METER{this.MeterIndex}\n"; return Message; } #endregion #region Amplitude end detect if (Enumerable.SequenceEqual(this.GP30LastRegister, GP30Registers.AmplitudePeakDetectEnd())) { Where = "Amplitude"; this.Amplitude = rxStringCommandChannel.ElementAt(GP30BytePosition.Reply); Message = $"COMMAND CHANNEL:\t Received response on write to 'Amplitude peak detect end'-register = 0x{this.Amplitude.ToString("X2", this.Culture)} at METER{this.MeterIndex}\n"; return Message; } #endregion #region Store calibration if (Enumerable.SequenceEqual(this.GP30LastRegister, GP30Registers.StoreCalibration())) { Where = "Store calibration"; this.StoreCalibration = rxStringCommandChannel.ElementAt(GP30BytePosition.Reply); Message = $"COMMAND CHANNEL:\t Received response on write to 'Store calibration'-register = {this.StoreCalibration.ToString(this.Culture)} at METER{this.MeterIndex}\n"; return Message; } #endregion #region First hit update periode if (Enumerable.SequenceEqual(this.GP30LastRegister, GP30Registers.FirstHitUpdatePeriod())) { Where = "First hit update periode"; this.UpdatePeriode= rxStringCommandChannel.ElementAt(GP30BytePosition.Reply); Message = $"COMMAND CHANNEL:\t Received response on write to 'Firsthit update period'-register = {UpdatePeriode.ToString(this.Culture)} at METER{this.MeterIndex}\n"; return Message; } #endregion #region First hit shift if (Enumerable.SequenceEqual(this.GP30LastRegister, GP30Registers.FirstHitShift())) { Where = "First hit shift"; this.FirstHitShift = rxStringCommandChannel.ElementAt(GP30BytePosition.Reply); Message = $"COMMAND CHANNEL:\t Received response on write to 'Firsthit shift'-register = {this.FirstHitShift.ToString(this.Culture)} at METER{this.MeterIndex}\n"; return Message; } #endregion #region Calibration factor PATH0 if (Enumerable.SequenceEqual(this.GP30LastRegister, GP30Registers.CalFactor1())) { Where = "Calibration factor PATH0"; Byte[] TempArray = new Byte[2]; TempArray = rxStringCommandChannel.GetRange(GP30BytePosition.Reply, 2).ToArray(); TempArray.Reverse(); this.CalibrationFactorPath0 = BitConverter.ToUInt16(TempArray, 0); Message = $"COMMAND CHANNEL:\t Received response on write to 'Calibration factor1'-register = 0x{CalibrationFactorPath0.ToString("X4", this.Culture)} at METER{this.MeterIndex}\n"; return Message; } #endregion #region Calibration factor PATH1 if (Enumerable.SequenceEqual(this.GP30LastRegister, GP30Registers.CalFactor2())) { Where = "Calibration factor PATH1"; Byte[] TempArray = new Byte[2]; TempArray = rxStringCommandChannel.GetRange(GP30BytePosition.Reply, 2).ToArray(); TempArray.Reverse(); this.CalibrationFactorPath1 = BitConverter.ToUInt16(TempArray, 0); Message = $"COMMAND CHANNEL:\t Received response on write to 'Calibration factor2'-register = 0x{CalibrationFactorPath1.ToString("X4", this.Culture)} at METER{this.MeterIndex}\n"; return Message; } #endregion #region Calibration factor PATH2 if (Enumerable.SequenceEqual(this.GP30LastRegister, GP30Registers.CalFactor3())) { Where = "Calibration factor PATH2"; Byte[] TempArray = new Byte[2]; TempArray = rxStringCommandChannel.GetRange(GP30BytePosition.Reply, 2).ToArray(); TempArray.Reverse(); this.CalibrationFactorPath2 = BitConverter.ToUInt16(TempArray, 0); Message = $"COMMAND CHANNEL:\t Received response on write to 'Calibration factor3'-register = 0x{CalibrationFactorPath2.ToString("X4", this.Culture)} at METER{this.MeterIndex}\n"; return Message; } #endregion #region Zero offset PATH0 if (Enumerable.SequenceEqual(this.GP30LastRegister, GP30Registers.ZeroOffset1())) { Where = "Zero offset PATH0"; Byte[] TempArray = new Byte[4]; TempArray = rxStringCommandChannel.GetRange(GP30BytePosition.Reply, 4).ToArray(); TempArray.Reverse(); this.ZeroOffsetPath0 = BitConverter.ToInt32(TempArray, 0); Message = $"COMMAND CHANNEL:\t Received response on write to 'Zero offset1'-register = 0x{ZeroOffsetPath0.ToString("X8", this.Culture)} at METER{this.MeterIndex}\n"; return Message; } #endregion #region Zero offset PATH1 if (Enumerable.SequenceEqual(this.GP30LastRegister, GP30Registers.ZeroOffset2())) { Where = "Zero offset PATH"; Byte[] TempArray = new Byte[4]; TempArray = rxStringCommandChannel.GetRange(GP30BytePosition.Reply, 4).ToArray(); TempArray.Reverse(); this.ZeroOffsetPath1 = BitConverter.ToInt32(TempArray, 0); Message = $"COMMAND CHANNEL:\t Received response on write to 'Zero offset2'-register = 0x{ZeroOffsetPath1.ToString("X8", this.Culture)} at METER{this.MeterIndex}\n"; return Message; } #endregion #region Zero offset PATH2 if (Enumerable.SequenceEqual(this.GP30LastRegister, GP30Registers.ZeroOffset3())) { Where = "Zero offset PATH2"; Byte[] TempArray = new Byte[4]; TempArray = rxStringCommandChannel.GetRange(GP30BytePosition.Reply, 4).ToArray(); TempArray.Reverse(); this.ZeroOffsetPath2 = BitConverter.ToInt32(TempArray, 0); Message = $"COMMAND CHANNEL:\t Received response on write to 'Zero offset3'-register = 0x{this.ZeroOffsetPath2.ToString("X8", this.Culture)} at METER{this.MeterIndex}\n"; return Message; } #endregion #region Samplerate if (Enumerable.SequenceEqual(this.GP30LastRegister, GP30Registers.Samplerate())) { Where = "Samplerate"; this.Samplerate = rxStringCommandChannel.ElementAt(GP30BytePosition.Reply); Message = $"COMMAND CHANNEL:\t Received response on write to 'Samplerate'-register = {this.Samplerate.ToString(this.Culture)} at METER{this.MeterIndex}\n"; return Message; } #endregion #region Metersize if (Enumerable.SequenceEqual(this.GP30LastRegister, GP30Registers.MeterSize())) { Where = "Metersize"; this.MeterSize = rxStringCommandChannel.ElementAt(GP30BytePosition.Reply); Message = $"COMMAND CHANNEL:\t Received response on write to 'Metersize'-register = {this.MeterSize.ToString(this.Culture)} at METER{this.MeterIndex}\n"; return Message; } #endregion #region LED Mode if (Enumerable.SequenceEqual(this.GP30LastRegister, GP30Registers.LedMode())) { Where = "LED Mode"; this.LedMode = rxStringCommandChannel.ElementAt(GP30BytePosition.Reply); Message = $"COMMAND CHANNEL:\t Received response on write to 'LED-Mode'-register = {LedMode.ToString(this.Culture)} at METER{this.MeterIndex}\n"; return Message; } #endregion #region ToFTempCalibrate if (Enumerable.SequenceEqual(this.GP30LastRegister, GP30Registers.ToFTempCalibrate())) { Where = "ToFTempCalibrate"; Byte[] TempArray = new Byte[4]; TempArray = rxStringCommandChannel.GetRange(GP30BytePosition.Reply, 4).ToArray(); TempArray.Reverse(); this.ToFTempCalibrate = BitConverter.ToUInt32(TempArray, 0); Message = $"COMMAND CHANNEL:\t Received response on write to 'ToFTempCalibrate'-register = 0x{ToFTempCalibrate.ToString("X8", this.Culture)} at METER{this.MeterIndex}\n"; return Message; } #endregion } catch (Exception ex) { ErrorLog.Log(LogErrReason.Exeption, $"CmdInterface{this.MeterIndex}.WriteDataResponse() failed", $"0x{ex.HResult.ToString("X", this.Culture)}", Where, this.Culture); } return Message; } private String ReadDataResponse(List rxStringCommandChannel) { #region Declarations and initializations String Message = String.Empty; String Where = "Beginning"; #endregion try { #region Percentage PATH0 if (Enumerable.SequenceEqual(GP30LastRegister, GP30Registers.FirstHitLevelPercentagePath0())) { Where = "Percentage PATH0"; this.PercentPath0 = rxStringCommandChannel.ElementAt(GP30BytePosition.Reply); Message = $"COMMAND CHANNEL:\t Received response on read 'Percentage1'-register = {this.PercentPath0.ToString(this.Culture)} at METER{this.MeterIndex}\n"; GenesisZeroFlow._GenesisZeroFlow.SetFirstHitPercentage(this.MeterNumber, Constants.PATH0, this.PercentPath0); return Message; } #endregion #region Percentage PATH1 if (Enumerable.SequenceEqual(GP30LastRegister, GP30Registers.FirstHitLevelPercentagePath1())) { Where = "Percentage PATH1"; this.PercentPath1 = rxStringCommandChannel.ElementAt(GP30BytePosition.Reply); Message = $"COMMAND CHANNEL:\t Received response on read 'Percentage2'-register = {this.PercentPath1.ToString(this.Culture)} at METER{this.MeterIndex}\n"; GenesisZeroFlow._GenesisZeroFlow.SetFirstHitPercentage(this.MeterNumber, Constants.PATH1, this.PercentPath1); return Message; } #endregion #region Percentage PATH2 if (Enumerable.SequenceEqual(GP30LastRegister, GP30Registers.FirstHitLevelPercentagePath2())) { Where = "Percentage PATH2"; this.PercentPath2 = rxStringCommandChannel.ElementAt(GP30BytePosition.Reply); Message = $"COMMAND CHANNEL:\t Received response on read 'Percentage3'-register = {this.PercentPath2.ToString(this.Culture)} at METER{this.MeterIndex}\n"; GenesisZeroFlow._GenesisZeroFlow.SetFirstHitPercentage(this.MeterNumber, Constants.PATH2, this.PercentPath2); return Message; } #endregion #region Calibration factor PATH0 if (Enumerable.SequenceEqual(GP30LastRegister, GP30Registers.CalFactor1())) { Where = "Calibration PATH0"; Byte[] TempArray = new Byte[2]; TempArray = rxStringCommandChannel.GetRange(GP30BytePosition.Reply, 2).ToArray(); TempArray.Reverse(); this.CalibrationFactorPath0 = BitConverter.ToUInt16(TempArray, 0); Message = $"COMMAND CHANNEL:\t Received response on read 'Calibration factor1'-register = 0x{this.CalibrationFactorPath0.ToString("X4", this.Culture)} at METER{this.MeterIndex}\n"; GenesisZeroFlow._GenesisZeroFlow.SetCalFactor(this.MeterNumber, Constants.PATH0, this.CalibrationFactorPath0); return Message; } #endregion #region Calibration factor PATH1 if (Enumerable.SequenceEqual(GP30LastRegister, GP30Registers.CalFactor2())) { Where = "Calibration PATH1"; Byte[] TempArray = new Byte[2]; TempArray = rxStringCommandChannel.GetRange(GP30BytePosition.Reply, 2).ToArray(); TempArray.Reverse(); this.CalibrationFactorPath1 = BitConverter.ToUInt16(TempArray, 0); Message = $"COMMAND CHANNEL:\t Received response on read 'Calibration factor2'-register = 0x{this.CalibrationFactorPath1.ToString("X4", this.Culture)} at METER{this.MeterIndex}\n"; GenesisZeroFlow._GenesisZeroFlow.SetCalFactor(this.MeterNumber, Constants.PATH1, CalibrationFactorPath1); return Message; } #endregion #region Calibration factor PATH2 if (Enumerable.SequenceEqual(GP30LastRegister, GP30Registers.CalFactor3())) { Where = "Calibration PATH2"; Byte[] TempArray = new Byte[2]; TempArray = rxStringCommandChannel.GetRange(GP30BytePosition.Reply, 2).ToArray(); TempArray.Reverse(); this.CalibrationFactorPath2 = BitConverter.ToUInt16(TempArray, 0); Message = $"COMMAND CHANNEL:\t Received response on read 'Calibration factor3'-register = 0x{this.CalibrationFactorPath2.ToString("X4", this.Culture)} at METER{this.MeterIndex}\n"; GenesisZeroFlow._GenesisZeroFlow.SetCalFactor(this.MeterNumber, Constants.PATH2, this.CalibrationFactorPath2); return Message; } #endregion #region Zeroflow offset PATH0 if (Enumerable.SequenceEqual(GP30LastRegister, GP30Registers.ZeroOffset1())) { Where = "Zerooffset PATH0"; Byte[] TempArray = new Byte[4]; TempArray = rxStringCommandChannel.GetRange(GP30BytePosition.Reply, 4).ToArray(); TempArray.Reverse(); this.ZeroOffsetPath0 = BitConverter.ToInt32(TempArray, 0); Message = $"COMMAND CHANNEL:\t Received response on read 'Zeroflow offset1'-register = 0x{this.ZeroOffsetPath0.ToString("X8", this.Culture)} at METER{this.MeterIndex}\n"; GenesisZeroFlow._GenesisZeroFlow.SetZeroFlowOffset(this.MeterNumber, Constants.PATH0, this.ZeroOffsetPath0); return Message; } #endregion #region Zeroflow offset PATH1 if (Enumerable.SequenceEqual(GP30LastRegister, GP30Registers.ZeroOffset2())) { Where = "Zerooffset PATH1"; Byte[] TempArray = new Byte[4]; TempArray = rxStringCommandChannel.GetRange(GP30BytePosition.Reply, 4).ToArray(); TempArray.Reverse(); this.ZeroOffsetPath1 = BitConverter.ToInt32(TempArray, 0); Message = $"COMMAND CHANNEL:\t Received response on read 'Zeroflow offset2'-register = 0x{this.ZeroOffsetPath1.ToString("X8", this.Culture)} at METER{this.MeterIndex}\n"; GenesisZeroFlow._GenesisZeroFlow.SetZeroFlowOffset(this.MeterNumber, Constants.PATH1, this.ZeroOffsetPath1); return Message; } #endregion #region Zeroflow offset PATH2 if (Enumerable.SequenceEqual(GP30LastRegister, GP30Registers.ZeroOffset3())) { Where = "Zerooffset PATH2"; Byte[] TempArray = new Byte[4]; TempArray = rxStringCommandChannel.GetRange(GP30BytePosition.Reply, 4).ToArray(); TempArray.Reverse(); this.ZeroOffsetPath2 = BitConverter.ToInt32(TempArray, 0); Message = $"COMMAND CHANNEL:\t Received response on read 'Zeroflow offset3'-register = 0x{this.ZeroOffsetPath2.ToString("X8", this.Culture)} at METER{this.MeterIndex}\n"; GenesisZeroFlow._GenesisZeroFlow.SetZeroFlowOffset(this.MeterNumber, Constants.PATH2, this.ZeroOffsetPath2); return Message; } #endregion #region Starthit if (Enumerable.SequenceEqual(GP30LastRegister, GP30Registers.StartHit())) { Where = "Starthit"; this.Starthit = rxStringCommandChannel.ElementAt(GP30BytePosition.Reply); Message = $"COMMAND CHANNEL:\t Received response on read 'Starthit'-register = {rxStringCommandChannel.ElementAt(GP30BytePosition.Reply).ToString(this.Culture)} at METER{this.MeterIndex}\n"; rxStringCommandChannel.Clear(); return Message; } #endregion #region Amplitude end detect if (Enumerable.SequenceEqual(GP30LastRegister, GP30Registers.AmplitudePeakDetectEnd())) { Where = "Amplitude"; this.Amplitude = rxStringCommandChannel.ElementAt(GP30BytePosition.Reply); Message = $"COMMAND CHANNEL:\t Received response on read 'Amplitude peak detect end'-register = {rxStringCommandChannel.ElementAt(GP30BytePosition.Reply).ToString(this.Culture)} at METER{this.MeterIndex}\n"; return Message; } #endregion #region Samplerate if (Enumerable.SequenceEqual(GP30LastRegister, GP30Registers.Samplerate())) { Where = "Samplerate"; this.Samplerate = rxStringCommandChannel.ElementAt(GP30BytePosition.Reply); Message = $"COMMAND CHANNEL:\t Received response on read 'Samplerate'-register = {rxStringCommandChannel.ElementAt(GP30BytePosition.Reply).ToString(this.Culture)} at METER{this.MeterIndex}\n"; return Message; } #endregion #region Metersize if (Enumerable.SequenceEqual(GP30LastRegister, GP30Registers.MeterSize())) { Where = "Metersize"; this.MeterSize = rxStringCommandChannel.ElementAt(GP30BytePosition.Reply); Message = $"COMMAND CHANNEL:\t Received response on read 'Metersize'-register = {this.MeterSize.ToString(this.Culture)} at METER{this.MeterIndex}\n"; return Message; } #endregion #region TofTempOffset PATH0 if (Enumerable.SequenceEqual(GP30LastRegister, GP30Registers.ToFTempOffset1())) { Where = "TofTempOffset PATH0"; Byte[] TempArray = new Byte[4]; TempArray = rxStringCommandChannel.GetRange(GP30BytePosition.Reply, 4).ToArray(); TempArray.Reverse(); this.ToFTempOffsetPath0 = BitConverter.ToInt32(TempArray, 0); Message = $"COMMAND CHANNEL:\t Received response on read 'ToFTempOffset1'-register = 0x{this.ToFTempOffsetPath0.ToString("X8", this.Culture)} at METER{this.MeterIndex}\n"; GenesisZeroFlow._GenesisZeroFlow.SetToFTempOffset(this.MeterNumber, Constants.PATH0, this.ToFTempOffsetPath0); return Message; } #endregion #region TofTempOffset PATH1 if (Enumerable.SequenceEqual(GP30LastRegister, GP30Registers.ToFTempOffset2())) { Where = "TofTempOffset PATH1"; Byte[] TempArray = new Byte[4]; TempArray = rxStringCommandChannel.GetRange(GP30BytePosition.Reply, 4).ToArray(); TempArray.Reverse(); this.ToFTempOffsetPath1 = BitConverter.ToInt32(TempArray, 0); Message = $"COMMAND CHANNEL:\t Received response on read 'ToFTempOffset2'-register = 0x{this.ToFTempOffsetPath1.ToString("X8", this.Culture)} at METER{this.MeterIndex}\n"; GenesisZeroFlow._GenesisZeroFlow.SetToFTempOffset(this.MeterNumber, Constants.PATH1, this.ToFTempOffsetPath1); return Message; } #endregion #region TofTempOffset PATH2 if (Enumerable.SequenceEqual(GP30LastRegister, GP30Registers.ToFTempOffset3())) { Where = "TofTempOffset PATH2"; Byte[] TempArray = new Byte[4]; TempArray = rxStringCommandChannel.GetRange(GP30BytePosition.Reply, 4).ToArray(); TempArray.Reverse(); this.ToFTempOffsetPath2 = BitConverter.ToInt32(TempArray, 0); Message = $"COMMAND CHANNEL:\t Received response on read 'ToFTempOffset3'-register = 0x{this.ToFTempOffsetPath2.ToString("X8", this.Culture)} at METER{this.MeterIndex}\n"; GenesisZeroFlow._GenesisZeroFlow.SetToFTempOffset(this.MeterNumber, Constants.PATH2, this.ToFTempOffsetPath2); return Message; } #endregion #region LED Mode / Keep authentified if (Enumerable.SequenceEqual(GP30LastRegister, GP30Registers.LedMode())) { Where = "LED-Mode"; this.LedMode = rxStringCommandChannel.ElementAt(GP30BytePosition.Reply); Message = $"COMMAND CHANNEL:\t Received response on read 'Keep authentified'/'LED Mode'-register = {this.LedMode.ToString(this.Culture)} at METER{this.MeterIndex}\n"; return Message; } #endregion } catch (Exception ex) { ErrorLog.Log(LogErrReason.Exeption, $"CmdInterface.ReadDataResponse() failed", $"0x{ex.HResult.ToString("X", this.Culture)}", Where, this.Culture); } #region Return return Message; #endregion } private String MultipleWriteDataResponse(List rxStringCommandChannel) { String Message = String.Empty; try { if (Enumerable.SequenceEqual(this.GP30LastRegister, GP30Registers.Password())) { Message = $"COMMAND CHANNEL:\t Received response on 'Multiple write to password register'. Address = 0x{this.GP30LastRegister[0].ToString("X2", this.Culture)}{this.GP30LastRegister[1].ToString("X2", this.Culture)}; Data= 0x{rxStringCommandChannel.ElementAt(GP30BytePosition.Reply).ToString("X2", this.Culture)} at METER{this.MeterIndex}\n"; return Message; } #region All others else { Message = $"COMMAND CHANNEL:\t Received response on 'Multiple write to register'. Address = 0x{this.GP30LastRegister[0].ToString("X2", this.Culture)}{this.GP30LastRegister[1].ToString("X2", this.Culture)}; Data= 0x{rxStringCommandChannel.ElementAt(GP30BytePosition.Reply).ToString("X2", this.Culture)} at METER{this.MeterIndex}\n"; return Message; } #endregion } catch (Exception ex) { ErrorLog.Log(LogErrReason.Exeption, $"CmdInterface{this.MeterIndex}.MulipleWriteDataResponse() failed", $"0x{ex.HResult.ToString("X", this.Culture)}", String.Empty, this.Culture); } return Message; } private Int32 Double0x5BGetLength(Byte[] inputData) { Int32 InputLength = inputData.Count(); Int32 NumberOf0x5B = 0; Int32 TotalLength = 0; try { for (Int32 InputIndex = 1; InputIndex < InputLength; InputIndex++) { if (Byte.Equals(inputData[InputIndex], GP30Commands.Startbyte)) NumberOf0x5B++; } TotalLength = InputLength + NumberOf0x5B; } catch (Exception ex) { ErrorLog.Log(LogErrReason.Exeption, $"CmdInterface{this.MeterIndex}.Double0x5BGetLength() failed", $"0x{ex.HResult.ToString("X", this.Culture)}", String.Empty, this.Culture); } return TotalLength; } private Byte[] Double0x5B(Byte[] inputData) { #region Definitions and initializations Int32 InputLength = (Int32)inputData.Count(); Int32 NumberOf0x5B = 0; Int32 OutputLength = 0; Int32 InputIndex = 1; Int32 OutputIndex = 1; #endregion try { #region Determine length for (InputIndex = 1; InputIndex < InputLength; InputIndex++) { if (Byte.Equals(inputData[InputIndex], GP30Commands.Startbyte)) NumberOf0x5B++; } OutputLength = InputLength + NumberOf0x5B; #endregion #region Generate output data Byte[] OutputData = new Byte[OutputLength]; OutputData[0] = GP30Commands.Startbyte; for (InputIndex = 1; InputIndex < InputLength; InputIndex++) { if (inputData[InputIndex] == GP30Commands.Startbyte) { OutputData[OutputIndex] = GP30Commands.Startbyte; OutputData[OutputIndex + 1] = GP30Commands.Startbyte; OutputIndex = OutputIndex + 2; } else { OutputData[OutputIndex] = inputData[InputIndex]; OutputIndex++; } } #endregion return OutputData; } catch (Exception ex) { ErrorLog.Log(LogErrReason.Exeption, $"CmdInterface{this.MeterIndex}.Double0x5BGetLength() failed", $"0x{ex.HResult.ToString("X", this.Culture)}", String.Empty, this.Culture); } return null; } public void DecodeHighLevelErrors(List rxStringCmd) { #region Definitions and initializations Byte GotSubreason = GP30HighLevelErrors.NoSubreason; String Where = "Beginning"; #endregion #region CA1062 if (rxStringCmd == null) return; #endregion try { #region Decode optical port errors (chapter 9.5.3) Where = "Decode 953"; if (Byte.Equals(rxStringCmd.ElementAt(GP30BytePosition.ErrCodeBase), GP30HighLevelErrors.Base)) { Display.DebugMessage(this.ErrorMessages953(rxStringCmd, out GotSubreason), this.Culture); this.IndicatorsFailed(); return; } #endregion #region Decode config exchange errors (chapter 8.5.3) Where = "Decode 853"; if (Byte.Equals(rxStringCmd.ElementAt(GP30BytePosition.ErrCodeBase), GP30ConfigExErrors.Base)) { Display.DebugMessage(this.ErrorMessages853(rxStringCmd, out GotSubreason), this.Culture); this.IndicatorsFailed(); this.Subreason = GotSubreason; return; } #endregion #region Decode response without errors Where = "Decode w/o errors"; if ((Byte.Equals(rxStringCmd.ElementAt(GP30BytePosition.ErrCodeBase), GP30HighLevelErrors.BaseOk)) && (Byte.Equals(rxStringCmd.ElementAt(GP30BytePosition.ErrCodeBase), GP30ConfigExErrors.BaseOk))) { #region Response on 'Read data' Where = "Read data"; if (Byte.Equals(this.GP30LastCommand, GP30Commands.ReadData)) { #region Save payload this.GP30RXPayload = rxStringCmd.ElementAt(GP30BytePosition.Reply); #endregion #region Display message !!!!! Display.DebugMessage(this.ReadDataResponse(rxStringCmd), this.Culture); // <===== Decoding of individual data this.IndicatorsOk(); this.Subreason = GP30HighLevelErrors.NoSubreason; Display.DebugMessage(String.Empty, this.Culture); rxStringCmd.Clear(); return; #endregion } #endregion #region Response on 'Write data' Where = "Write data"; if (Byte.Equals(this.GP30LastCommand, GP30Commands.WriteData)) { Display.DebugMessage(this.WriteDataResponse(rxStringCmd), this.Culture); // <===== this.IndicatorsOk(); this.Subreason = GP30HighLevelErrors.NoSubreason; rxStringCmd.Clear(); return; } #endregion #region Response to 'Multiple write data' Where = "Multiple write data"; if (Byte.Equals(this.GP30LastCommand, GP30Commands.MultipleWritedata)) { Display.DebugMessage(this.MultipleWriteDataResponse(rxStringCmd), this.Culture); // <==== this.IndicatorsOk(); this.Subreason = GP30HighLevelErrors.NoSubreason; rxStringCmd.Clear(); return; } #endregion this.IndicatorsOk(); this.Subreason = GP30HighLevelErrors.NoSubreason; } #endregion #region Unknown error code Where = "Unknown error code"; if ((rxStringCmd.ElementAt(GP30BytePosition.ErrCodeBase) != GP30HighLevelErrors.BaseOk) && (rxStringCmd.ElementAt(GP30BytePosition.ErrCodeBase) != GP30ConfigExErrors.BaseOk) && (rxStringCmd.ElementAt(GP30BytePosition.ErrCodeBase) != GP30HighLevelErrors.Base) && (rxStringCmd.ElementAt(GP30BytePosition.ErrCodeBase) != GP30ConfigExErrors.Base)) { Display.DebugMessage($"Error Code = 0x{rxStringCmd.ElementAt(GP30BytePosition.ErrCodeBase).ToString("X", this.Culture)}{rxStringCmd.ElementAt(GP30BytePosition.ErrCodeSubreason).ToString("X2", this.Culture)}\n", this.Culture); this.IndicatorsFailed(); GotSubreason = rxStringCmd.ElementAt(GP30BytePosition.ErrCodeSubreason); } #endregion // for all this.Subreason = GotSubreason; } catch(Exception ex) { ErrorLog.Log(LogErrReason.Exeption, $"CmdInterface{this.MeterIndex}.DecodeHighLevelErrors() failed", $"0x{ex.HResult.ToString("X", this.Culture)}", Where, this.Culture); } } public List Remove0x5B(List inputData) { #region Definitions and initializations UInt16 InputLength = (UInt16)inputData.Count(); UInt16 InputIndex = 0; Byte LastData = 0; Byte CurrentData = 0; List OutputData = new List(); #endregion try { #region Prepare output data for (InputIndex = 0; InputIndex < InputLength; InputIndex++) { CurrentData = inputData.ElementAt(InputIndex); if (!((LastData == GP30Commands.Startbyte) && (CurrentData == GP30Commands.Startbyte))) { OutputData.Add(CurrentData); LastData = CurrentData; } else LastData = 0; } #endregion } catch (Exception ex) { ErrorLog.Log(LogErrReason.Exeption, $"CommandInterface{this.MeterIndex}.Remove0x5B() failed", $"0x{ex.HResult.ToString("X", this.Culture)}", $"Index = { InputIndex.ToString(this.Culture)}", this.Culture); } return OutputData; } private String ErrorMessages953(List rxStringCommandChannel, out Byte subreason) { #region Definitions and initializations String Data = String.Empty; subreason = 0; #endregion try { #region Decode optical port errors (chapter 9.5.3 of breeze specification document) subreason = rxStringCommandChannel.ElementAt(GP30BytePosition.ErrCodeSubreason); switch (rxStringCommandChannel.ElementAt(GP30BytePosition.ErrCodeSubreason)) { case GP30HighLevelErrors.CrcFailure: Data = "ERROR: CRC Failure\n"; break; case GP30HighLevelErrors.InvalidEscape: Data = "ERROR: INVALIDESCAPE\n"; break; case GP30HighLevelErrors.InvalidBaudrate: Data = "ERROR: INVALID_BAUDRATE\n"; break; case GP30HighLevelErrors.InvalidBuffersize: Data = "ERROR: INVALID_BUFFERSIZE\n"; break; case GP30HighLevelErrors.InvalidSubreason: Data = "ERROR: INVALID_SUBREASON\n"; break; case GP30HighLevelErrors.NoBreak: Data = "ERROR: NOBREAK\n"; break; case GP30HighLevelErrors.Overflow: Data = "ERROR: OVERFLOW\n"; break; case GP30HighLevelErrors.PacketTimeout: Data = "ERROR: PACKETTIMEOUT\n"; break; case GP30HighLevelErrors.PayloadCount: Data = "ERROR: PAYLOAD_COUNT\n"; break; case GP30HighLevelErrors.TrainingFailed: Data = "ERROR: TRAINING_FAILED\n"; break; case GP30HighLevelErrors.UnknownParameter: Data = "ERROR: UNKNOWN_PARAMETER\n"; break; case GP30HighLevelErrors.UnrecognizedCmd: Data = "ERROR: UNRECOGNISEDCMD\n"; break; default: Data = "ERROR: Unkwown failure code\n"; break; } #endregion } catch (Exception ex) { ErrorLog.Log(LogErrReason.Exeption, $"CommandInterface{this.MeterIndex}.ErrorMessages953() failed", $"0x{ex.HResult.ToString("X", this.Culture)}", String.Empty, this.Culture); } #region Return return Data; #endregion } private String ErrorMessages853(List rxStringCommandChannel, out Byte subreason) { String data = String.Empty; subreason = 0; try { #region Decode optical port errors (chapter 8.5.3 of breeze specification document) subreason = rxStringCommandChannel.ElementAt(GP30BytePosition.ErrCodeSubreason); switch (rxStringCommandChannel.ElementAt(GP30BytePosition.ErrCodeSubreason)) { case (GP30ConfigExErrors.LockedOut): data = "ERROR: Locked out\n"; break; case (GP30ConfigExErrors.AuthenticationFail): data = "ERROR: Authenfication failure\n"; break; case (GP30ConfigExErrors.AccessDenied): data = "ERROR: Access denied!\n"; break; case (GP30ConfigExErrors.UnknownParameter): data = "ERROR: Unknown parameter\n"; break; case (GP30ConfigExErrors.InUse): data = "ERROR: In use\n"; break; case (GP30ConfigExErrors.SizesDoNotMatch): data = "ERROR: Sizes don't match\n"; break; case (GP30ConfigExErrors.CannotReadConfigfile): data = "ERROR: Can't read config file\n"; break; case (GP30ConfigExErrors.UserNotKnown): data = "ERROR: User not known\n"; break; case (GP30ConfigExErrors.CannotCreateConfigfile): data = "ERROR: Can't create config file\n"; break; case (GP30ConfigExErrors.StoreDidNotStore): data = "ERROR: Store didn't store\n"; break; case (GP30ConfigExErrors.StoreCorrupt): data = "ERROR: Store corrupt\n"; break; case (GP30ConfigExErrors.ExpectedWrite): data = "ERROR: Expected write\n"; break; case (GP30ConfigExErrors.ExpectedRead): data = "ERROR: Expected read\n"; break; case (GP30ConfigExErrors.StopCycling): data = "ERROR: Stop cycling\n"; break; case (GP30ConfigExErrors.TooManyOpen): data = "ERROR: Too many open\n"; break; case (GP30ConfigExErrors.NeverOpened): data = "ERROR: Never opened\n"; break; case (GP30ConfigExErrors.FileProtected): data = "ERROR: File protected\n"; break; case (GP30ConfigExErrors.PartialRecall): data = "ERROR: Partial recall\n"; break; case (GP30ConfigExErrors.DefaultPasswordUsed): data = "ERROR: Default password used\n"; break; default: data = $"ERROR: Unknown error code: 0x{rxStringCommandChannel.ElementAt(GP30BytePosition.ErrCodeSubreason).ToString("X2", this.Culture)}\n"; break; } #endregion } catch (Exception ex) { ErrorLog.Log(LogErrReason.Exeption, $"CommandInterface{this.MeterIndex}.ErrorMessages853() failed ", $"0x{ex.HResult.ToString("X", this.Culture)}", String.Empty, this.Culture); } return data; } } public partial class GenesisZeroFlow : Form { const Boolean DisplayUndecodedRxData = false; private void GetReplyCmdMeter1(object sender, EventArgs e) { CultureInfo Culture = GetGlobalCulture(); try { #region Decode reply command Display.DebugMessage(CommandInterface1.ReplyCommand(RxStringCmd[Constants.Meter1]), Culture); #endregion CommandInterface1.DecodeHighLevelErrors(RxStringCmd[Constants.Meter1]); RxStringCmd[Constants.Meter1].Clear(); } catch (Exception ex) { #region Error: exception ErrorLog.Log(LogErrReason.Exeption, "GetReplyCmdMeter1() failed", $"0x{ex.HResult.ToString("X", Culture)}", String.Empty, Culture); #endregion } } private void GetReplyCmdMeter2(object sender, EventArgs e) { CultureInfo Culture = GetGlobalCulture(); try { #region Decode reply command Display.DebugMessage(CommandInterface2.ReplyCommand(RxStringCmd[Constants.Meter2]), Culture); #endregion #region Obtain error status CommandInterface2.DecodeHighLevelErrors(RxStringCmd[Constants.Meter2]); RxStringCmd[Constants.Meter2].Clear(); #endregion } catch (Exception ex) { #region Error: exception ErrorLog.Log(LogErrReason.Exeption, "GetReplyCmdMeter2() failed", $"0x{ex.HResult.ToString("X", Culture)}", String.Empty, Culture); #endregion } } private void GetReplyCmdMeter3(object sender, EventArgs e) { CultureInfo Culture = GetGlobalCulture(); try { #region Decode reply command Display.DebugMessage(CommandInterface3.ReplyCommand(RxStringCmd[Constants.Meter3]), Culture); #endregion #region Obtain error status CommandInterface3.DecodeHighLevelErrors(RxStringCmd[Constants.Meter3]); RxStringCmd[Constants.Meter3].Clear(); #endregion } catch (Exception ex) { #region Error: exception ErrorLog.Log(LogErrReason.Exeption, "GetReplyCmdMeter3() failed", $"0x{ex.HResult.ToString("X", Culture)}", String.Empty, Culture); #endregion } } private void GetReplyCmdMeter4(object sender, EventArgs e) { CultureInfo Culture = GetGlobalCulture(); try { #region Decode reply command Display.DebugMessage(CommandInterface4.ReplyCommand(RxStringCmd[Constants.Meter4]), Culture); #endregion #region Obtain error status CommandInterface4.DecodeHighLevelErrors(RxStringCmd[Constants.Meter4]); RxStringCmd[Constants.Meter4].Clear(); #endregion } catch (Exception ex) { #region Error: exception ErrorLog.Log(LogErrReason.Exeption, "GetReplyCmdMeter4() failed", $"0x{ex.HResult.ToString("X", Culture)}", String.Empty, Culture); #endregion } } private void GetReplyCmdMeter5(object sender, EventArgs e) { CultureInfo Culture = GetGlobalCulture(); try { #region Decode reply command Display.DebugMessage(CommandInterface5.ReplyCommand(RxStringCmd[Constants.Meter5]), Culture); #endregion #region Obtain error status CommandInterface5.DecodeHighLevelErrors(RxStringCmd[Constants.Meter5]); RxStringCmd[Constants.Meter5].Clear(); #endregion } catch (Exception ex) { #region Error: exception ErrorLog.Log(LogErrReason.Exeption, "GetReplyCmdMeter5() failed", $"0x{ex.HResult.ToString("X", Culture)}", String.Empty, Culture); #endregion } } private void GetReplyCmdMeter6(object sender, EventArgs e) { CultureInfo Culture = GetGlobalCulture(); try { #region Decode reply command Display.DebugMessage(CommandInterface6.ReplyCommand(RxStringCmd[Constants.Meter6]), Culture); #endregion #region Obtain error status CommandInterface6.DecodeHighLevelErrors(RxStringCmd[Constants.Meter6]); RxStringCmd[Constants.Meter6].Clear(); #endregion } catch (Exception ex) { #region Error: exception ErrorLog.Log(LogErrReason.Exeption, "GetReplyCmdMeter6() failed", $"0x{ex.HResult.ToString("X", Culture)}", String.Empty, Culture); #endregion } } private void GetReplyCmdMeter7(object sender, EventArgs e) { CultureInfo Culture = GetGlobalCulture(); try { #region Decode reply command Display.DebugMessage(CommandInterface7.ReplyCommand(RxStringCmd[Constants.Meter7]), Culture); #endregion #region Obtain error status CommandInterface7.DecodeHighLevelErrors(RxStringCmd[Constants.Meter7]); RxStringCmd[Constants.Meter7].Clear(); #endregion } catch (Exception ex) { #region Error: exception ErrorLog.Log(LogErrReason.Exeption, "GetReplyCmdMeter7() failed", $"0x{ex.HResult.ToString("X", Culture)}", String.Empty, Culture); #endregion } } private void GetReplyCmdMeter8(object sender, EventArgs e) { CultureInfo Culture = GetGlobalCulture(); try { #region Decode reply command Display.DebugMessage(CommandInterface8.ReplyCommand(RxStringCmd[Constants.Meter8]), Culture); #endregion #region Obtain error status CommandInterface8.DecodeHighLevelErrors(RxStringCmd[Constants.Meter8]); RxStringCmd[Constants.Meter8].Clear(); #endregion } catch (Exception ex) { #region Error: exception ErrorLog.Log(LogErrReason.Exeption, "GetReplyCmdMeter8() failed", $"0x{ex.HResult.ToString("X", Culture)}", String.Empty, Culture); #endregion } } private void GetReplyCmdMeter9(object sender, EventArgs e) { CultureInfo Culture = GetGlobalCulture(); try { #region Decode reply command Display.DebugMessage(CommandInterface9.ReplyCommand(RxStringCmd[Constants.Meter9]), Culture); #endregion #region Obtain error status CommandInterface9.DecodeHighLevelErrors(RxStringCmd[Constants.Meter9]); RxStringCmd[Constants.Meter9].Clear(); #endregion } catch (Exception ex) { #region Error: exception ErrorLog.Log(LogErrReason.Exeption, "GetReplyCmdMeter9() failed", $"0x{ex.HResult.ToString("X", Culture)}", String.Empty, Culture); #endregion } } private void GetReplyCmdMeter10(object sender, EventArgs e) { CultureInfo Culture = GetGlobalCulture(); try { #region Decode reply command Display.DebugMessage(CommandInterface10.ReplyCommand(RxStringCmd[Constants.Meter10]), Culture); #endregion #region Obtain error status CommandInterface10.DecodeHighLevelErrors(RxStringCmd[Constants.Meter10]); RxStringCmd[Constants.Meter10].Clear(); #endregion } catch (Exception ex) { #region Error: exception ErrorLog.Log(LogErrReason.Exeption, "GetReplyCmdMeter10() failed", $"0x{ex.HResult.ToString("X", Culture)}", String.Empty, Culture); #endregion } } } }