-
Notifications
You must be signed in to change notification settings - Fork 5
/
modbus-types.h
147 lines (137 loc) · 3.24 KB
/
modbus-types.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
//-----------------------------------------------------------------------------
//
//
//
//
//
//-----------------------------------------------------------------------------
#ifndef MODBUS_TYPES_H
#define MODBUS_TYPES_H
/*
* \enum
* \brief Modbus functions
*/
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
enum MB_FUNC
{
MB_FUNC_NONE = 0x00,
MB_FUNC_READ_COILS = 0x01,
MB_FUNC_READ_DISCRETE_INPUT = 0x02,
MB_FUNC_READ_HOLDING_REGISTERS = 0x03,
MB_FUNC_READ_INPUT_REGISTERS = 0x04,
MB_FUNC_WRITE_COIL = 0x05,
MB_FUNC_WRITE_HOLDING_REGISTER = 0x06,
MB_FUNC_WRITE_MULTIPLE_COILS = 0x0F,
MB_FUNC_WRITE_MULTIPLE_REGISTERS = 0x10
};
/*
* \enum
* \brief Multiplies for timing calculation
*/
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
enum MB_TIMINGS_MULTIPLIES
{
QUIET_TIME_MULTIPLE = 28000000 ///< 8 bits * 1000000 us * 3.5
};
/*
* \enum
* \brief Hardware serial ports ID
*/
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
enum SERIAL_PORT
{
SERIAL_0 = 0x00,
SERIAL_1 = 0x01,
SERIAL_2 = 0x02,
SERIAL_3 = 0x03
};
/*
* \enum
* \brief Pins reserved in Arduino
*/
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
enum RESERVED_PINS
{
RX_PIN = 0, ///< Rx pin
TX_PIN = 1 ///< Tx pin
};
/*
* \enum
* \brief Maximal data buffer size
*/
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
enum
{
MAX_BUFFER_SIZE = 64
};
/*
* \enum
* \brief Modbus errors
*/
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
enum MB_ERROR
{
ERROR_NOT_MASTER = -1,
ERROR_POLLING = -2,
ERROR_BUFF_OVERFLOW = -3,
ERROR_BAD_CRC = -4,
ERR_EXCEPTION = -5
};
/*
* \enum
* \brief Massage parts position in data buffer
*/
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
enum MB_MESSAGE_POS
{
ID = 0,
FUNC_CODE,
ADDRESS_HI,
ADDRESS_LO,
NB_HI,
NB_LO,
BYTE_COUNT
};
/*
* \enum
* \brief Exceptions codes
*/
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
enum
{
NO_REPLY = 255,
EXC_FUNC_CODE = 1,
EXC_ADDR_RANGE = 2,
EXC_REGS_QUANT = 3,
EXC_EXECUTE = 4
};
/*
* \enum
* \brief Sizes of some messages data
*/
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
enum
{
RESPOSE_SIZE = 6,
EXCEPTION_SIZE = 3,
CHECKSUMM_SIZE = 2
};
#endif