public static Boolean IsLength(byte[] buffer) { string msg = ByteStrUtil.ByteToKHex(buffer); msg = msg.Replace("7D 82", "7D"); byte[] data = ByteStrUtil.HexToByte(msg); int var1 = data[2]; int index = var1 + 3; int var2 = data[index]; index = var1 + var2 + 6; int var3 = (int)(((data[index] & 0xFF) << 8) | (data[index + 1] & 0xFF)); int length = var1 + var2 + var3 + 12; return(length == data.Length); }
/// <summary> /// 编码 /// </summary> /// <param name="command">命令数据</param> /// <param name="isForward">是否转发</param> public static byte[] Encoder(Command command, bool isForward) { string data = command.Pack(); StringBuilder encoderData = new StringBuilder(); encoderData.Append(head); string address = "01 12 01 F2"; if (isForward) { address = "02 10 12 01 F2"; } data = address + data; data += Crc(data); data = Repeat(data); encoderData.Append(data); encoderData.Append(end); return(ByteStrUtil.HexToByte(encoderData.ToString())); }