@@ -29,27 +29,184 @@ extern "C" {
29
29
class ModbusClient {
30
30
31
31
public:
32
+ /* *
33
+ * Set the (slave) id to use for read and write operations.
34
+ * Defaults to 0x00 (broadcast).
35
+ *
36
+ * @param id id to use
37
+ */
32
38
void setId (int id);
33
39
40
+ /* *
41
+ * Perform a "Read Coils" operation for the specified address for a single
42
+ * coil.
43
+ *
44
+ * @param address address to use for operation
45
+ *
46
+ * @return coil value on success, -1 on failure.
47
+ */
34
48
int readCoil (int address);
49
+
50
+ /* *
51
+ * Perform a "Read Coils" operation for the specified address and number of
52
+ * coils.
53
+ *
54
+ * @param address start address to use for operation
55
+ * @param values array of bytes to store coil values
56
+ * @param nb number of coils to read
57
+ *
58
+ * @return 1 success, 0 on failure.
59
+ */
35
60
int readCoils (int address, uint8_t values[], int nb);
61
+
62
+ /* *
63
+ * Perform a "Read Discrete Inputs" operation for the specified address for a
64
+ * single discrete input.
65
+ *
66
+ * @param address address to use for operation
67
+ *
68
+ * @return discrete input value on success, -1 on failure.
69
+ */
36
70
int readDiscreteInput (int address);
71
+
72
+ /* *
73
+ * Perform a "Read Discrete Inputs" operation for the specified address and
74
+ * number of inputs.
75
+ *
76
+ * @param address start address to use for operation
77
+ * @param values array of bytes to store discrete input values
78
+ * @param nb number of discrete inputs to read
79
+ *
80
+ * @return 1 success, 0 on failure.
81
+ */
37
82
int readDiscreteInputs (int address, uint8_t values[], int nb);
83
+
84
+ /* *
85
+ * Perform a "Read Holding Registers" operation for a single holding
86
+ * register.
87
+ *
88
+ * @param address start address to use for operation
89
+ *
90
+ * @return holiding register value on success, -1 on failure.
91
+ */
38
92
long readHoldingRegister (int address);
93
+
94
+ /* *
95
+ * Perform a "Read Holding Registers" operation for the specified address and
96
+ * number of holding registers.
97
+ *
98
+ * @param address start address to use for operation
99
+ * @param values array of words to store holding register values
100
+ * @param nb number of holding registers to read
101
+ *
102
+ * @return 1 success, 0 on failure.
103
+ */
39
104
int readHoldingRegisters (int address, uint16_t values[], int nb);
105
+
106
+ /* *
107
+ * Perform a "Read Input Registers" operation for a single input
108
+ * register.
109
+ *
110
+ * @param address address to use for operation
111
+ *
112
+ * @return input register value on success, -1 on failure.
113
+ */
40
114
long readInputRegister (int address);
115
+
116
+ /* *
117
+ * Perform a "Read Input Registers" operation for the specified address and
118
+ * number of input registers.
119
+ *
120
+ * @param address start address to use for operation
121
+ * @param values array of words to store input register values
122
+ * @param nb number of holding input to read
123
+ *
124
+ * @return 1 success, 0 on failure.
125
+ */
41
126
int readInputRegisters (int address, uint16_t values[], int nb);
42
127
128
+ /* *
129
+ * Perform a "Write Single Coil" operation for the specified address and
130
+ * value.
131
+ *
132
+ * @param address address to use for operation
133
+ * @param value coil value to write
134
+ *
135
+ * @return 1 on success, 0 on failure.
136
+ */
43
137
int writeCoil (int address, uint8_t value);
138
+
139
+ /* *
140
+ * Perform a "Write Multiple Coils" operation for the specified address and
141
+ * values.
142
+ *
143
+ * @param address start address to use for operation
144
+ * @param values array of coil values to write
145
+ * @param nb number of coil values to write
146
+ *
147
+ * @return 1 on success, 0 on failure.
148
+ */
44
149
int writeCoils (int address, const uint8_t values[], int nb);
45
- int writeRegister (int address, uint16_t value);
46
- int writeRegisters (int address, const uint16_t values[], int nb);
150
+
151
+ /* *
152
+ * Perform a "Write Single Holding Register" operation for the specified
153
+ * address and value.
154
+ *
155
+ * @param address address to use for operation
156
+ * @param value holding register value to write
157
+ *
158
+ * @return 1 on success, 0 on failure.
159
+ */
160
+ int writeHoldingRegister (int address, uint16_t value);
161
+
162
+ /* *
163
+ * Perform a "Write Multiple Holding Registers" operation for the specified
164
+ * address and values.
165
+ *
166
+ * @param address start address to use for operation
167
+ * @param values array of holding register values to write
168
+ * @param nb number of holding register values to write
169
+ *
170
+ * @return 1 on success, 0 on failure.
171
+ */
172
+ int writeHoldingRegisters (int address, const uint16_t values[], int nb);
173
+
174
+ /* *
175
+ * Perform a "Mask Write Registers" operation for the specified
176
+ * address, AND mask and OR mask.
177
+ *
178
+ * @param address address to use for operation
179
+ * @param andMask AND mask to use for operation
180
+ * @param orMask OR mask to use for operation
181
+ *
182
+ * @return 1 on success, 0 on failure.
183
+ */
47
184
int maskWriteRegister (int address, uint16_t andMask, uint16_t orMask);
48
185
186
+ /* *
187
+ * Perform a "Read/Write Registers" operation.
188
+ *
189
+ * @param writeAddress write address to use for operation
190
+ * @param writeValues array of words to write
191
+ * @param writeNb number of registers to write
192
+ * @param readAddress read address to use for operation
193
+ * @param readValues array of words to store register values
194
+ * @param readNb number of registers to read
195
+ *
196
+ * @return 1 on success, 0 on failure.
197
+ */
49
198
int writeAndReadRegisters (int writeAddress, const uint16_t writeValues[], int writeNb, int readAddress, uint16_t readValues[], int readNb);
50
199
200
+ /* *
201
+ * Read the last error reason as a string
202
+ *
203
+ * @return Last error reason as a C string
204
+ */
51
205
const char * lastError ();
52
206
207
+ /* *
208
+ * Stop the client and clean up
209
+ */
53
210
void end ();
54
211
55
212
protected:
0 commit comments