/// <summary> /// /// </summary> /// <param name="p"></param> /// <returns></returns> public static byte[] CreateReadRealCommand(byte address) { CRC_16 c = new CRC_16(); byte[] bs = new byte[] { address, 0x04, 0x00, 0x00, 0x00, 0x11 }; byte[] crcResult = c.CRC16(bs); byte[] r = new byte[bs.Length + 2]; Array.Copy(bs, r, bs.Length); Array.Copy(crcResult, 0, r, bs.Length, crcResult.Length); return(r); }
/// <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; }
/// <summary> /// /// </summary> /// <param name="p"></param> /// <returns></returns> public static byte[] CreateReadRealCommand(byte address) { CRC_16 c = new CRC_16(); byte[] bs = new byte[] { address, 0x04, 0x00, 0x00, 0x00, 0x11 }; byte[] crcResult = c.CRC16(bs); byte[] r = new byte[bs.Length + 2]; Array.Copy(bs, r, bs.Length); Array.Copy(crcResult, 0, r, bs.Length, crcResult.Length); return r; }