public readonly int currentAngle; //当前姿态角度 /// <summary> /// 叉车详细状态 /// </summary> /// <param name="state">状态:1前往取货点,2取货点取货,3前往送货点,4送货点,5:任务完成,6:空闲,7:故障,8:充电中,9:手动</param> /// <param name="currentNodeNum">当前节点号</param> /// <param name="currentPathNum">当前地图号</param> /// <param name="electricityValue">电量值</param> /// <param name="faultCode">故障代码</param> /// <param name="pos_ux">坐标X,单位mm</param> /// <param name="pos_uy">坐标Y,单位mm</param> /// <param name="pos_uth"></param> /// <param name="currentAngle">当前姿态角度</param> public ForkLiftStatus(ForkliftStatusEnum state, uint currentNodeNum, ushort currentPathNum, ushort electricityValue, uint faultCode, int pos_ux, int pos_uy, int currentAngle) { this.state = state; this.currentNodeNum = currentNodeNum; this.currentPathNum = currentPathNum; this.electricityValue = electricityValue; this.faultCode = faultCode; this.pos_ux = pos_ux; this.pos_uy = pos_uy; this.currentAngle = currentAngle; }
/// <summary> /// 解析叉车状态 /// </summary> /// <param name="status"></param> /// <returns></returns> public ForkliftStatusEnum GetForkliftStatus(byte status) { try { ForkliftStatusEnum forkliftStatusEnum = (ForkliftStatusEnum)status; return(forkliftStatusEnum); } catch { return(ForkliftStatusEnum.Malfunction); } }
static string GenerateStatus(byte id, ForkliftStatusEnum forkliftStatusEnum, uint currentNode, uint currentMap, ushort battery, uint X, uint Y, uint angle) { byte[] sendMsg = new byte[35]; sendMsg[0] = 0x47; sendMsg[1] = 0x53; sendMsg[2] = 0x00; sendMsg[3] = 0x00; sendMsg[4] = id; sendMsg[5] = 0x53; sendMsg[6] = 0x46; sendMsg[7] = 0x01; sendMsg[8] = (byte)forkliftStatusEnum; sendMsg[9] = (byte)(currentNode & 0xFF); sendMsg[10] = (byte)(currentNode >> 8 & 0xFF); sendMsg[11] = (byte)(currentNode >> 16 & 0xFF); sendMsg[12] = (byte)(currentNode >> 24 & 0xFF); sendMsg[13] = (byte)(currentMap & 0xFF); sendMsg[14] = (byte)(currentMap >> 8 & 0xFF); sendMsg[15] = (byte)(battery & 0xFF); sendMsg[16] = (byte)(battery >> 8 & 0xFF); sendMsg[17] = 0x00; sendMsg[18] = 0x00; sendMsg[19] = 0x00; sendMsg[20] = 0x00; sendMsg[21] = (byte)(X & 0xFF); sendMsg[22] = (byte)(X >> 8 & 0xFF); sendMsg[23] = (byte)(X >> 16 & 0xFF); sendMsg[24] = (byte)(X >> 24 & 0xFF); sendMsg[25] = (byte)(Y & 0xFF); sendMsg[26] = (byte)(Y >> 8 & 0xFF); sendMsg[27] = (byte)(Y >> 16 & 0xFF); sendMsg[28] = (byte)(Y >> 24 & 0xFF); sendMsg[29] = (byte)(angle & 0xFF); sendMsg[30] = (byte)(angle >> 8 & 0xFF); sendMsg[31] = (byte)(angle >> 16 & 0xFF); sendMsg[32] = (byte)(angle >> 24 & 0xFF); ushort crcTmp = CRC16(sendMsg, 35); //CRC16校验 sendMsg[33] = (byte)(crcTmp & 0xFF); sendMsg[34] = (byte)(crcTmp >> 8 & 0xFF); StringBuilder stringBuilder = new StringBuilder(); foreach (var item in sendMsg) { stringBuilder.AppendFormat("{0:x2}", item); } return(stringBuilder.ToString()); }