/** ****************************************************************************** * @file : ModbusRTU.h * @brief : Header for ModbusRTU.c file. * This file contains the common defines of the ModbusRTU protocol. ****************************************************************************** */ #ifndef __MODBUSRTU_H__ #define __MODBUSRTU_H__ typedef unsigned char uchar; typedef unsigned short ushort; typedef unsigned char uint8_t; typedef unsigned short uint16_t; typedef int int32_t; /* enum enResult { S_OK = 0, S_ERR = 1, }; */ enum enModbusRTUCmd { None =0, ReadCoils =1, //读线圈 ReadInputs =2, //读离散量输入 ReadKeepRegs =3, //读保持寄存器 ReadInputRegs =4, //读输入寄存器 WriteCoil = 5, //写单个线圈 WriteReg =6, //写单个寄存器 ReadExptStat = 7, //读取异常状态 FetchCommEventCtr =11, //Fetch Comm Event Ctr // 12 Fetch Comm Event Log WriteCoils =15, //写多个线圈 WriteRegs = 16, //写多个寄存器 //17 Report Slave ID //20 Read General Reference //21 Write General Reference //22 Mask Write 4X Register // 23 Read/Write 4X Registers //24 Read FIFO Queue }; #pragma anon_unions typedef struct tagModBusRTUReqPkg { uchar Dst; uchar Cmd; union { ushort Addr; struct { uchar AddrH; uchar AddrL; }; }; union { ushort nCount; struct { uchar CountH; uchar CountL; }; }; }stModBusRTUReqPkg, *pModBusRTUReqPkg; typedef struct tagModBusRTUReplyPkg { uchar Dst; uchar Cmd; uchar nByteCount; uchar Datas[1]; }stModBusRTUReplyPkg, *pModBusRTUReplyPkg; //int ModBusCRC16(void * pBuf, int len1); uint16_t crc16tablefast(const uint8_t *ptr, uint16_t len); int ModBusSlaveCheckPkg(int nChn, void * pPkg, uint16_t len1); int ModBusSlaveParsePkg(int nChn, void * pPkg, uint16_t len1); #endif /* __MODBUSRTU_H__ */