提交 | 用户 | age
|
483170
|
1 |
/** |
Q |
2 |
****************************************************************************** |
|
3 |
* @file : ModbusRTU.h |
|
4 |
* @brief : Header for ModbusRTU.c file. |
|
5 |
* This file contains the common defines of the ModbusRTU protocol. |
|
6 |
****************************************************************************** |
|
7 |
*/ |
|
8 |
#ifndef __MODBUSRTU_H__ |
|
9 |
#define __MODBUSRTU_H__ |
|
10 |
|
|
11 |
typedef unsigned char uchar; |
|
12 |
typedef unsigned short ushort; |
|
13 |
typedef unsigned char uint8_t; |
|
14 |
typedef unsigned short uint16_t; |
|
15 |
typedef int int32_t; |
|
16 |
|
|
17 |
/* |
|
18 |
enum enResult |
|
19 |
{ |
|
20 |
S_OK = 0, |
|
21 |
S_ERR = 1, |
|
22 |
}; |
|
23 |
*/ |
|
24 |
enum enModbusRTUCmd |
|
25 |
{ |
|
26 |
None =0, |
|
27 |
ReadCoils =1, //读线圈 |
|
28 |
ReadInputs =2, //读离散量输入 |
|
29 |
ReadKeepRegs =3, //读保持寄存器 |
|
30 |
ReadInputRegs =4, //读输入寄存器 |
|
31 |
WriteCoil = 5, //写单个线圈 |
|
32 |
WriteReg =6, //写单个寄存器 |
|
33 |
ReadExptStat = 7, //读取异常状态 |
|
34 |
FetchCommEventCtr =11, //Fetch Comm Event Ctr |
|
35 |
// 12 Fetch Comm Event Log |
|
36 |
|
|
37 |
WriteCoils =15, //写多个线圈 |
|
38 |
WriteRegs = 16, //写多个寄存器 |
|
39 |
//17 Report Slave ID |
|
40 |
//20 Read General Reference |
|
41 |
//21 Write General Reference |
|
42 |
//22 Mask Write 4X Register |
|
43 |
// 23 Read/Write 4X Registers |
|
44 |
//24 Read FIFO Queue |
|
45 |
|
|
46 |
}; |
|
47 |
#pragma anon_unions |
|
48 |
typedef struct tagModBusRTUReqPkg |
|
49 |
{ |
|
50 |
uchar Dst; |
|
51 |
uchar Cmd; |
|
52 |
union { |
|
53 |
ushort Addr; |
|
54 |
struct { |
|
55 |
uchar AddrH; |
|
56 |
uchar AddrL; |
|
57 |
}; |
|
58 |
}; |
|
59 |
union |
|
60 |
{ |
|
61 |
ushort nCount; |
|
62 |
struct |
|
63 |
{ |
|
64 |
uchar CountH; |
|
65 |
uchar CountL; |
|
66 |
}; |
|
67 |
}; |
|
68 |
}stModBusRTUReqPkg, *pModBusRTUReqPkg; |
|
69 |
|
|
70 |
typedef struct tagModBusRTUReplyPkg |
|
71 |
{ |
|
72 |
uchar Dst; |
|
73 |
uchar Cmd; |
|
74 |
uchar nByteCount; |
|
75 |
uchar Datas[1]; |
|
76 |
}stModBusRTUReplyPkg, *pModBusRTUReplyPkg; |
|
77 |
|
|
78 |
//int ModBusCRC16(void * pBuf, int len1); |
|
79 |
uint16_t crc16tablefast(const uint8_t *ptr, uint16_t len); |
|
80 |
|
|
81 |
int ModBusSlaveCheckPkg(int nChn, void * pPkg, uint16_t len1); |
|
82 |
|
|
83 |
int ModBusSlaveParsePkg(int nChn, void * pPkg, uint16_t len1); |
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
#endif /* __MODBUSRTU_H__ */ |