public static NormalParamEntity ReadNormal(byte address, CommonConfig config, Action <string> callback) { byte[] sendb = Command.GetReadSendByte(address, 0x00, 0x20, 22); callback(string.Format("W: {0}", CommandUnits.ByteToHexStr(sendb))); byte[] rbytes = PLAASerialPort.Read(sendb); callback(string.Format("R: {0}", CommandUnits.ByteToHexStr(rbytes))); NormalParamEntity normal = new NormalParamEntity(); Array.Reverse(rbytes, 3, 2); normal.GasCount = BitConverter.ToInt16(rbytes, 3); Array.Reverse(rbytes, 5, 2); normal.WeatherCount = BitConverter.ToInt16(rbytes, 5); Array.Reverse(rbytes, 7, 2); normal.HotTimeSpan = BitConverter.ToUInt16(rbytes, 7); Array.Reverse(rbytes, 9, 2); Array.Reverse(rbytes, 11, 2); normal.DataStorageInterval = BitConverter.ToInt32(rbytes, 9); Array.Reverse(rbytes, 13, 2); normal.CurveTimeSpan = BitConverter.ToUInt16(rbytes, 13); normal.IfSoundAlert = BitConverter.ToBoolean(rbytes, 16); Array.Reverse(rbytes, 17, 2); normal.AlertDelay = BitConverter.ToUInt16(rbytes, 17); Array.Reverse(rbytes, 19, 2); normal.RelayModelA1.Value = BitConverter.ToInt16(rbytes, 19); normal.RelayModelA1.Name = config.RelayModelA.FirstOrDefault(c => c.Value == normal.RelayModelA1.Value).Key; Array.Reverse(rbytes, 21, 2); normal.RelayModelA2.Value = BitConverter.ToInt16(rbytes, 21); normal.RelayModelA2.Name = config.RelayModelA.FirstOrDefault(c => c.Value == normal.RelayModelA2.Value).Key; Array.Reverse(rbytes, 23, 2); normal.RelayModel1.Value = BitConverter.ToInt16(rbytes, 23); normal.RelayModel1.Name = config.RelayModel.FirstOrDefault(c => c.Value == normal.RelayModel1.Value).Key; Array.Reverse(rbytes, 25, 2); normal.RelayMatchChannel1 = BitConverter.ToInt16(rbytes, 25); Array.Reverse(rbytes, 27, 2); normal.RelayInterval1 = BitConverter.ToUInt16(rbytes, 27); Array.Reverse(rbytes, 29, 2); normal.RelayActionTimeSpan1 = BitConverter.ToUInt16(rbytes, 29); Array.Reverse(rbytes, 31, 2); normal.RelayModel2.Value = BitConverter.ToInt16(rbytes, 31); normal.RelayModel2.Name = config.RelayModel.FirstOrDefault(c => c.Value == normal.RelayModel2.Value).Key; Array.Reverse(rbytes, 33, 2); normal.RelayMatchChannel2 = BitConverter.ToInt16(rbytes, 33); Array.Reverse(rbytes, 35, 2); normal.RelayInterval2 = BitConverter.ToUInt16(rbytes, 35); Array.Reverse(rbytes, 37, 2); normal.RelayActionTimeSpan2 = BitConverter.ToUInt16(rbytes, 37); Array.Reverse(rbytes, 39, 2); normal.RelayModel3.Value = BitConverter.ToInt16(rbytes, 39); normal.RelayModel3.Name = config.RelayModel.FirstOrDefault(c => c.Value == normal.RelayModel3.Value).Key; Array.Reverse(rbytes, 41, 2); normal.RelayMatchChannel3 = BitConverter.ToInt16(rbytes, 41); Array.Reverse(rbytes, 43, 2); normal.RelayInterval3 = BitConverter.ToUInt16(rbytes, 43); Array.Reverse(rbytes, 45, 2); normal.RelayActionTimeSpan3 = BitConverter.ToUInt16(rbytes, 45); return(normal); }
public static List <WeatherEntity> ReadWeather(byte address, CommonConfig config, Action <string> callback) { byte[] sendb1 = Command.GetReadSendByte(address, 0x00, 0x21, 1); callback(string.Format("W: {0}", CommandUnits.ByteToHexStr(sendb1))); byte[] rbytes1 = PLAASerialPort.Read(sendb1); callback(string.Format("R: {0}", CommandUnits.ByteToHexStr(rbytes1))); byte count = rbytes1[4]; List <WeatherEntity> list = new List <WeatherEntity>(); for (byte i = 0; i < count; i++) { //Thread.Sleep(CommandUnits.CommandDelay); byte high = (byte)(0x10 + i); byte[] sendb = Command.GetReadSendByte(address, high, 0x10, 19); callback(string.Format("W: {0}", CommandUnits.ByteToHexStr(sendb))); byte[] rbytes = PLAASerialPort.Read(sendb); callback(string.Format("R: {0}", CommandUnits.ByteToHexStr(rbytes))); WeatherEntity weather = new WeatherEntity(); weather.WeatherID = i; Array.Reverse(rbytes, 3, 2); weather.WeatherName.Value = BitConverter.ToInt16(rbytes, 3); weather.WeatherName.Name = config.WeatherName.FirstOrDefault(c => c.Value == weather.WeatherName.Value).Key; Array.Reverse(rbytes, 5, 2); weather.WeatherUnit.Value = BitConverter.ToInt16(rbytes, 5); weather.WeatherUnit.Name = config.WeatherUnit.FirstOrDefault(c => c.Value == weather.WeatherUnit.Value).Key; Array.Reverse(rbytes, 7, 2); weather.WeatherPoint.Value = BitConverter.ToInt16(rbytes, 7); weather.WeatherPoint.Name = config.Point.FirstOrDefault(c => c.Value == weather.WeatherPoint.Value).Key; Array.Reverse(rbytes, 9, 2); Array.Reverse(rbytes, 11, 2); weather.Rang = BitConverter.ToSingle(rbytes, 9); List <byte> byteTemp = new List <byte>(); for (int j = 13; j < 13 + 12;) { if (rbytes[j + 1] != 0x00) { byteTemp.Add(rbytes[j + 1]); } j += 2; } weather.WeatherFactor = ASCIIEncoding.ASCII.GetString(byteTemp.ToArray()); Array.Reverse(rbytes, 25, 2); Array.Reverse(rbytes, 27, 2); weather.WeatherCompensation = BitConverter.ToSingle(rbytes, 25); Array.Reverse(rbytes, 29, 2); Array.Reverse(rbytes, 31, 2); weather.CurrentWeather = BitConverter.ToSingle(rbytes, 29); weather.WeatherAlertStatus.Value = rbytes[34]; weather.WeatherAlertStatus.Name = config.AlertStatus.FirstOrDefault(c => c.Value == rbytes[34]).Key; list.Add(weather); } return(list); }
public static DateTime ReadOutDate(byte address, Action <string> callBack) { byte[] sendb = Command.GetReadSendByte(address, 0x00, 0x96, 3); callBack(string.Format("W: {0}", CommandUnits.ByteToHexStr(sendb))); byte[] rbytes = PLAASerialPort.Read(sendb); callBack(string.Format("R: {0}", CommandUnits.ByteToHexStr(rbytes))); DateTime dt = new DateTime(2000 + rbytes[4], rbytes[6], rbytes[8]); return(dt); }
public static List <GasEntity> ReadGasList(byte address, CommonConfig config, Action <string> callback) { List <GasEntity> list = new List <GasEntity>(); byte[] sendb1 = Command.GetReadSendByte(address, 0x00, 0x20, 1); callback(string.Format("W: {0}", CommandUnits.ByteToHexStr(sendb1))); byte[] rbytes1 = PLAASerialPort.Read(sendb1); callback(string.Format("R: {0}", CommandUnits.ByteToHexStr(rbytes1))); byte count = rbytes1[4]; for (byte i = 1; i <= count; i++) { list.Add(ReadGas(i, address, config, callback)); } return(list); }
public static GasEntity ReadCurrent(int gasId, byte address, CommonConfig config, Action <string> callback) { byte[] sendb = Command.GetReadSendByte(address, (byte)gasId, 0x50, 5); callback(string.Format("W: {0}", CommandUnits.ByteToHexStr(sendb))); byte[] rbytes = PLAASerialPort.Read(sendb); callback(string.Format("R: {0}", CommandUnits.ByteToHexStr(rbytes))); Array.Reverse(rbytes, 3, 2); Array.Reverse(rbytes, 5, 2); Array.Reverse(rbytes, 7, 2); Array.Reverse(rbytes, 9, 2); GasEntity gas = new GasEntity(); gas.CurrentAD = BitConverter.ToInt32(rbytes, 3); gas.CurrentChroma = BitConverter.ToSingle(rbytes, 7); if (config != null) { gas.AlertStatus.Value = rbytes[12]; gas.AlertStatus.Name = config.AlertStatus.FirstOrDefault(c => c.Value == gas.AlertStatus.Value).Key; } return(gas); }
public static GasEntity ReadChromaAndAD(int gasId, EnumChromaLevel level, byte address, Action <string> callback) { byte low = 0x2a; switch (level) { case EnumChromaLevel.Zero: low = 0x2a; break; case EnumChromaLevel.One: low = 0x2e; break; case EnumChromaLevel.Two: low = 0x32; break; case EnumChromaLevel.Three: low = 0x36; break; default: break; } byte[] sendb = Command.GetReadSendByte(address, (byte)gasId, low, 4); callback(string.Format("W: {0}", CommandUnits.ByteToHexStr(sendb))); byte[] rbytes = PLAASerialPort.Read(sendb); callback(string.Format("R: {0}", CommandUnits.ByteToHexStr(rbytes))); Array.Reverse(rbytes, 3, 2); Array.Reverse(rbytes, 5, 2); Array.Reverse(rbytes, 7, 2); Array.Reverse(rbytes, 9, 2); GasEntity gas = new GasEntity(); switch (level) { case EnumChromaLevel.Zero: gas.ZeroAD = BitConverter.ToInt32(rbytes, 3); gas.ZeroChroma = BitConverter.ToSingle(rbytes, 7); break; case EnumChromaLevel.One: gas.OneAD = BitConverter.ToInt32(rbytes, 3); gas.OneChroma = BitConverter.ToSingle(rbytes, 7); break; case EnumChromaLevel.Two: gas.TwoAD = BitConverter.ToInt32(rbytes, 3); gas.TwoChroma = BitConverter.ToSingle(rbytes, 7); break; case EnumChromaLevel.Three: gas.ThreeAD = BitConverter.ToInt32(rbytes, 3); gas.ThreeChroma = BitConverter.ToSingle(rbytes, 7); break; default: break; } return(gas); }
public static GasEntity ReadGas(int gasId, byte address, CommonConfig config, Action <string> callback) { byte[] sendb = Command.GetReadSendByte(address, (byte)gasId, 0x10, 42); callback(string.Format("W: {0}", CommandUnits.ByteToHexStr(sendb))); byte[] rbytes = PLAASerialPort.Read(sendb); callback(string.Format("R: {0}", CommandUnits.ByteToHexStr(rbytes))); GasEntity gas = new GasEntity(); gas.GasID = gasId; Array.Reverse(rbytes, 3, 2); gas.GasName.Value = BitConverter.ToInt16(rbytes, 3); gas.GasName.Name = config.GasName.FirstOrDefault(c => c.Value == gas.GasName.Value).Key; Array.Reverse(rbytes, 5, 2); gas.GasUnit.Value = BitConverter.ToInt16(rbytes, 5); gas.GasUnit.Name = config.GasUnit.FirstOrDefault(c => c.Value == gas.GasUnit.Value).Key; Array.Reverse(rbytes, 7, 2); gas.GasPoint.Value = BitConverter.ToInt16(rbytes, 7); gas.GasPoint.Name = config.Point.FirstOrDefault(c => c.Value == gas.GasPoint.Value).Key; Array.Reverse(rbytes, 9, 2); Array.Reverse(rbytes, 11, 2); gas.GasRang = BitConverter.ToSingle(rbytes, 9); List <byte> byteTemp = new List <byte>(); for (int i = 13; i < 13 + 12;) { if (rbytes[i + 1] != 0x00) { byteTemp.Add(rbytes[i + 1]); } i += 2; } // to do test gas.Factor = ASCIIEncoding.ASCII.GetString(byteTemp.ToArray()); gas.IfGasAlarm = BitConverter.ToBoolean(rbytes, 26); Array.Reverse(rbytes, 27, 2); gas.AlertModel.Value = BitConverter.ToInt16(rbytes, 27); gas.AlertModel.Name = config.AlertModel.FirstOrDefault(c => c.Value == gas.AlertModel.Value).Key; Array.Reverse(rbytes, 29, 2); Array.Reverse(rbytes, 31, 2); gas.GasA1 = BitConverter.ToSingle(rbytes, 29); Array.Reverse(rbytes, 33, 2); Array.Reverse(rbytes, 35, 2); gas.GasA2 = BitConverter.ToSingle(rbytes, 33); Array.Reverse(rbytes, 45, 2); Array.Reverse(rbytes, 47, 2); gas.Compensation = BitConverter.ToSingle(rbytes, 45); Array.Reverse(rbytes, 49, 2); Array.Reverse(rbytes, 51, 2); gas.Show = BitConverter.ToSingle(rbytes, 49); gas.CheckNum = (byte)(rbytes[54] < 2 ? 2 : (rbytes[54] > 4 ? 4 : rbytes[54])); gas.IfTwo = gas.CheckNum >= 3; gas.IfThree = gas.CheckNum >= 4; Array.Reverse(rbytes, 55, 2); Array.Reverse(rbytes, 57, 2); gas.ZeroAD = BitConverter.ToInt32(rbytes, 55); Array.Reverse(rbytes, 59, 2); Array.Reverse(rbytes, 61, 2); gas.ZeroChroma = BitConverter.ToSingle(rbytes, 59); Array.Reverse(rbytes, 63, 2); Array.Reverse(rbytes, 65, 2); gas.OneAD = BitConverter.ToInt32(rbytes, 63); Array.Reverse(rbytes, 67, 2); Array.Reverse(rbytes, 69, 2); gas.OneChroma = BitConverter.ToSingle(rbytes, 67); Array.Reverse(rbytes, 71, 2); Array.Reverse(rbytes, 73, 2); gas.TwoAD = BitConverter.ToInt32(rbytes, 71); Array.Reverse(rbytes, 75, 2); Array.Reverse(rbytes, 77, 2); gas.TwoChroma = BitConverter.ToSingle(rbytes, 75); Array.Reverse(rbytes, 79, 2); Array.Reverse(rbytes, 81, 2); gas.ThreeAD = BitConverter.ToInt32(rbytes, 79); Array.Reverse(rbytes, 83, 2); Array.Reverse(rbytes, 85, 2); gas.ThreeChroma = BitConverter.ToSingle(rbytes, 83); GasEntity current = ReadCurrent(gasId, address, config, callback); gas.CurrentAD = current.CurrentAD; gas.CurrentChroma = current.CurrentChroma; gas.AlertStatus = current.AlertStatus; return(gas); }
public static SerialEntity ReadSerialParam(byte address, CommonConfig config, Action <string> callback) { byte[] sendb = Command.GetReadSendByte(address, 0x00, 0x36, 82); callback(string.Format("T: {0}", CommandUnits.ByteToHexStr(sendb))); byte[] rbytes = PLAASerialPort.Read(sendb); callback(string.Format("R: {0}", CommandUnits.ByteToHexStr(rbytes))); SerialEntity serial = new SerialEntity(); Array.Reverse(rbytes, 3, 2); serial.SerialOneBaudRate.Value = BitConverter.ToInt16(rbytes, 3); serial.SerialOneBaudRate.Name = config.BaudRate.FirstOrDefault(c => c.Value == serial.SerialOneBaudRate.Value).Key; Array.Reverse(rbytes, 5, 2); serial.SerialOnePortModel.Value = BitConverter.ToInt16(rbytes, 5); serial.SerialOnePortModel.Name = config.SerialPortModel.FirstOrDefault(c => c.Value == serial.SerialOnePortModel.Value).Key; Array.Reverse(rbytes, 7, 2); serial.SerialOneAddress = BitConverter.ToInt16(rbytes, 7); Array.Reverse(rbytes, 9, 2); Array.Reverse(rbytes, 11, 2); serial.SerialOneInterval = BitConverter.ToInt32(rbytes, 9); List <byte> byteTemp = new List <byte>(); for (int i = 13; i < 13 + 48;) { if (rbytes[i + 1] != 0x00) { byteTemp.Add(rbytes[i + 1]); } i += 2; } serial.SerialOneMN = ASCIIEncoding.ASCII.GetString(byteTemp.ToArray()); byteTemp = new List <byte>(); for (int i = 61; i < 61 + 4;) { if (rbytes[i + 1] != 0x00) { byteTemp.Add(rbytes[i + 1]); } i += 2; } serial.SerialOneST = ASCIIEncoding.ASCII.GetString(byteTemp.ToArray()); byteTemp = new List <byte>(); for (int i = 65; i < 65 + 8;) { if (rbytes[i + 1] != 0x00) { byteTemp.Add(rbytes[i + 1]); } i += 2; } serial.SerialOneCN = ASCIIEncoding.ASCII.GetString(byteTemp.ToArray()); byteTemp = new List <byte>(); for (int i = 73; i < 73 + 12;) { if (rbytes[i + 1] != 0x00) { byteTemp.Add(rbytes[i + 1]); } i += 2; } serial.SerialOnePW = ASCIIEncoding.ASCII.GetString(byteTemp.ToArray()); Array.Reverse(rbytes, 85, 2); serial.SerialTwoBaudRate.Value = BitConverter.ToInt16(rbytes, 85); serial.SerialTwoBaudRate.Name = config.BaudRate.FirstOrDefault(c => c.Value == serial.SerialTwoBaudRate.Value).Key; Array.Reverse(rbytes, 87, 2); serial.SerialTwoPortModel.Value = BitConverter.ToInt16(rbytes, 87); serial.SerialTwoPortModel.Name = config.SerialPortModel.FirstOrDefault(c => c.Value == serial.SerialTwoPortModel.Value).Key; Array.Reverse(rbytes, 89, 2); serial.SerialTwoAddress = BitConverter.ToInt16(rbytes, 89); Array.Reverse(rbytes, 91, 2); Array.Reverse(rbytes, 93, 2); serial.SerialTwoInterval = BitConverter.ToInt32(rbytes, 91); byteTemp = new List <byte>(); for (int i = 95; i < 95 + 48;) { if (rbytes[i + 1] != 0x00) { byteTemp.Add(rbytes[i + 1]); } i += 2; } serial.SerialTwoMN = ASCIIEncoding.ASCII.GetString(byteTemp.ToArray()); byteTemp = new List <byte>(); for (int i = 143; i < 143 + 4;) { if (rbytes[i + 1] != 0x00) { byteTemp.Add(rbytes[i + 1]); } i += 2; } serial.SerialTwoST = ASCIIEncoding.ASCII.GetString(byteTemp.ToArray()); byteTemp = new List <byte>(); for (int i = 147; i < 147 + 8;) { if (rbytes[i + 1] != 0x00) { byteTemp.Add(rbytes[i + 1]); } i += 2; } serial.SerialTwoCN = ASCIIEncoding.ASCII.GetString(byteTemp.ToArray()); byteTemp = new List <byte>(); for (int i = 155; i < 155 + 12;) { if (rbytes[i + 1] != 0x00) { byteTemp.Add(rbytes[i + 1]); } i += 2; } serial.SerialTwoPW = ASCIIEncoding.ASCII.GetString(byteTemp.ToArray()); return(serial); }