1987 lines
104 KiB
C#
1987 lines
104 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Globalization;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using System.IO;
|
|
using System.IO.Ports;
|
|
using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore;
|
|
using Xylem.Common.Hardware.WaterMeter.Genesis.Registers;
|
|
|
|
namespace GenesisDisplayTool
|
|
{
|
|
public class CmdInterface
|
|
{
|
|
public string Gp30LastRegister { get; set; }
|
|
public void SetGp30LastRegister(string data)
|
|
{
|
|
Gp30LastRegister = data;
|
|
}
|
|
private Byte Gp30LastPayloadLsb { get; set; }
|
|
public Byte Gp30LastCommand { get; set; }
|
|
public Byte Gp30LastByte { get; set; }
|
|
public SerialPort Port { get; set; }
|
|
private Byte Gp30RXPayload { get; set; }
|
|
private Boolean Gp30RequestStarted { get; set; }
|
|
private Boolean Gp30RequestFailed { get; set; }
|
|
private Boolean Gp30RequestGotAnswer { 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 NumberOfFirePulses { get; set; }
|
|
// private Byte Subreason { get; set; }
|
|
private Byte Starthit { get; set; }
|
|
private Byte Amplitude { get; set; }
|
|
private Byte Samplerate { get; set; }
|
|
private Byte PercentagePath0 { get; set; }
|
|
private Byte PercentagePath1 { get; set; }
|
|
private Byte PercentagePath2 { 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 Metersize { get; set; }
|
|
private Byte Arrow { get; set; }
|
|
private UInt16 MeterNumber { get; set; }
|
|
private String MeterIndex { get; set; }
|
|
private CultureInfo Culture { get; set; }
|
|
private UInt32 Voltage { get; set; }
|
|
private UInt32 ToFTempOffsetPath0 { get; set; }
|
|
private UInt32 ToFTempOffsetPath1 { get; set; }
|
|
private UInt32 ToFTempOffsetPath2 { get; set; }
|
|
public void Init(UInt16 meterNumber, SerialPort port, CultureInfo culture)
|
|
{
|
|
this.Gp30LastRegister = "";
|
|
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.Port = port;
|
|
this.Culture = culture;
|
|
this.MeterIndex = (meterNumber + 1).ToString(culture);
|
|
|
|
}
|
|
//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 Int16 QueryCaps()
|
|
{
|
|
|
|
#region Definitions and initializations
|
|
Int16 ErrCode = GP30LowLevelErrors.NoError;
|
|
Byte[] FirstLevelByteTx = new Byte[7] { 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 Prepare data
|
|
try
|
|
{
|
|
#region Fill buffer
|
|
Byte[] FirstLevelByteCrcInput = new Byte[6] { FirstLevelLengthLsb, FirstLevelLengthMsb, GP30Commands.QueryCaps, GP30Commands.Nop, FirstLevelCrcLsb, FirstLevelCrcMsb };
|
|
FirstLevelByteTx[0] = GP30Commands.Startbyte;
|
|
Buffer.BlockCopy(FirstLevelByteCrcInput, 0, FirstLevelByteTx, 1, FirstLevelByteCrcInput.Length);
|
|
#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
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#region Error: CRC
|
|
ErrorLog.Log(LogErrReason.Exception(), "Gp30QueryCaps() failed", "0x" + ex.HResult.ToString("X", this.Culture), "CRC");
|
|
ErrCode = GP30LowLevelErrors.CrcCalcError;
|
|
return ErrCode;
|
|
#endregion
|
|
}
|
|
#endregion
|
|
#region Send data
|
|
try
|
|
{
|
|
if (this.Port.IsOpen)
|
|
{
|
|
#region Command memory
|
|
this.Gp30LastCommand = GP30Commands.QueryCaps;
|
|
#endregion
|
|
#region Send data
|
|
Port.Write(FirstLevelByteTx, 0, FirstLevelByteTx.Length);
|
|
#endregion
|
|
}
|
|
else
|
|
{
|
|
#region Error: serial port not open
|
|
ErrCode = GP30LowLevelErrors.SerialPortClosed;
|
|
#endregion
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#region Error: serial port write failed
|
|
ErrorLog.Log(LogErrReason.Exception(), "Gp30QueryCaps() failed", "0x" + ex.HResult.ToString("X", this.Culture), "Send data");
|
|
ErrCode = GP30LowLevelErrors.SerialPortWriteFailure;
|
|
#endregion
|
|
}
|
|
#endregion
|
|
#region Return error code
|
|
return ErrCode;
|
|
#endregion
|
|
}
|
|
public Int16 RXProcessor(UInt16 requestType)
|
|
{
|
|
|
|
#region Definitions and initializations
|
|
UInt16 Timeoutcounter = 0;
|
|
Int16 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.Exception(), "CmdInterface.RxProcessor() failed", $"0x{ex.HResult.ToString("X", this.Culture)}", String.Empty);
|
|
}
|
|
#region Return error code
|
|
return ErrCode;
|
|
#endregion
|
|
}
|
|
public Int16 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)((UInt32)gp30Data.Length / 4);
|
|
if ((gp30Data.Length % 4) != 0)
|
|
PasswordNumberOfWritesLsb++;
|
|
#endregion
|
|
#region Zero padding (Get number of required zeros)
|
|
if (((UInt32)gp30Data.Length % 4) != 0)
|
|
ZeroPadding = (Byte)(4 - ((UInt32)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 (this.Port.IsOpen)
|
|
{
|
|
int 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
|
|
this.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.Exception(), $"CmdInterface.MultipleWriteRegister() failed", $"0x{ex.HResult.ToString("X", this.Culture)}", String.Empty);
|
|
ErrCode = GP30LowLevelErrors.SerialPortWriteFailure;
|
|
#endregion
|
|
}
|
|
#endregion
|
|
#region Return error code
|
|
return ErrCode;
|
|
#endregion
|
|
}
|
|
public Int16 WriteRegister(string gp30Register, Byte[] gp30Data, Boolean double0x5B)
|
|
{
|
|
//#region Definitions and initializations
|
|
Int16 ErrCode = GP30LowLevelErrors.NoError;
|
|
//#endregion
|
|
//#region To avoid warning CA1061
|
|
//if ((gp30Register == null) || (gp30Data == null))
|
|
// return GP30LowLevelErrors.Unknown;
|
|
//#endregion
|
|
//if (int.Equals(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.Exception(), "CmdInterface.WriteRegister()/'Prepare data' failed", $"0x{ex.HResult.ToString("X", this.Culture)}", String.Empty + "\n");
|
|
// ErrCode = GP30LowLevelErrors.CrcCalcError;
|
|
// return ErrCode;
|
|
// #endregion
|
|
// }
|
|
// #endregion
|
|
// #region Send data
|
|
// try
|
|
// {
|
|
// if (this.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];
|
|
// //SetGP30LastRegister(gp30Register);
|
|
// this.Gp30LastRegister = gp30Register;
|
|
// #endregion
|
|
// #region Send data
|
|
// this.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.Exception(), "CmdInterface.WriteRegister()/'Send data' failed", $"0x{ex.HResult.ToString("X", this.Culture)}", String.Empty);
|
|
// ErrCode = GP30LowLevelErrors.SerialPortWriteFailure;
|
|
// #endregion
|
|
// }
|
|
// #endregion
|
|
//}
|
|
//else
|
|
//{
|
|
// #region Error: max. length
|
|
// ErrCode = GP30LowLevelErrors.MaxDataLength;
|
|
// #endregion
|
|
//}
|
|
|
|
return ErrCode;
|
|
|
|
}
|
|
//public Int16 ReadRegister(string 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 ((this.Port == null) || (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.Exception(), $"CmdInterface.ReadRegister()/ 'CRC calc' failed", $"0x{ex.HResult.ToString("X", this.Culture)}", String.Empty);
|
|
// ErrCode = GP30LowLevelErrors.CrcCalcError;
|
|
// return ErrCode;
|
|
// #endregion
|
|
// }
|
|
// #endregion
|
|
// #region Send data
|
|
// try
|
|
// {
|
|
// if (this.Port.IsOpen)
|
|
// {
|
|
// #region Command memory
|
|
// this.Gp30LastCommand = GP30Commands.ReadData;
|
|
// this.Gp30LastRegister = register;
|
|
// #endregion
|
|
// #region Send data
|
|
// this.Port.Write(FirstLevelByteTx, 0, FirstLevelByteTx.Length);
|
|
// #endregion
|
|
// }
|
|
// else
|
|
// {
|
|
// #region Error
|
|
// ErrCode = GP30LowLevelErrors.SerialPortClosed;
|
|
// #endregion
|
|
// }
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// #region Error
|
|
// ErrorLog.Log(LogErrReason.Exception(), "Gp30ReadRegister()/ 'Send data' failed", $"0x{ex.HResult.ToString("X", this.Culture)}", String.Empty);
|
|
// ErrCode = GP30LowLevelErrors.SerialPortWriteFailure;
|
|
// #endregion
|
|
// }
|
|
// #endregion
|
|
// #region Return error code
|
|
// return ErrCode;
|
|
// #endregion
|
|
//}
|
|
public String ReplyCommandLabelText(List<Byte> RxStringCommandChannel)
|
|
{
|
|
#region Definitions and initializations
|
|
String Data = String.Empty;
|
|
String DefaultText = "---";
|
|
#endregion
|
|
|
|
try
|
|
{
|
|
if (Byte.Equals(RxStringCommandChannel.ElementAt(GP30BytePosition.Cmd), GP30Commands.ReadDataReply))
|
|
{
|
|
Int32 StopPosition = (Int32)RxStringCommandChannel.ElementAt(0) - 4;
|
|
Int32 StartPosition = (Int32)RxStringCommandChannel.ElementAt(0) - 1;
|
|
for (Int32 i = StartPosition; i >= StopPosition; i--)
|
|
Data = $"{Data}0x{RxStringCommandChannel.ElementAt(i).ToString("X", this.Culture)}; ";
|
|
}
|
|
else
|
|
Data = DefaultText;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ErrorLog.Log(LogErrReason.Exception(), "CommandInterface.ReplyCommandLabelText() failed", $"0x{ex.HResult.ToString("X", this.Culture)}", String.Empty);
|
|
}
|
|
return Data;
|
|
}
|
|
|
|
|
|
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;
|
|
}
|
|
|
|
|
|
// The most complex parts are not being used
|
|
public String ReplyCommand(List<Byte> rxStringCommandChannel)
|
|
{
|
|
String Data = String.Empty;
|
|
|
|
//meterNo++;
|
|
|
|
try
|
|
{
|
|
switch (rxStringCommandChannel.ElementAt(GP30BytePosition.Cmd))
|
|
{
|
|
|
|
case GP30Commands.ReadDataReply:
|
|
Data = $"{Data} RX-Command 'READ_DATA_REPLY' at METER{this.MeterIndex}\n";
|
|
break;
|
|
case GP30Commands.WriteDataReply:
|
|
Data = $"{Data} RX-Command 'WRITE_DATA_REPLY' at METER{this.MeterIndex}\n";
|
|
break;
|
|
case GP30Commands.MultipleReadDataReply:
|
|
Data = $"{Data} RX-Command 'MULTIPLE_READ_DATA_REPLY' at METER{this.MeterIndex}\n";
|
|
break;
|
|
case GP30Commands.MultipleWriteDataReply:
|
|
Data = $"{Data} RX-Command 'MULTIPLE_WRITE_DATA_REPLY at METER{this.MeterIndex}\n";
|
|
break;
|
|
case GP30Commands.SetLevelReply:
|
|
Data = $"{Data} RX-Command 'SET_LEVEL_REPLY' at METER{this.MeterIndex}\n";
|
|
break;
|
|
case GP30Commands.QueryCapsReply:
|
|
#region Command
|
|
Data = $"RX-Command 'QUERY_CAPS_REPLY' at METER{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] "; // 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}RX-Command 'SET_CAPS_REPLY' at METER{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 ((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}\n";
|
|
|
|
}
|
|
#endregion
|
|
break;
|
|
case GP30Commands.TrainReply:
|
|
Data = $"{Data} RX-Command 'TRAIN_REPLY' at METER{this.MeterIndex}\n";
|
|
break;
|
|
case GP30Commands.RepeatLastReply:
|
|
Data = $"{Data} RX-Command 'REPEAT_LAST_REPLY' at METER{MeterIndex}\n";
|
|
break;
|
|
default:
|
|
Data = $"{Data} RX-Command unexpected command: 0x{rxStringCommandChannel.ElementAt(2).ToString("X2", this.Culture)} at METER{this.MeterIndex}\n";
|
|
break;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ErrorLog.Log(LogErrReason.Exception(), "CmdInterface.ReplyCommand() failed", $"0x{ex.HResult.ToString("X", this.Culture)}", String.Empty);
|
|
}
|
|
|
|
return Data;
|
|
}
|
|
|
|
|
|
private String WriteDataResponse(List<Byte> rxStringCommandChannel, Int32 displayOnTab)
|
|
{
|
|
string tempLastReg = this.Gp30LastRegister;// GENESIS_DISPLAY_TOOL._GENESIS_DISPLAY_TOOL.Gp30LastParam.Register;
|
|
String Message = $"COMMAND CHANNEL\t Received response on write to register {tempLastReg}\n";
|
|
Byte[] JsonData = new Byte[4];
|
|
|
|
|
|
try
|
|
{
|
|
|
|
if (!Int32.Equals(displayOnTab, SelectedTab.Json) && (!Int32.Equals(displayOnTab, SelectedTab.None)))
|
|
{
|
|
|
|
#region Privilege register
|
|
if (tempLastReg.Equals(Register.Configexchange.Privilege))
|
|
{
|
|
Message = $"COMMAND CHANNEL\t Received response on write to 'Privilege'-register at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region Percentage PATH0
|
|
if (tempLastReg.Equals(Register.Genesisflow.FirstHitPercent1))
|
|
{
|
|
Message = $"COMMAND CHANNEL\t Received response on write to 'Percentage'-register, PATH1 at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region Percentage PATH1
|
|
if (tempLastReg.Equals(Register.Genesisflow.FirstHitPercent2))
|
|
{
|
|
Message = $"COMMAND CHANNEL\t Received response on write to 'Percentage'-register, PATH2 at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region Percentage PATH2
|
|
if (tempLastReg.Equals(Register.Genesisflow.FirstHitPercent3))
|
|
{
|
|
Message = $"COMMAND CHANNEL\t Received response on write to 'Percentage'-register, PATH3 at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region First hit level up PATH0
|
|
if (tempLastReg.Equals(Register.Genesisflow.FirstHitLvlUp1))
|
|
{
|
|
Message = $"COMMAND CHANNEL\t Received response on write to 'First hit level up'-register, PATH1 at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region First hit level up PATH1
|
|
if (tempLastReg.Equals(Register.Genesisflow.FirstHitLvlUp2))
|
|
{
|
|
Message = $"COMMAND CHANNEL\t Received response on write to 'First hit level up'-register, PATH2 at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region First hit level up PATH2
|
|
if (tempLastReg.Equals(Register.Genesisflow.FirstHitLvlUp3))
|
|
{
|
|
Message = $"COMMAND CHANNEL\t Received response on write to 'First hit level up'-register, PATH3 at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region First hit level down PATH0
|
|
if (tempLastReg.Equals(Register.Genesisflow.FirstHitLvlDown1))
|
|
{
|
|
Message = $"COMMAND CHANNEL\t Received response on write to 'First hit level down'-register, PATH1 at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region First hit level down PATH1
|
|
if (tempLastReg.Equals(Register.Genesisflow.FirstHitLvlDown2))
|
|
{
|
|
Message = $"COMMAND CHANNEL\t Received response on write to 'First hit level down'-register, PATH2 at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region First hit level down PATH2
|
|
if (tempLastReg.Equals(Register.Genesisflow.FirstHitLvlDown3))
|
|
{
|
|
Message = $"COMMAND CHANNEL\t Received response on write to 'First hit level down'-register, PATH3 at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region Number of TX bursts
|
|
if (tempLastReg.Equals(Register.Genesisflow.NumFirePulses))
|
|
{
|
|
Message = $"COMMAND CHANNEL\t Received response on write to 'Number of fire pulses'-register at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region Starthit
|
|
if (tempLastReg.Equals(Register.Genesisflow.StartHit))
|
|
{
|
|
Message = $"COMMAND CHANNEL\t Received response on write to 'Starthit'-register at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region Amplitude end detect
|
|
if (tempLastReg.Equals(Register.Genesisflow.AmplitudePeakDetectEnd))
|
|
{
|
|
Message = $"COMMAND CHANNEL\t Received response on write to 'Amplitude peak detect end'-register at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region Store calibration
|
|
if (tempLastReg.Equals(Register.Genesisflow.StoreCalibration))
|
|
{
|
|
Message = $"COMMAND CHANNEL\t Received response on write to 'Store calibration'-register at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region First hit update periode
|
|
if (tempLastReg.Equals(Register.Genesisflow.FirstHitUpdatePeriod))
|
|
{
|
|
Message = $"COMMAND CHANNEL\t Received response on write to 'Firsthit update period'-register at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region First hit shift
|
|
if (tempLastReg.Equals(Register.Genesisflow.FirstHitShift))
|
|
{
|
|
Message = $"COMMAND CHANNEL\t Received response on write to 'Firsthit shift'-register at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region Calibration factor PATH0
|
|
if (tempLastReg.Equals(Register.Genesisflow.CalFactor1))
|
|
{
|
|
Message = $"COMMAND CHANNEL\t Received response on write to 'Calibration factor1'-register at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region Calibration factor PATH1
|
|
if (tempLastReg.Equals(Register.Genesisflow.CalFactor2))
|
|
{
|
|
Message = $"COMMAND CHANNEL\t Received response on write to 'Calibration factor2'-register at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region Calibration factor PATH2
|
|
if (tempLastReg.Equals(Register.Genesisflow.CalFactor3))
|
|
{
|
|
Message = $"COMMAND CHANNEL\t Received response on write to 'Calibration factor3'-register at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region Zero offset PATH0
|
|
if (tempLastReg.Equals(Register.Genesisflow.ZeroOffset1))
|
|
{
|
|
Message = $"COMMAND CHANNEL\t Received response on write to 'Zero offset1'-register at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region Zero offset PATH1
|
|
if (tempLastReg.Equals(Register.Genesisflow.ZeroOffset2))
|
|
{
|
|
Message = $"COMMAND CHANNEL\t Received response on write to 'Zero offset2'-register at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region Zero offset PATH2
|
|
if (tempLastReg.Equals(Register.Genesisflow.ZeroOffset3))
|
|
{
|
|
Message = $"COMMAND CHANNEL\t Received response on write to 'Zero offset3'-register at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region Samplerate
|
|
if (tempLastReg.Equals(Register.Genesisflow.SampleRate))
|
|
{
|
|
Message = $"COMMAND CHANNEL\t Received response on write to 'Samplerate'-register at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region Metersize
|
|
if (tempLastReg.Equals(Register.Genesisflow.MeterSize))
|
|
{
|
|
Message = $"COMMAND CHANNEL\t Received response on write to 'Metersize'-register at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region LED Mode
|
|
if (tempLastReg.Equals(Register.Genesisflow.LedMode))
|
|
{
|
|
Message = $"COMMAND CHANNEL\t Received response on write to 'LED-Mode'-register at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region Forward Arrow
|
|
if (tempLastReg.Equals(Register.Genesisflow.ForwardArrow))
|
|
{
|
|
Message = $"COMMAND CHANNEL\t Received response on write to 'Forward Arrow'-register at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region Forward Arrow
|
|
if (tempLastReg.Equals(Register.Genesisflow.ResetAccumulators))
|
|
{
|
|
Message = $"COMMAND CHANNEL\t Received response on write to 'Accu Reset'-register at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region ToFTempCalibrate
|
|
if (tempLastReg.Equals(Register.Genesisflow.ToFTempCalibrate))
|
|
{
|
|
Message = $"COMMAND CHANNEL\t Received response on write to 'ToFTempCalibrate'-register at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region Unknown register
|
|
return Message = $"COMMAND CHANNEL\t Received response on write to unknown register at METER{this.MeterIndex}\n";
|
|
#endregion
|
|
}
|
|
else
|
|
{
|
|
#region JSON
|
|
if (Int32.Equals(displayOnTab, SelectedTab.Json))
|
|
{
|
|
Array.Copy(rxStringCommandChannel.ToArray(), GP30BytePosition.Reply, JsonData, 0, 4);
|
|
Array.Reverse(JsonData);
|
|
Message = $"COMMAND CHANNEL\t Received response on write to register {tempLastReg} at METER{this.MeterIndex}\n";
|
|
}
|
|
#endregion
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ErrorLog.Log(LogErrReason.Exception(), "CmdInterface.WriteDataResponse() failed", $"0x{ex.HResult.ToString("X", this.Culture)}", String.Empty);
|
|
}
|
|
|
|
return Message;
|
|
}
|
|
|
|
|
|
public String ReadDataResponse(List<Byte> rxStringCommandChannel, Int32 displayOnTab, String jsonDataType)
|
|
{
|
|
|
|
#region Declarations and initializations
|
|
string tempLastReg = this.Gp30LastRegister;
|
|
String Message = String.Empty;
|
|
String Where = "Start";
|
|
Byte[] JsonData = new Byte[4];
|
|
this.MeterNumber = Constants.Meter1;
|
|
#endregion
|
|
|
|
try
|
|
{
|
|
|
|
if (!Int32.Equals(displayOnTab, SelectedTab.Json) && (!Int32.Equals(displayOnTab, SelectedTab.None)))
|
|
{
|
|
#region GP30 Pages
|
|
#region LED Mode / Keep authentified
|
|
if (tempLastReg.Equals(Register.Genesisflow.LedMode))
|
|
{
|
|
Where = "LED-Mode";
|
|
this.LedMode = rxStringCommandChannel.ElementAt(GP30BytePosition.Reply);
|
|
Message = $"COMMAND CHANNEL\t Received response on read 'LED Mode'-register = {this.LedMode.ToString(this.Culture)} at METER{this.MeterIndex}\n";
|
|
GENESIS_DISPLAY_TOOL.Display.Gp30readLedMode(this.LedMode, this.MeterNumber, this.Culture);
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region Percentage PATH0
|
|
if (tempLastReg.Equals(Register.Genesisflow.FirstHitPercent1))
|
|
{
|
|
Where = "Percentage PATH0";
|
|
this.PercentagePath0 = rxStringCommandChannel.ElementAt(GP30BytePosition.Reply);
|
|
GENESIS_DISPLAY_TOOL.Display.Gp30readPercentagePath0(PercentagePath0, this.MeterNumber, this.Culture);
|
|
Message = $"COMMAND CHANNEL\t Received response on read 'Percentage1'-register = {PercentagePath0.ToString(this.Culture)} at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region Percentage PATH1
|
|
if (tempLastReg.Equals(Register.Genesisflow.FirstHitPercent2))
|
|
{
|
|
Where = "Percentage PATH1";
|
|
this.PercentagePath1 = rxStringCommandChannel.ElementAt(GP30BytePosition.Reply);
|
|
GENESIS_DISPLAY_TOOL.Display.Gp30readPercentagePath1(PercentagePath1, this.MeterNumber, this.Culture);
|
|
Message = $"COMMAND CHANNEL\t Received response on read 'Percentage2'-register = {PercentagePath1.ToString(this.Culture)} at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region Percentage PATH2
|
|
if (tempLastReg.Equals(Register.Genesisflow.FirstHitPercent3))
|
|
{
|
|
Where = "Percentage PATH2";
|
|
this.PercentagePath2 = rxStringCommandChannel.ElementAt(GP30BytePosition.Reply);
|
|
GENESIS_DISPLAY_TOOL.Display.Gp30readPercentagePath2(PercentagePath2, this.MeterNumber, this.Culture);
|
|
Message = $"COMMAND CHANNEL\t Received response on read 'Percentage3'-register = {PercentagePath2.ToString(this.Culture)} at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region First hit level up PATH0
|
|
if (tempLastReg.Equals(Register.Genesisflow.FirstHitLvlUp1))
|
|
{
|
|
Where = "Firsthit Up PATH0";
|
|
this.FirstHitLevelUpPath0 = rxStringCommandChannel.ElementAt(GP30BytePosition.Reply);
|
|
GENESIS_DISPLAY_TOOL.Display.Gp30readFirstHitLevelUpPath0(FirstHitLevelUpPath0, this.MeterNumber, this.Culture);
|
|
GENESIS_DISPLAY_TOOL.Display.Gp30readFirstHitVoltageUpPath0(FirstHitLevelUpPath0, this.MeterNumber, this.Culture);
|
|
Message = $"COMMAND CHANNEL\t Received response on read 'First hit level up'-register, PATH1 = {this.FirstHitLevelUpPath0.ToString(this.Culture)} ({(FirstHitLevelUpPath0 * Constants.FirstHitLevelFactor).ToString(this.Culture)} mV)' at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region First hit level up PATH1
|
|
if (tempLastReg.Equals(Register.Genesisflow.FirstHitLvlUp2))
|
|
{
|
|
Where = "Firsthit Up PATH1";
|
|
this.FirstHitLevelUpPath1 = rxStringCommandChannel.ElementAt(GP30BytePosition.Reply);
|
|
GENESIS_DISPLAY_TOOL.Display.Gp30readFirstHitLevelUpPath1(FirstHitLevelUpPath1, this.MeterNumber, this.Culture);
|
|
GENESIS_DISPLAY_TOOL.Display.Gp30readFirstHitVoltageUpPath1(FirstHitLevelUpPath1, this.MeterNumber, this.Culture);
|
|
Message = $"COMMAND CHANNEL\t Received response on read 'First hit level up'-register, PATH2 = {this.FirstHitLevelUpPath1.ToString(this.Culture)} ({(FirstHitLevelUpPath1 * Constants.FirstHitLevelFactor).ToString(this.Culture)} mV)' at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region First hit level up PATH2
|
|
if (tempLastReg.Equals(Register.Genesisflow.FirstHitLvlUp3))
|
|
{
|
|
Where = "Firsthit Up PATH2";
|
|
this.FirstHitLevelUpPath2 = rxStringCommandChannel.ElementAt(GP30BytePosition.Reply);
|
|
GENESIS_DISPLAY_TOOL.Display.Gp30readFirstHitLevelUpPath2(FirstHitLevelUpPath2, this.MeterNumber, this.Culture);
|
|
GENESIS_DISPLAY_TOOL.Display.Gp30readFirstHitVoltageUpPath2(FirstHitLevelUpPath2, this.MeterNumber, this.Culture);
|
|
Message = $"COMMAND CHANNEL\t Received response on read 'First hit level up'-register, PATH3 = {this.FirstHitLevelUpPath2.ToString(this.Culture)} ({(FirstHitLevelUpPath2 * Constants.FirstHitLevelFactor).ToString(this.Culture)} mV)' at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region First hit level down PATH0
|
|
if (tempLastReg.Equals(Register.Genesisflow.FirstHitLvlDown1))
|
|
{
|
|
Where = "Firsthit Down PATH0";
|
|
this.FirstHitLevelDownPath0 = rxStringCommandChannel.ElementAt(GP30BytePosition.Reply);
|
|
GENESIS_DISPLAY_TOOL.Display.Gp30readFirstHitLevelDownPath0(FirstHitLevelDownPath0, this.MeterNumber, this.Culture);
|
|
GENESIS_DISPLAY_TOOL.Display.Gp30readFirstHitVoltageDownPath0(FirstHitLevelDownPath0, this.MeterNumber, this.Culture);
|
|
Message = $"COMMAND CHANNEL\t Received response on read 'First hit level down'-register, PATH1 = {FirstHitLevelDownPath0.ToString(this.Culture)} ({(FirstHitLevelDownPath0 * Constants.FirstHitLevelFactor).ToString(this.Culture)} mV)' at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region First hit level down PATH1
|
|
if (tempLastReg.Equals(Register.Genesisflow.FirstHitLvlDown2))
|
|
{
|
|
Where = "Firsthit Down PATH1";
|
|
this.FirstHitLevelDownPath1 = rxStringCommandChannel.ElementAt(GP30BytePosition.Reply);
|
|
GENESIS_DISPLAY_TOOL.Display.Gp30readFirstHitLevelDownPath1(FirstHitLevelDownPath1, this.MeterNumber, this.Culture);
|
|
GENESIS_DISPLAY_TOOL.Display.Gp30readFirstHitVoltageDownPath1(FirstHitLevelDownPath1, this.MeterNumber, this.Culture);
|
|
Message = $"COMMAND CHANNEL\t Received response on read 'First hit level down'-register, PATH2 = {FirstHitLevelDownPath1.ToString(this.Culture)} ({(FirstHitLevelDownPath1 * Constants.FirstHitLevelFactor).ToString(this.Culture)} mV)' at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region First hit level down PATH2
|
|
if (tempLastReg.Equals(Register.Genesisflow.FirstHitLvlDown3))
|
|
{
|
|
Where = "Firsthit Down PATH2";
|
|
this.FirstHitLevelDownPath2 = rxStringCommandChannel.ElementAt(GP30BytePosition.Reply);
|
|
GENESIS_DISPLAY_TOOL.Display.Gp30readFirstHitLevelDownPath2(FirstHitLevelDownPath2, this.MeterNumber, this.Culture);
|
|
GENESIS_DISPLAY_TOOL.Display.Gp30readFirstHitVoltageDownPath2(FirstHitLevelDownPath2, this.MeterNumber, this.Culture);
|
|
Message = $"COMMAND CHANNEL\t Received response on read 'First hit level down'-register, PATH3 = {FirstHitLevelDownPath2.ToString(this.Culture)} ({(FirstHitLevelDownPath2 * Constants.FirstHitLevelFactor).ToString(this.Culture)} mV)' at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region Number of TX bursts
|
|
if (tempLastReg.Equals(Register.Genesisflow.NumFirePulses))
|
|
{
|
|
Where = "TX bursts";
|
|
this.NumberOfFirePulses = rxStringCommandChannel.ElementAt(GP30BytePosition.Reply);
|
|
GENESIS_DISPLAY_TOOL.Display.Gp30readTxBursts(NumberOfFirePulses, this.MeterNumber, this.Culture);
|
|
Message = $"COMMAND CHANNEL\t Received response on read 'Number of fire pulses'-register = {NumberOfFirePulses.ToString(this.Culture)} at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region Starthit
|
|
if (tempLastReg.Equals(Register.Genesisflow.StartHit))
|
|
{
|
|
Where = "Starthit";
|
|
this.Starthit = rxStringCommandChannel.ElementAt(GP30BytePosition.Reply);
|
|
GENESIS_DISPLAY_TOOL.Display.Gp30readStarthit(Starthit, this.MeterNumber, this.Culture);
|
|
Message = $"COMMAND CHANNEL\t Received response on read 'Starthit'-register = {Starthit.ToString(this.Culture)} at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region Amplitude end detect
|
|
if (tempLastReg.Equals(Register.Genesisflow.AmplitudePeakDetectEnd))
|
|
{
|
|
Where = "Amplitude";
|
|
this.Amplitude = rxStringCommandChannel.ElementAt(GP30BytePosition.Reply);
|
|
GENESIS_DISPLAY_TOOL.Display.Gp30readAmplitude(Amplitude, this.MeterNumber, this.Culture);
|
|
Message = $"COMMAND CHANNEL\t Received response on read 'Amplitude peak detect end'-register = {Amplitude.ToString(this.Culture)} at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region Samplerate
|
|
if (tempLastReg.Equals(Register.Genesisflow.SampleRate))
|
|
{
|
|
Where = "Samplerate";
|
|
this.Samplerate = rxStringCommandChannel.ElementAt(GP30BytePosition.Reply);
|
|
GENESIS_DISPLAY_TOOL.Display.Gp30readSamplerate(Samplerate, this.MeterNumber, this.Culture);
|
|
Message = $"COMMAND CHANNEL\t Received response on read 'Samplerate'-register = {Samplerate.ToString(this.Culture)} at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region Calibration factor PATH0
|
|
if (tempLastReg.Equals(Register.Genesisflow.CalFactor1))
|
|
{
|
|
Where = "CalFactor1";
|
|
Byte[] TempArray = new Byte[2];
|
|
TempArray = rxStringCommandChannel.GetRange(GP30BytePosition.Reply, 2).ToArray();
|
|
TempArray.Reverse();
|
|
CalibrationFactorPath0 = BitConverter.ToUInt16(TempArray, 0);
|
|
GENESIS_DISPLAY_TOOL.Display.Gp30readCalibrationFactorPath0(CalibrationFactorPath0, this.MeterNumber, this.Culture);
|
|
Message = $"COMMAND CHANNEL\t Received response on read 'Calibration factor1'-register = {CalibrationFactorPath0.ToString(this.Culture)} at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region Calibration factor PATH1
|
|
if (tempLastReg.Equals(Register.Genesisflow.CalFactor2))
|
|
{
|
|
Where = "CalFactor2";
|
|
Byte[] TempArray = new Byte[2];
|
|
TempArray = rxStringCommandChannel.GetRange(GP30BytePosition.Reply, 2).ToArray();
|
|
TempArray.Reverse();
|
|
CalibrationFactorPath1 = BitConverter.ToUInt16(TempArray, 0);
|
|
GENESIS_DISPLAY_TOOL.Display.Gp30readCalibrationFactorPath1(CalibrationFactorPath1, MeterNumber, this.Culture);
|
|
Message = $"COMMAND CHANNEL\t Received response on read 'Calibration factor2'-register = {CalibrationFactorPath1.ToString(this.Culture)} at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region Calibration factor PATH2
|
|
if (tempLastReg.Equals(Register.Genesisflow.CalFactor3))
|
|
{
|
|
Where = "CalFactor1";
|
|
Byte[] TempArray = new Byte[2];
|
|
TempArray = rxStringCommandChannel.GetRange(GP30BytePosition.Reply, 2).ToArray();
|
|
TempArray.Reverse();
|
|
CalibrationFactorPath2 = BitConverter.ToUInt16(TempArray, 0);
|
|
GENESIS_DISPLAY_TOOL.Display.Gp30readCalibrationFactorPath2(CalibrationFactorPath2, MeterNumber, this.Culture);
|
|
Message = $"COMMAND CHANNEL\t Received response on read 'Calibration factor3'-register = {CalibrationFactorPath2.ToString(this.Culture)} at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region Zeroflow offset PATH0
|
|
if (tempLastReg.Equals(Register.Genesisflow.ZeroOffset1))
|
|
{
|
|
Where = "ZeroOffset1";
|
|
Byte[] TempArray = new Byte[4];
|
|
TempArray = rxStringCommandChannel.GetRange(GP30BytePosition.Reply, 4).ToArray();
|
|
TempArray.Reverse();
|
|
this.ZeroOffsetPath0 = BitConverter.ToInt32(TempArray, 0);
|
|
GENESIS_DISPLAY_TOOL.Display.Gp30readZeroOffsetPath0(ZeroOffsetPath0, MeterNumber, this.Culture);
|
|
Message = $"COMMAND CHANNEL\t Received response on read 'Zeroflow offset1'-register = {ZeroOffsetPath0.ToString(this.Culture)} at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region Zeroflow offset PATH1
|
|
if (tempLastReg.Equals(Register.Genesisflow.ZeroOffset2))
|
|
{
|
|
Where = "ZeroOffset2";
|
|
Byte[] TempArray = new Byte[4];
|
|
TempArray = rxStringCommandChannel.GetRange(GP30BytePosition.Reply, 4).ToArray();
|
|
TempArray.Reverse();
|
|
this.ZeroOffsetPath1 = BitConverter.ToInt32(TempArray, 0);
|
|
GENESIS_DISPLAY_TOOL.Display.Gp30readZeroOffsetPath1(ZeroOffsetPath1, MeterNumber, this.Culture);
|
|
Message = $"COMMAND CHANNEL\t Received response on read 'Zeroflow offset2'-register = {ZeroOffsetPath1.ToString(this.Culture)} at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region Zeroflow offset PATH2
|
|
if (tempLastReg.Equals(Register.Genesisflow.ZeroOffset3))
|
|
{
|
|
Where = "ZeroOffset3";
|
|
Byte[] TempArray = new Byte[4];
|
|
TempArray = rxStringCommandChannel.GetRange(GP30BytePosition.Reply, 4).ToArray();
|
|
TempArray.Reverse();
|
|
this.ZeroOffsetPath2 = BitConverter.ToInt32(TempArray, 0);
|
|
GENESIS_DISPLAY_TOOL.Display.Gp30readZeroOffsetPath2(ZeroOffsetPath2, MeterNumber, this.Culture);
|
|
Message = $"COMMAND CHANNEL\t Received response on read 'Zeroflow offset3'-register = {ZeroOffsetPath2.ToString(this.Culture)} at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region Voltage
|
|
if (tempLastReg.Equals(Register.Powermon.BatteryVoltage))
|
|
{
|
|
Where = "Voltage";
|
|
Byte[] TempArray = new Byte[4];
|
|
TempArray = rxStringCommandChannel.GetRange(GP30BytePosition.Reply, 2).ToArray();
|
|
TempArray.Reverse();
|
|
this.Voltage = BitConverter.ToUInt16(TempArray, 0);
|
|
GENESIS_DISPLAY_TOOL.Display.Gp30readVoltage(Voltage, MeterNumber, this.Culture);
|
|
Message = $"COMMAND CHANNEL\t Received response on read 'Battery voltage'-register = {Voltage.ToString(this.Culture)} at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region Metersize
|
|
if (tempLastReg.Equals(Register.Genesisflow.MeterSize))
|
|
{
|
|
Where = "Metersize";
|
|
this.Metersize = rxStringCommandChannel.ElementAt(GP30BytePosition.Reply);
|
|
GENESIS_DISPLAY_TOOL.Display.Gp30readMetersize(Metersize, MeterNumber, this.Culture);
|
|
Message = $"COMMAND CHANNEL\t Received response on read 'Metersize'-register = {Metersize.ToString(this.Culture)} at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region Forward arrow
|
|
if (tempLastReg.Equals(Register.Genesisflow.ForwardArrow))
|
|
{
|
|
Where = "ForwardArrow";
|
|
this.Arrow = rxStringCommandChannel.ElementAt(GP30BytePosition.Reply);
|
|
GENESIS_DISPLAY_TOOL.Display.Gp30readArrow(Arrow, MeterNumber, this.Culture);
|
|
Message = $"COMMAND CHANNEL\t Received response on read 'Forward arrow'-register = {Arrow.ToString(this.Culture)} at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region TofTempOffset PATH0
|
|
if (tempLastReg.Equals(Register.Genesisflow.ToFTempOffset1))
|
|
{
|
|
Where = "ToFTempOffset1";
|
|
Byte[] TempArray = new Byte[4];
|
|
TempArray = rxStringCommandChannel.GetRange(GP30BytePosition.Reply, 4).ToArray();
|
|
TempArray.Reverse();
|
|
this.ToFTempOffsetPath0 = BitConverter.ToUInt32(TempArray, 0);
|
|
Message = $"COMMAND CHANNEL\t Received response on read 'ToFTempOffset1'-register = {ToFTempOffsetPath0.ToString(this.Culture)} at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region TofTempOffset PATH1
|
|
if (tempLastReg.Equals(Register.Genesisflow.ToFTempOffset2))
|
|
{
|
|
Where = "ToFTempOffset2";
|
|
Byte[] TempArray = new Byte[4];
|
|
TempArray = rxStringCommandChannel.GetRange(GP30BytePosition.Reply, 4).ToArray();
|
|
TempArray.Reverse();
|
|
this.ToFTempOffsetPath1 = BitConverter.ToUInt32(TempArray, 0);
|
|
Message = $"COMMAND CHANNEL\t Received response on read 'ToFTempOffset2'-register = {ToFTempOffsetPath1.ToString(this.Culture)} at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region TofTempOffset PATH2
|
|
if (tempLastReg.Equals(Register.Genesisflow.ToFTempOffset3))
|
|
{
|
|
Where = "ToFTempOffset3";
|
|
Byte[] TempArray = new Byte[4];
|
|
TempArray = rxStringCommandChannel.GetRange(GP30BytePosition.Reply, 4).ToArray();
|
|
TempArray.Reverse();
|
|
this.ToFTempOffsetPath2 = BitConverter.ToUInt32(TempArray, 0);
|
|
Message = $"COMMAND CHANNEL\t Received response on read 'ToFTempOffset3'-register = {ToFTempOffsetPath2.ToString(this.Culture)} at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region Zero offset PATH0
|
|
if (tempLastReg.Equals(Register.Genesisflow.ZeroOffset1))
|
|
{
|
|
Where = "ZeroOffset1";
|
|
Byte[] TempArray = new Byte[4];
|
|
TempArray = rxStringCommandChannel.GetRange(GP30BytePosition.Reply, 4).ToArray();
|
|
TempArray.Reverse();
|
|
this.ZeroOffsetPath0 = BitConverter.ToInt32(TempArray, 0);
|
|
GENESIS_DISPLAY_TOOL.Display.Gp30readZeroOffsetPath0(ZeroOffsetPath0, MeterNumber, this.Culture);
|
|
Message = $"COMMAND CHANNEL\t Received response on read 'ZeroFlowOffset1'-register = {ZeroOffsetPath0.ToString(this.Culture)} at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region Zero offset PATH1
|
|
if (tempLastReg.Equals(Register.Genesisflow.ZeroOffset2))
|
|
{
|
|
Where = "ZeroOffset2";
|
|
Byte[] TempArray = new Byte[4];
|
|
TempArray = rxStringCommandChannel.GetRange(GP30BytePosition.Reply, 4).ToArray();
|
|
TempArray.Reverse();
|
|
this.ZeroOffsetPath1 = BitConverter.ToInt32(TempArray, 0);
|
|
GENESIS_DISPLAY_TOOL.Display.Gp30readZeroOffsetPath1(ZeroOffsetPath1, MeterNumber, this.Culture);
|
|
Message = $"COMMAND CHANNEL\t Received response on read 'ZeroFlowOffset2'-register = {ZeroOffsetPath1.ToString(this.Culture)} at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region Zero offset PATH2
|
|
if ((tempLastReg.Equals(Register.Genesisflow.ZeroOffset3)))
|
|
{
|
|
Where = "ZeroOffset3";
|
|
Byte[] TempArray = new Byte[4];
|
|
TempArray = rxStringCommandChannel.GetRange(GP30BytePosition.Reply, 4).ToArray();
|
|
TempArray.Reverse();
|
|
this.ZeroOffsetPath2 = BitConverter.ToInt32(TempArray, 0);
|
|
GENESIS_DISPLAY_TOOL.Display.Gp30readZeroOffsetPath2(ZeroOffsetPath2, MeterNumber, this.Culture);
|
|
Message = $"COMMAND CHANNEL\t Received response on read 'ZeroFlowOffset3'-register = {ZeroOffsetPath2.ToString(this.Culture)} at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
#region Unknown register
|
|
Message = $"COMMAND CHANNEL\t Received response on read unknown register = {ZeroOffsetPath2.ToString(this.Culture)} at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
#endregion
|
|
#endregion
|
|
}
|
|
else
|
|
{
|
|
#region JSON
|
|
if (Int32.Equals(displayOnTab, SelectedTab.Json))
|
|
{
|
|
var meter = ((GenesisMeter) ((GENESIS_DISPLAY_TOOL._GENESIS_DISPLAY_TOOL.GlobalMeterBatch)
|
|
.ListOfMeters.First()));
|
|
|
|
|
|
var registerResult = meter.GetRegisters(tempLastReg).First();
|
|
|
|
|
|
|
|
String Result = BitConverter.ToString(registerResult.Value);
|
|
GENESIS_DISPLAY_TOOL.Display.LabelJsonRead(Result);
|
|
GENESIS_DISPLAY_TOOL.Display.LabelJsonDec(tempLastReg, registerResult.Value, this.Culture);
|
|
Message = $"COMMAND CHANNEL\t Received response on read data from register {tempLastReg};\tValue = {Result} at METER{this.MeterIndex}\n";
|
|
}
|
|
else
|
|
Message = $"COMMAND CHANNEL\t Received response on read unknown register = {tempLastReg.ToString(this.Culture)} at METER{this.MeterIndex}\n";
|
|
#endregion
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ErrorLog.Log(LogErrReason.Exception(), "CmdInterface.ReadDataResponse() failed", $"0x{ex.HResult.ToString("X", this.Culture)}", Where);
|
|
}
|
|
|
|
#region Return
|
|
return Message;
|
|
#endregion
|
|
}
|
|
private String MultipleWriteDataResponse(List<Byte> rxStringCommandChannel)
|
|
{
|
|
String Message = String.Empty;
|
|
|
|
try
|
|
{
|
|
if (Enumerable.SequenceEqual(this.Gp30LastRegister, Register.Configexchange.Password))
|
|
{
|
|
Message = $"COMMAND CHANNEL\t Received response on 'Multiple write to password register'. Register:{Gp30LastRegister}; Data= 0x{BitConverter.ToString(rxStringCommandChannel.GetRange(GP30BytePosition.Reply, 4).ToArray())} at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
|
|
#region All others
|
|
else
|
|
{
|
|
Message = $"COMMAND CHANNEL\t Received response on 'Multiple write to register'. Register:{Gp30LastRegister}; Data= 0x{BitConverter.ToString(rxStringCommandChannel.GetRange(GP30BytePosition.Reply, 4).ToArray())} at METER{this.MeterIndex}\n";
|
|
return Message;
|
|
}
|
|
#endregion
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ErrorLog.Log(LogErrReason.Exception(), "CmdInterface.MulipleWriteDataResponse() failed", $"0x{ex.HResult.ToString("X", this.Culture)}", String.Empty);
|
|
}
|
|
|
|
return Message;
|
|
}
|
|
private Int32 Double0x5BGetLength(Byte[] inputData)
|
|
{
|
|
Int32 InputLength = inputData.Count();
|
|
Int32 NumberOf0x5B = 0;
|
|
Int32 TotalLength = 0;
|
|
|
|
try
|
|
{
|
|
for (Int16 InputIndex = 1; InputIndex < InputLength; InputIndex++)
|
|
{
|
|
if (Byte.Equals(inputData[InputIndex], GP30Commands.Startbyte))
|
|
NumberOf0x5B++;
|
|
}
|
|
TotalLength = InputLength + NumberOf0x5B;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ErrorLog.Log(LogErrReason.Exception(), "CmdInterface.Double0x5BGetLength() failed", $"0x{ex.HResult.ToString("X", this.Culture)}", String.Empty);
|
|
}
|
|
|
|
return TotalLength;
|
|
}
|
|
private Byte[] Double0x5B(Byte[] inputData)
|
|
{
|
|
#region Definitions and initializations
|
|
Int32 InputLength = 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 (Byte.Equals(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.Exception(), "CmdInterface.Double0x5BGetLength() failed", $"0x{ex.HResult.ToString("X", this.Culture)}", String.Empty);
|
|
}
|
|
|
|
return null;
|
|
}
|
|
public void DecodeHighLevelErrors(List<Byte> rxStringCmd, Int32 displayOnTab, String jsonDataType)
|
|
{
|
|
#region Definitions and initializations
|
|
String Timestamp = DateTime.Now.ToString(Formats.RawDataDateTimeLogString, this.Culture);
|
|
#endregion
|
|
#region CA1062
|
|
if (rxStringCmd == null)
|
|
return;
|
|
#endregion
|
|
#region Decode optical port errors (chapter 9.5.3)
|
|
if (Byte.Equals(rxStringCmd.ElementAt(GP30BytePosition.ErrCodeBase), GP30HighLevelErrors.Base))
|
|
{
|
|
if (Int32.Equals(displayOnTab, (Int32)SelectedTab.Json))
|
|
GENESIS_DISPLAY_TOOL.Display.JsonDisplayDebugMessage($"{Timestamp}\t{Gp30.ErrorMessages953(rxStringCmd)} at METER{this.MeterIndex}\n");
|
|
else
|
|
GENESIS_DISPLAY_TOOL.Display.CmdDecoded($"{Timestamp}\t{Gp30.ErrorMessages953(rxStringCmd)} at METER{this.MeterIndex}\n", this.MeterNumber);
|
|
//this.IndicatorsFailed();
|
|
rxStringCmd.Clear();
|
|
return;
|
|
}
|
|
#endregion
|
|
#region Decode config exchange errors (chapter 8.5.3)
|
|
if (Byte.Equals(rxStringCmd.ElementAt(GP30BytePosition.ErrCodeBase), GP30ConfigExErrors.Base))
|
|
{
|
|
if (Int32.Equals(displayOnTab, (Int32)SelectedTab.Json))
|
|
GENESIS_DISPLAY_TOOL.Display.JsonDisplayDebugMessage($"{Timestamp}\t{Gp30.ErrorMessages853(rxStringCmd)} at METER{this.MeterIndex}\n");
|
|
else
|
|
{
|
|
if (!Int32.Equals(displayOnTab, SelectedTab.None))
|
|
GENESIS_DISPLAY_TOOL.Display.CmdDecoded($"{Timestamp}\t{Gp30.ErrorMessages853(rxStringCmd)} at METER{this.MeterIndex}\n", this.MeterNumber);
|
|
}
|
|
//this.IndicatorsFailed();
|
|
rxStringCmd.Clear();
|
|
return;
|
|
}
|
|
#endregion
|
|
#region Decode response without errors
|
|
if ((Byte.Equals(rxStringCmd.ElementAt(GP30BytePosition.ErrCodeBase), GP30HighLevelErrors.BaseOk)) &&
|
|
(Byte.Equals(rxStringCmd.ElementAt(GP30BytePosition.ErrCodeBase), GP30ConfigExErrors.BaseOk)))
|
|
{
|
|
|
|
#region Response on 'Read data'
|
|
if (Byte.Equals(rxStringCmd.ElementAt(GP30BytePosition.Cmd), GP30Commands.ReadDataReply) || Byte.Equals(rxStringCmd.ElementAt(GP30BytePosition.Cmd), GP30Commands.MultipleReadDataReply))
|
|
{
|
|
#region Display message
|
|
if (Int32.Equals(displayOnTab, SelectedTab.Json))
|
|
GENESIS_DISPLAY_TOOL.Display.JsonDisplayDebugMessage($"{Timestamp}\t{this.ReadDataResponse(rxStringCmd, displayOnTab, jsonDataType)},");
|
|
else
|
|
{
|
|
if(!Int32.Equals(displayOnTab, SelectedTab.None))
|
|
GENESIS_DISPLAY_TOOL.Display.CmdDecoded($"{Timestamp}\t{this.ReadDataResponse(rxStringCmd, displayOnTab, jsonDataType)}", this.MeterNumber); // <===== Decoding of individual data
|
|
}
|
|
#endregion
|
|
#region Save payload
|
|
this.Gp30RXPayload = (byte)rxStringCmd.ElementAt(GP30BytePosition.Reply);
|
|
//this.IndicatorsOk();
|
|
rxStringCmd.Clear();
|
|
#endregion
|
|
return;
|
|
}
|
|
#endregion
|
|
#region Response on 'Write data'
|
|
if (Byte.Equals(rxStringCmd.ElementAt(GP30BytePosition.Cmd), GP30Commands.WriteDataReply))
|
|
{
|
|
if (Int32.Equals(displayOnTab, SelectedTab.Json))
|
|
GENESIS_DISPLAY_TOOL.Display.JsonDisplayDebugMessage($"{Timestamp}\t{this.WriteDataResponse(rxStringCmd, displayOnTab)}");
|
|
else
|
|
{
|
|
if (!Int32.Equals(displayOnTab, SelectedTab.None))
|
|
GENESIS_DISPLAY_TOOL.Display.CmdDecoded($"{Timestamp}\t{this.WriteDataResponse(rxStringCmd, displayOnTab)}", this.MeterNumber);
|
|
}
|
|
//this.IndicatorsOk();
|
|
rxStringCmd.Clear();
|
|
return;
|
|
}
|
|
#endregion
|
|
#region Response to 'Multiple write data'
|
|
if (Byte.Equals(this.Gp30LastCommand, GP30Commands.MultipleWriteDataReply))
|
|
{
|
|
if (Int32.Equals(displayOnTab, (Int32)SelectedTab.Json))
|
|
GENESIS_DISPLAY_TOOL.Display.JsonDisplayDebugMessage($"{Timestamp}\t{this.MultipleWriteDataResponse(rxStringCmd)}");
|
|
else
|
|
{
|
|
if (!Int32.Equals(displayOnTab, SelectedTab.None))
|
|
GENESIS_DISPLAY_TOOL.Display.CmdDecoded($"{Timestamp}\t{this.MultipleWriteDataResponse(rxStringCmd)}", this.MeterNumber);
|
|
}
|
|
//this.IndicatorsOk();
|
|
rxStringCmd.Clear();
|
|
return;
|
|
}
|
|
#endregion
|
|
//this.IndicatorsOk();
|
|
}
|
|
#endregion
|
|
#region Unknown error code
|
|
if ((!Byte.Equals(rxStringCmd.ElementAt(GP30BytePosition.ErrCodeBase), GP30HighLevelErrors.BaseOk)) &&
|
|
(!Byte.Equals(rxStringCmd.ElementAt(GP30BytePosition.ErrCodeBase), GP30ConfigExErrors.BaseOk)) &&
|
|
(!Byte.Equals(rxStringCmd.ElementAt(GP30BytePosition.ErrCodeBase), GP30HighLevelErrors.Base)) &&
|
|
(!Byte.Equals(rxStringCmd.ElementAt(GP30BytePosition.ErrCodeBase), GP30ConfigExErrors.Base)))
|
|
{
|
|
if (Int32.Equals(displayOnTab, (Int32)SelectedTab.Json))
|
|
GENESIS_DISPLAY_TOOL.Display.JsonDisplayDebugMessage($"{Timestamp}\tCOMMAND CHANNEL\t Received unknown Error Code\t\t\tValue = {BitConverter.ToString(rxStringCmd.GetRange(GP30BytePosition.ErrCodeBase, 2).ToArray(), 0, 2)} at METER{this.MeterIndex}\n");
|
|
else
|
|
{
|
|
if (!Int32.Equals(displayOnTab, SelectedTab.None))
|
|
GENESIS_DISPLAY_TOOL.Display.CmdDecoded($"{Timestamp}\tCOMMAND CHANNEL\t Received unknown Error Code\t\t\tValue= {BitConverter.ToString(rxStringCmd.GetRange(GP30BytePosition.ErrCodeBase, 2).ToArray(), 0, 2)} at METER{this.MeterIndex}\n", this.MeterNumber);
|
|
}
|
|
//this.IndicatorsFailed();
|
|
rxStringCmd.Clear();
|
|
}
|
|
#endregion
|
|
rxStringCmd.Clear();
|
|
}
|
|
}
|
|
|
|
public class Gp30LastParameter
|
|
{
|
|
public UInt16 MeterNumber = 0;
|
|
public Byte[] Register = new Byte[2] { 0, 0 };
|
|
}
|
|
public class SelectedTab
|
|
{
|
|
public const Int32 Json = 0;
|
|
public const Int32 Gp30Meter1 = 1;
|
|
public const Int32 Gp30Meter2 = 2;
|
|
public const Int32 Gp30Meter3 = 3;
|
|
public const Int32 None = 4;
|
|
}
|
|
|
|
public partial class GENESIS_DISPLAY_TOOL : Form
|
|
{
|
|
#region Definitions and initializations
|
|
private Byte[] Gp30RxPayload = new Byte[2] { 0, 0 };
|
|
#endregion
|
|
|
|
private void GetReplyCmdMeterFromCommon1(List<Byte> currentResponse)
|
|
{
|
|
String JsonDataType = GetJsonDataType();
|
|
|
|
if (!Int32.Equals(DisplayOnTab, SelectedTab.Json))
|
|
{
|
|
//try
|
|
//{
|
|
var tmpList = new List<Byte>();
|
|
for (UInt16 i = 0; i < (currentResponse.Count()); i++) // erase
|
|
tmpList.Add(currentResponse.ElementAt(i)); // erase
|
|
|
|
#region Error decoding
|
|
CommandInterface1.DecodeHighLevelErrors(tmpList, DisplayOnTab, JsonDataType);
|
|
tmpList.Clear();
|
|
//currentResponse.Clear();
|
|
#endregion
|
|
//}
|
|
//catch (Exception ex)
|
|
//{
|
|
// #region Error: exception
|
|
// ErrorLog.Log(LogErrReason.Exception(), "Gp30RxDataMeter1() failed", "0x" + ex.HResult.ToString("X", culture), String.Empty);
|
|
// MessageBox.Show("COMMAND CHANNEL RX-Dectection error!", "Form closing", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
// #endregion
|
|
//}
|
|
}
|
|
else
|
|
{
|
|
var tmpList = new List<Byte>();
|
|
for (UInt16 i = 0; i < (currentResponse.Count()); i++)
|
|
tmpList.Add(currentResponse.ElementAt(i));
|
|
|
|
CommandInterface1.DecodeHighLevelErrors(tmpList, DisplayOnTab, JsonDataType);
|
|
tmpList.Clear();
|
|
}
|
|
}
|
|
|
|
private void GetReplyCmdMeter1(object sender, EventArgs e)
|
|
{
|
|
//CultureInfo culture = GENESIS_DISPLAY_TOOL._GENESIS_DISPLAY_TOOL.GetGlobalCulture();
|
|
|
|
//if (tab_Maintab.SelectedTab != tab_Json)
|
|
//{
|
|
//try
|
|
//{
|
|
#region Decode reply command
|
|
//WaitForBackgroundWorkers();
|
|
//rTB_CommandChannelDecodedMeter1.AppendText(CommandInterface1.ReplyCommand(RxStringCmd[MeterNumber]));
|
|
//rTB_CommandChannelDecodedMeter1.ScrollToCaret();
|
|
#endregion
|
|
#region Error decoding
|
|
//CommandInterface1.DecodeHighLevelErrors(RxStringCmd[MeterNumber], MeterNumber, DisplayOnTab);
|
|
//RxStringCmd[MeterNumber].Clear();
|
|
#endregion
|
|
//}
|
|
//catch (Exception ex)
|
|
//{
|
|
// #region Error: exception
|
|
// ErrorLog.Log(LogErrReason.Exception(), "Gp30RxDataMeter1() failed", "0x" + ex.HResult.ToString("X", culture), String.Empty);
|
|
// MessageBox.Show("COMMAND CHANNEL RX-Dectection error!", "Form closing", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
// #endregion
|
|
//}
|
|
//}
|
|
}
|
|
private void GetReplyCmdMeter2(object sender, EventArgs e)
|
|
{
|
|
CultureInfo culture = GENESIS_DISPLAY_TOOL._GENESIS_DISPLAY_TOOL.GetGlobalCulture();
|
|
|
|
if (tab_Maintab.SelectedTab != tab_Json)
|
|
{
|
|
try
|
|
{
|
|
#region Decode reply command
|
|
WaitForBackgroundWorkers();
|
|
//rTB_CommandChannelDecodedMeter2.AppendText(CommandInterface2.ReplyCommand(RxStringCmd[MeterNumber]));
|
|
//rTB_CommandChannelDecodedMeter2.ScrollToCaret();
|
|
#endregion
|
|
#region Decode errors
|
|
// CommandInterface2.DecodeHighLevelErrors(RxStringCmd[MeterNumber], MeterNumber, DisplayOnTab);
|
|
// RxStringCmd[MeterNumber].Clear();
|
|
#endregion
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#region Error: exception
|
|
ErrorLog.Log(LogErrReason.Exception(), "Gp30RxDataMeter2() failed", $"0x{ex.HResult.ToString("X", culture)}", String.Empty);
|
|
MessageBox.Show("COMMAND CHANNEL RX-Dectection error!", "Form closing", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
}
|
|
private void GetReplyCmdMeter3(object sender, EventArgs e)
|
|
{
|
|
CultureInfo culture = GENESIS_DISPLAY_TOOL._GENESIS_DISPLAY_TOOL.GetGlobalCulture();
|
|
|
|
if (tab_Maintab.SelectedTab != tab_Json)
|
|
{
|
|
try
|
|
{
|
|
#region Decode reply command
|
|
WaitForBackgroundWorkers();
|
|
//rTB_CommandChannelDecodedMeter3.AppendText(CommandInterface3.ReplyCommand(RxStringCmd[MeterNumber]));
|
|
//rTB_CommandChannelDecodedMeter3.ScrollToCaret();
|
|
#endregion
|
|
#region Decode errors
|
|
// CommandInterface3.DecodeHighLevelErrors(RxStringCmd[MeterNumber], MeterNumber, DisplayOnTab);
|
|
// RxStringCmd[MeterNumber].Clear();
|
|
#endregion
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#region Error: exception
|
|
ErrorLog.Log(LogErrReason.Exception(), "Gp30RxDataMeter3() failed", $"0x{ex.HResult.ToString("X", culture)}", String.Empty);
|
|
MessageBox.Show("COMMAND CHANNEL RX-Dectection error!", "Form closing", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public static class Gp30
|
|
{
|
|
private static CultureInfo culture = GENESIS_DISPLAY_TOOL._GENESIS_DISPLAY_TOOL.GetGlobalCulture();
|
|
|
|
public static List<Byte> Remove0x5B(List<Byte> inputData, CultureInfo setCulture)
|
|
{
|
|
#region Definitions and initializations
|
|
Int32 InputLength = inputData.Count();
|
|
Int32 InputIndex = 0;
|
|
Byte LastData = 0;
|
|
Byte CurrentData = 0;
|
|
List<Byte> OutputData = new List<Byte>();
|
|
#endregion
|
|
|
|
try
|
|
{
|
|
#region Prepare output data
|
|
for (InputIndex = 0; InputIndex < InputLength; InputIndex++)
|
|
{
|
|
CurrentData = inputData.ElementAt(InputIndex);
|
|
if (!((Byte.Equals(LastData, GP30Commands.Startbyte)) && ( Byte.Equals(CurrentData, GP30Commands.Startbyte))))
|
|
{
|
|
OutputData.Add(CurrentData);
|
|
LastData = CurrentData;
|
|
}
|
|
else
|
|
LastData = 0;
|
|
}
|
|
#endregion
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ErrorLog.Log(LogErrReason.Exception(), "GP30.Remove0x5B() failed", $"0x{ex.HResult.ToString("X", culture)}", $"Index = {InputIndex.ToString(setCulture)}");
|
|
}
|
|
|
|
return OutputData;
|
|
}
|
|
public static String ErrorMessages953(List<Byte> rxStringCommandChannel)
|
|
{
|
|
#region Definitions and initializations
|
|
String Message = String.Empty;
|
|
#endregion
|
|
|
|
try
|
|
{
|
|
#region Decode optical port errors (chapter 9.5.3 of breeze specification document)
|
|
// See 'Functional Specification Breeze Core and Applications'
|
|
switch (rxStringCommandChannel.ElementAt(GP30BytePosition.ErrCodeSubreason))
|
|
{
|
|
case GP30HighLevelErrors.CrcFailure:
|
|
Message = "COMMAND CHANNEL\t ERROR: CRC Failure";
|
|
break;
|
|
case GP30HighLevelErrors.InvalidEscape:
|
|
Message = "COMMAND CHANNEL\t ERROR: INVALIDESCAPE";
|
|
break;
|
|
case GP30HighLevelErrors.InvalidBaudrate:
|
|
Message = "COMMAND CHANNEL\t ERROR: INVALID_BAUDRATE";
|
|
break;
|
|
case GP30HighLevelErrors.InvalidBuffersize:
|
|
Message = "COMMAND CHANNEL\t ERROR: INVALID_BUFFERSIZE";
|
|
break;
|
|
case GP30HighLevelErrors.InvalidSubreason:
|
|
Message = "COMMAND CHANNEL\t ERROR: INVALID_SUBREASON";
|
|
break;
|
|
case GP30HighLevelErrors.NoBreak:
|
|
Message = "COMMAND CHANNEL\t ERROR: NOBREAK";
|
|
break;
|
|
case GP30HighLevelErrors.Overflow:
|
|
Message = "COMMAND CHANNEL\t ERROR: OVERFLOW";
|
|
break;
|
|
case GP30HighLevelErrors.PacketTimeout:
|
|
Message = "COMMAND CHANNEL\t ERROR: PACKETTIMEOUT";
|
|
break;
|
|
case GP30HighLevelErrors.PayloadCount:
|
|
Message = "COMMAND CHANNEL\t ERROR: PAYLOAD_COUNT";
|
|
break;
|
|
case GP30HighLevelErrors.TrainingFailed:
|
|
Message = "COMMAND CHANNEL\t ERROR: TRAINING_FAILED";
|
|
break;
|
|
case GP30HighLevelErrors.UnknownParameter:
|
|
Message = "COMMAND CHANNEL\t ERROR: UNKNOWN_PARAMETER";
|
|
break;
|
|
case GP30HighLevelErrors.UnrecognizedCmd:
|
|
Message = "COMMAND CHANNEL\t ERROR: UNRECOGNISEDCMD";
|
|
break;
|
|
default:
|
|
Message = "COMMAND CHANNEL\t ERROR: Unkwown failure code";
|
|
break;
|
|
}
|
|
#endregion
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ErrorLog.Log(LogErrReason.Exception(), "GP30.ErrorMessages953() failed", $"0x{ex.HResult.ToString("X", culture)}", String.Empty);
|
|
}
|
|
#region Return
|
|
return Message;
|
|
#endregion
|
|
}
|
|
|
|
public static String ErrorMessages853(List<Byte> rxStringCommandChannel)
|
|
{
|
|
String Message = String.Empty;
|
|
|
|
|
|
try
|
|
{
|
|
#region Decode optical port errors (chapter 9.5.3 of breeze specification document)
|
|
// See 'Functional Specification Breeze Core and Applications'
|
|
switch (rxStringCommandChannel.ElementAt(GP30BytePosition.ErrCodeSubreason))
|
|
{
|
|
case (GP30ConfigExErrors.LockedOut):
|
|
Message = "COMMAND CHANNEL\t ERROR: Locked out";
|
|
break;
|
|
case (GP30ConfigExErrors.AuthenticationFail):
|
|
Message = "COMMAND CHANNEL\t ERROR: Authenfication failure";
|
|
break;
|
|
case (GP30ConfigExErrors.AccessDenied):
|
|
Message = "COMMAND CHANNEL\t ERROR: Access denied!";
|
|
break;
|
|
case (GP30ConfigExErrors.UnknownParameter):
|
|
Message = "COMMAND CHANNEL\t ERROR: Unknown parameter";
|
|
break;
|
|
case (GP30ConfigExErrors.InUse):
|
|
Message = "COMMAND CHANNEL\t ERROR: In use";
|
|
break;
|
|
case (GP30ConfigExErrors.SizesDoNotMatch):
|
|
Message = "COMMAND CHANNEL\t ERROR: Sizes don't match";
|
|
break;
|
|
case (GP30ConfigExErrors.CannotReadConfigfile):
|
|
Message = "COMMAND CHANNEL\t ERROR: Can't read config file";
|
|
break;
|
|
case (GP30ConfigExErrors.UserNotKnown):
|
|
Message = "COMMAND CHANNEL\t ERROR: User not known";
|
|
break;
|
|
case (GP30ConfigExErrors.CannotCreateConfigFile):
|
|
Message = "COMMAND CHANNEL\t ERROR: Can't create config file";
|
|
break;
|
|
case (GP30ConfigExErrors.StoreDidNotStore):
|
|
Message = "COMMAND CHANNEL\t ERROR: Store didn't store";
|
|
break;
|
|
case (GP30ConfigExErrors.StoreCorrupt):
|
|
Message = "COMMAND CHANNEL\t ERROR: Store corrupt";
|
|
break;
|
|
case (GP30ConfigExErrors.ExpectedWrite):
|
|
Message = "COMMAND CHANNEL\t ERROR: Expected write";
|
|
break;
|
|
case (GP30ConfigExErrors.ExpectedRead):
|
|
Message = "COMMAND CHANNEL\t ERROR: Expected read";
|
|
break;
|
|
case (GP30ConfigExErrors.StopCycling):
|
|
Message = "COMMAND CHANNEL\t ERROR: Stop cycling";
|
|
break;
|
|
case (GP30ConfigExErrors.TooManyOpen):
|
|
Message = "COMMAND CHANNEL\t ERROR: Too many open";
|
|
break;
|
|
case (GP30ConfigExErrors.NeverOpened):
|
|
Message = "COMMAND CHANNEL\t ERROR: Never opened";
|
|
break;
|
|
case (GP30ConfigExErrors.FileProtected):
|
|
Message = "COMMAND CHANNEL\t ERROR: File protected";
|
|
break;
|
|
case (GP30ConfigExErrors.PartialRecall):
|
|
Message = "COMMAND CHANNEL\t ERROR: Partial recall";
|
|
break;
|
|
case (GP30ConfigExErrors.DefaultPasswordUsed):
|
|
Message = "COMMAND CHANNEL\t ERROR: Default password used";
|
|
break;
|
|
default:
|
|
Message = $"COMMAND CHANNEL\t ERROR: Unknown error code: 0x{rxStringCommandChannel.ElementAt(GP30BytePosition.ErrCodeSubreason).ToString("X", culture)}";
|
|
break;
|
|
}
|
|
#endregion
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ErrorLog.Log(LogErrReason.Exception(), "GP30.ErrorMessages853() failed", $"0x{ex.HResult.ToString("X", culture)}", String.Empty);
|
|
}
|
|
|
|
return Message;
|
|
}
|
|
}
|
|
|
|
|
|
} |