/// <summary> /// 创建包-ping指令 /// </summary> /// <param name="bArrTargetAddress">目的地址5个字节</param> /// <returns></returns> private static byte[] BuildBag_Ping(DeviceAddress objDeviceAddress) { if (objDeviceAddress == null || string.IsNullOrEmpty(objDeviceAddress.DeviceNo)) { return(new byte[0]); } byte[] arrRtn = new byte[18]; int iIndex = 0; //帧起始符 高位 arrRtn[iIndex++] = 0x55; //帧起始符 低位 arrRtn[iIndex++] = 0xFF; //数据长度 高位 arrRtn[iIndex++] = 0x00; //数据长度 低位 arrRtn[iIndex++] = 0x0D; //命令字 arrRtn[iIndex++] = 0x92; //目的地址 5字节 arrRtn[iIndex++] = GetDeviceTypeByte(objDeviceAddress.DeviceType); byte[] bArrDeviceNo = ScaleConverter.HexStr2ByteArr(objDeviceAddress.DeviceNo); for (int i = 0; i < 4; i++) { arrRtn[iIndex++] = bArrDeviceNo[i]; } //源地址 5字节 arrRtn[iIndex++] = 0x01; arrRtn[iIndex++] = 0x00; arrRtn[iIndex++] = 0x00; arrRtn[iIndex++] = 0x00; arrRtn[iIndex++] = 0x00; //序号 2字节 BCD码:0~9999(每次序号不一样) byte[] bArrPingNum = ScaleConverter.Int2ByteArr(objDeviceAddress.PingNum); arrRtn[iIndex++] = bArrPingNum[1]; arrRtn[iIndex++] = bArrPingNum[0]; //CRC8校验 arrRtn[iIndex++] = CRC8A.GetCRC8(arrRtn, 0, arrRtn.Length - 1); return(arrRtn); }