/** ****************************************************************************** * @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__ */