/// <summary> /// /// </summary> /// <param name="deviceInfo"></param> /// <param name="inbyte"></param> /// <param name="li"></param> /// <returns></returns> public static bool Process(DeviceInfo deviceInfo, byte[] inbyte, LogItem li, out GateDriver.Gate_His gateHisortyData) { gateHisortyData = null; // parse xd202 data // string errormsg; object gateHis = Parse(inbyte, out errormsg); // save to db // if (gateHis != null) { DbClass db = new DbClass(); db.Gate_His_Save(ref gateHis); gateHisortyData = (GateDriver.Gate_His)gateHis; return(true); } else { li.Add("Error", errormsg); return(false); } }
public void ParseRealDataTest() { byte[] bs = null; bs = null; object obj = XD202.ParseForTest(bs); Assert.IsNull(obj); bs = new byte[0]; obj = XD202.ParseForTest(bs); Assert.IsNull(obj); bs = new byte[] { 0x01, 0x04, 0x22, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xE6, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA9, 0x64 }; obj = XD202.ParseForTest(bs); Assert.IsNotNull(obj); GateDriver.Gate_His his = (GateDriver.Gate_His)obj; Assert.AreEqual(1, his.ComAdr); Console.WriteLine(his.ToString()); }
/// <summary> /// /// </summary> /// <param name="inbyte"></param> /// <returns></returns> private static GateDriver.Gate_His Parse(byte[] inbyte, out string errorMsg) { errorMsg = string.Empty; // check null // if (inbyte == null) { return(null); } // check length // if (inbyte.Length < 39) { errorMsg = "length < 39, is " + inbyte.Length; return(null); } // check data // if (inbyte[1] == 0x04 && inbyte[2] == 0x22) { int address = inbyte[0]; // check crc // byte[] bscrc = new CRC_16().CRC16(inbyte); if ((bscrc[0] == 00) && (bscrc[1] == 00)) { float IF = Convert.ToInt32( new UInt32ModbusConverter().ConvertToObject( GetPartBytes(inbyte, 3, 4)) ); IF /= 100F; int remainAmount = Convert.ToInt32( new Int32ModbusConverter().ConvertToObject( GetPartBytes(inbyte, 7, 4))); int height = Convert.ToInt32( new Int16ModbusConverter().ConvertToObject( GetPartBytes(inbyte, 11, 2) ) ); int wl2 = Convert.ToInt32( new Int16ModbusConverter().ConvertToObject( GetPartBytes(inbyte, 25, 2) ) ); int wl1 = Convert.ToInt32( new Int16ModbusConverter().ConvertToObject( GetPartBytes(inbyte, 35, 2) ) ); int totalAmount = Math.Abs(remainAmount); GateDriver.Gate_His d = new GateDriver.Gate_His(address, 0, DateTime.Now.ToString(), wl1, wl2, height, IF, remainAmount, totalAmount, "", ""); return(d); } else { // crc error // errorMsg = "crc error"; } } else { errorMsg = "data error"; } return(null); }
/// <summary> /// /// </summary> /// <param name="inbyte"></param> /// <returns></returns> private static GateDriver.Gate_His Parse(byte[] inbyte , out string errorMsg) { errorMsg = string.Empty; // check null // if (inbyte == null) { return null; } // check length // if (inbyte.Length < 39) { errorMsg = "length < 39, is " + inbyte.Length ; return null; } // check data // if (inbyte[1] == 0x04 && inbyte[2] == 0x22) { int address = inbyte[0]; // check crc // byte[] bscrc = new CRC_16().CRC16(inbyte); if ((bscrc[0] == 00) && (bscrc[1] == 00)) { float IF = Convert.ToInt32( new UInt32ModbusConverter().ConvertToObject( GetPartBytes(inbyte, 3, 4)) ); IF /= 100F; int remainAmount = Convert.ToInt32( new Int32ModbusConverter().ConvertToObject( GetPartBytes(inbyte, 7, 4))); int height = Convert.ToInt32( new Int16ModbusConverter().ConvertToObject( GetPartBytes(inbyte, 11, 2) ) ); int wl2 = Convert.ToInt32( new Int16ModbusConverter().ConvertToObject( GetPartBytes(inbyte, 25, 2) ) ); int wl1 = Convert.ToInt32( new Int16ModbusConverter().ConvertToObject( GetPartBytes(inbyte, 35, 2) ) ); int totalAmount = Math.Abs(remainAmount); GateDriver.Gate_His d = new GateDriver.Gate_His(address, 0, DateTime.Now.ToString(), wl1, wl2, height, IF, remainAmount, totalAmount, "", ""); return d; } else { // crc error // errorMsg = "crc error"; } } else { errorMsg = "data error"; } return null; }