31
31
using callback_f = void (*)(bool , bool );
32
32
class ModbusT1SClientClass : public ModbusClient {
33
33
public:
34
+ /* *
35
+ * Default constructor for ModbusT1SClientClass.
36
+ *
37
+ * Initializes the Modbus client with a default timeout of 1000 milliseconds.
38
+ */
34
39
ModbusT1SClientClass ();
40
+
41
+ /* *
42
+ * Constructor for ModbusT1SClientClass with RS485 support.
43
+ *
44
+ * Initializes the Modbus client with a default timeout of 1000 milliseconds and sets up RS485 communication.
45
+ *
46
+ * @param rs485 Reference to an RS485Class object for RS485 communication.
47
+ */
35
48
ModbusT1SClientClass (RS485Class& rs485);
49
+
50
+ /* *
51
+ * Destructor for ModbusT1SClientClass.
52
+ */
36
53
virtual ~ModbusT1SClientClass ();
37
54
38
55
/* *
@@ -44,205 +61,259 @@ class ModbusT1SClientClass : public ModbusClient {
44
61
* Return 1 on success, 0 on failure
45
62
*/
46
63
int begin (int node_id);
47
- /* *
48
- * Sets the IP address of the Modbus server.
49
- *
50
- * This function sets the IP address of the Modbus server that the client will communicate with.
51
- *
52
- * @param server_ip The IP address of the Modbus server. Default is IPAddress(0, 0, 0, 0).
53
- */
54
- void setServerIp (IPAddress server_ip = IPAddress(0 , 0 , 0 , 0 ));
55
-
56
- /* *
57
- * Sets the port number of the Modbus server.
58
- *
59
- * This function sets the port number of the Modbus server that the client will communicate with.
60
- *
61
- * @param server_port The port number of the Modbus server. Default is 8889.
62
- */
63
- void setServerPort (uint16_t server_port = 8889 );
64
-
65
- /* *
66
- * Sets the Modbus ID of the client.
67
- *
68
- * This function sets the Modbus ID that the client will use for communication.
69
- *
70
- * @param id The Modbus ID.
71
- */
72
- void setModbusId (uint16_t id);
73
-
74
- /* *
75
- * Reads the status of a coil from the Modbus server.
76
- *
77
- * This function sends a request to read the status of a coil at the specified address
78
- * from the Modbus server using the provided UDP client and port.
79
- *
80
- * @param address The address of the coil to read.
81
- * @param client A pointer to the Arduino_10BASE_T1S_UDP client used for communication. Default is nullptr.
82
- * @param port The port number of the Modbus server. Default is 0.
83
- * @return int The status of the coil (1 for ON, 0 for OFF) or -1 if an error occurs.
84
- */
85
- int coilRead (int address, Arduino_10BASE_T1S_UDP * client = nullptr );
86
-
87
- /* *
88
- * Reads the status of a coil from the Modbus server with a specified ID.
89
- *
90
- * This function sends a request to read the status of a coil at the specified address
91
- * from the Modbus server with the given ID using the provided UDP client and port.
92
- *
93
- * @param id The ID of the Modbus server.
94
- * @param address The address of the coil to read.
95
- * @param client A pointer to the Arduino_10BASE_T1S_UDP client used for communication. Default is nullptr.
96
- * @param port The port number of the Modbus server. Default is 0.
97
- * @return int The status of the coil (1 for ON, 0 for OFF) or -1 if an error occurs.
98
- */
99
- int coilRead (int id, int address, Arduino_10BASE_T1S_UDP * client = nullptr );
100
-
101
- /* *
102
- * Writes a value to a coil on the Modbus server.
103
- *
104
- * This function sends a request to write a value to a coil at the specified address
105
- * on the Modbus server using the provided UDP client and port.
106
- *
107
- * @param address The address of the coil to write to.
108
- * @param value The value to write to the coil (1 for ON, 0 for OFF).
109
- * @param client A pointer to the Arduino_10BASE_T1S_UDP client used for communication. Default is nullptr.
110
- * @param port The port number of the Modbus server. Default is 0.
111
- * @return int Returns 1 if the write operation is successful, 0 otherwise.
112
- */
113
- int coilWrite (int address, uint16_t value, Arduino_10BASE_T1S_UDP * client = nullptr );
114
-
115
- /* *
116
- * Writes a value to a coil on the Modbus server with a specified ID.
117
- *
118
- * This function sends a request to write a value to a coil at the specified address
119
- * on the Modbus server with the given ID using the provided UDP client and port.
120
- *
121
- * @param id The ID of the Modbus server.
122
- * @param address The address of the coil to write to.
123
- * @param value The value to write to the coil (1 for ON, 0 for OFF).
124
- * @param client A pointer to the Arduino_10BASE_T1S_UDP client used for communication. Default is nullptr.
125
- * @param port The port number of the Modbus server. Default is 0.
126
- * @return int Returns 1 if the write operation is successful, 0 otherwise.
127
- */
128
- int coilWrite (int id, int address, uint16_t value, Arduino_10BASE_T1S_UDP * client = nullptr );
129
-
130
- /* *
131
- * Reads the status of a discrete input from the Modbus server.
132
- *
133
- * This function sends a request to read the status of a discrete input at the specified address
134
- * from the Modbus server using the provided UDP client and port.
135
- *
136
- * @param address The address of the discrete input to read.
137
- * @param client A pointer to the Arduino_10BASE_T1S_UDP client used for communication. Default is nullptr.
138
- * @param port The port number of the Modbus server. Default is 0.
139
- * @return int The status of the discrete input (1 for ON, 0 for OFF) or -1 if an error occurs.
140
- */
141
- int discreteInputRead (int address, Arduino_10BASE_T1S_UDP * client = nullptr );
142
-
143
- /* *
144
- * Reads the status of a discrete input from the Modbus server with a specified ID.
145
- *
146
- * This function sends a request to read the status of a discrete input at the specified address
147
- * from the Modbus server with the given ID using the provided UDP client and port.
148
- *
149
- * @param id The ID of the Modbus server.
150
- * @param address The address of the discrete input to read.
151
- * @param client A pointer to the Arduino_10BASE_T1S_UDP client used for communication. Default is nullptr.
152
- * @param port The port number of the Modbus server. Default is 0.
153
- * @return int The status of the discrete input (1 for ON, 0 for OFF) or -1 if an error occurs.
154
- */
155
- int discreteInputRead (int id, int address, Arduino_10BASE_T1S_UDP * client = nullptr );
156
-
157
- /* *
158
- * Reads the value of an input register from the Modbus server.
159
- *
160
- * This function sends a request to read the value of an input register at the specified address
161
- * from the Modbus server using the provided UDP client and port.
162
- *
163
- * @param address The address of the input register to read.
164
- * @param client A pointer to the Arduino_10BASE_T1S_UDP client used for communication. Default is nullptr.
165
- * @param port The port number of the Modbus server. Default is 0.
166
- * @return long The value of the input register or -1 if an error occurs.
167
- */
168
- long inputRegisterRead (int address, Arduino_10BASE_T1S_UDP * client = nullptr );
169
-
170
- /* *
171
- * Reads the value of an input register from the Modbus server with a specified ID.
172
- *
173
- * This function sends a request to read the value of an input register at the specified address
174
- * from the Modbus server with the given ID using the provided UDP client and port.
175
- *
176
- * @param id The ID of the Modbus server.
177
- * @param address The address of the input register to read.
178
- * @param client A pointer to the Arduino_10BASE_T1S_UDP client used for communication. Default is nullptr.
179
- * @param port The port number of the Modbus server. Default is 0.
180
- * @return long The value of the input register or -1 if an error occurs.
181
- */
182
- long inputRegisterRead (int id, int address, Arduino_10BASE_T1S_UDP * client = nullptr );
183
-
184
- /* *
185
- * Writes a value to a holding register on the Modbus server.
186
- *
187
- * This function sends a request to write a value to a holding register at the specified address
188
- * on the Modbus server using the provided UDP client and port.
189
- *
190
- * @param address The address of the holding register to write to.
191
- * @param value The value to write to the holding register.
192
- * @param client A pointer to the Arduino_10BASE_T1S_UDP client used for communication. Default is nullptr.
193
- * @param port The port number of the Modbus server. Default is 0.
194
- * @return int Returns 1 if the write operation is successful, 0 otherwise.
195
- */
196
- int holdingRegisterWrite (int address, uint16_t value, Arduino_10BASE_T1S_UDP * client = nullptr );
197
-
198
- /* *
199
- * Writes a value to a holding register on the Modbus server with a specified ID.
200
- *
201
- * This function sends a request to write a value to a holding register at the specified address
202
- * on the Modbus server with the given ID using the provided UDP client and port.
203
- *
204
- * @param id The ID of the Modbus server.
205
- * @param address The address of the holding register to write to.
206
- * @param value The value to write to the holding register.
207
- * @param client A pointer to the Arduino_10BASE_T1S_UDP client used for communication. Default is nullptr.
208
- * @param port The port number of the Modbus server. Default is 0.
209
- * @return int Returns 1 if the write operation is successful, 0 otherwise.
210
- */
211
- int holdingRegisterWrite (int id, int address, uint16_t value, Arduino_10BASE_T1S_UDP * client = nullptr );
212
-
213
- /* *
214
- * Reads the value of a holding register from the Modbus server.
215
- *
216
- * This function sends a request to read the value of a holding register at the specified address
217
- * from the Modbus server using the provided UDP client and port.
218
- *
219
- * @param address The address of the holding register to read.
220
- * @param client A pointer to the Arduino_10BASE_T1S_UDP client used for communication. Default is nullptr.
221
- * @param port The port number of the Modbus server. Default is 0.
222
- * @return long The value of the holding register or -1 if an error occurs.
223
- */
224
- long holdingRegisterRead (int address, Arduino_10BASE_T1S_UDP * client = nullptr );
225
-
226
- /* *
227
- * Reads the value of a holding register from the Modbus server with a specified ID.
228
- *
229
- * This function sends a request to read the value of a holding register at the specified address
230
- * from the Modbus server with the given ID using the provided UDP client and port.
231
- *
232
- * @param id The ID of the Modbus server.
233
- * @param address The address of the holding register to read.
234
- * @param client A pointer to the Arduino_10BASE_T1S_UDP client used for communication. Default is nullptr.
235
- * @param port The port number of the Modbus server. Default is 0.
236
- * @return long The value of the holding register or -1 if an error occurs.
237
- */
238
- long holdingRegisterRead (int id, int address, Arduino_10BASE_T1S_UDP * client = nullptr );
239
- void setT1SClient (Arduino_10BASE_T1S_UDP & client);
240
- void setRxTimeout (unsigned long timeout = RX_TIMEOUT);
241
- void setT1SPort (int port = 8889 );
242
- void update ();
243
- void setCallback (callback_f cb = nullptr );
244
- void enablePOE ();
245
- void disablePOE ();
64
+
65
+ /* *
66
+ * Sets the IP address of the Modbus server.
67
+ *
68
+ * This function sets the IP address of the Modbus server that the client will communicate with.
69
+ *
70
+ * @param server_ip The IP address of the Modbus server. Default is IPAddress(0, 0, 0, 0).
71
+ */
72
+ void setServerIp (IPAddress server_ip = IPAddress(0 , 0 , 0 , 0 ));
73
+
74
+ /* *
75
+ * Sets the port number of the Modbus server.
76
+ *
77
+ * This function sets the port number of the Modbus server that the client will communicate with.
78
+ *
79
+ * @param server_port The port number of the Modbus server. Default is 8889.
80
+ */
81
+ void setServerPort (uint16_t server_port = 8889 );
82
+
83
+ /* *
84
+ * Sets the Modbus ID of the client.
85
+ *
86
+ * This function sets the Modbus ID that the client will use for communication.
87
+ *
88
+ * @param id The Modbus ID.
89
+ */
90
+ void setModbusId (uint16_t id);
91
+
92
+ /* *
93
+ * Reads the status of a coil from the Modbus server.
94
+ *
95
+ * This function sends a request to read the status of a coil at the specified address
96
+ * from the Modbus server using the provided UDP client and port.
97
+ *
98
+ * @param address The address of the coil to read.
99
+ * @param client A pointer to the Arduino_10BASE_T1S_UDP client used for communication. Default is nullptr.
100
+ * @return int The status of the coil (1 for ON, 0 for OFF) or -1 if an error occurs.
101
+ */
102
+ int coilRead (int address, Arduino_10BASE_T1S_UDP * client = nullptr );
103
+
104
+ /* *
105
+ * Reads the status of a coil from the Modbus server with a specified ID.
106
+ *
107
+ * This function sends a request to read the status of a coil at the specified address
108
+ * from the Modbus server with the given ID using the provided UDP client and port.
109
+ *
110
+ * @param id The ID of the Modbus server.
111
+ * @param address The address of the coil to read.
112
+ * @param client A pointer to the Arduino_10BASE_T1S_UDP client used for communication. Default is nullptr.
113
+ * @return int The status of the coil (1 for ON, 0 for OFF) or -1 if an error occurs.
114
+ */
115
+ int coilRead (int id, int address, Arduino_10BASE_T1S_UDP * client = nullptr );
116
+
117
+ /* *
118
+ * Writes a value to a coil on the Modbus server.
119
+ *
120
+ * This function sends a request to write a value to a coil at the specified address
121
+ * on the Modbus server using the provided UDP client and port.
122
+ *
123
+ * @param address The address of the coil to write to.
124
+ * @param value The value to write to the coil (1 for ON, 0 for OFF).
125
+ * @param client A pointer to the Arduino_10BASE_T1S_UDP client used for communication. Default is nullptr.
126
+ * @return int Returns 1 if the write operation is successful, 0 otherwise.
127
+ */
128
+ int coilWrite (int address, uint16_t value, Arduino_10BASE_T1S_UDP * client = nullptr );
129
+
130
+ /* *
131
+ * Writes a value to a coil on the Modbus server with a specified ID.
132
+ *
133
+ * This function sends a request to write a value to a coil at the specified address
134
+ * on the Modbus server with the given ID using the provided UDP client and port.
135
+ *
136
+ * @param id The ID of the Modbus server.
137
+ * @param address The address of the coil to write to.
138
+ * @param value The value to write to the coil (1 for ON, 0 for OFF).
139
+ * @param client A pointer to the Arduino_10BASE_T1S_UDP client used for communication. Default is nullptr.
140
+ * @return int Returns 1 if the write operation is successful, 0 otherwise.
141
+ */
142
+ int coilWrite (int id, int address, uint16_t value, Arduino_10BASE_T1S_UDP * client = nullptr );
143
+
144
+ /* *
145
+ * Reads the status of a discrete input from the Modbus server.
146
+ *
147
+ * This function sends a request to read the status of a discrete input at the specified address
148
+ * from the Modbus server using the provided UDP client and port.
149
+ *
150
+ * @param address The address of the discrete input to read.
151
+ * @param client A pointer to the Arduino_10BASE_T1S_UDP client used for communication. Default is nullptr.
152
+ * @return int The status of the discrete input (1 for ON, 0 for OFF) or -1 if an error occurs.
153
+ */
154
+ int discreteInputRead (int address, Arduino_10BASE_T1S_UDP * client = nullptr );
155
+
156
+ /* *
157
+ * Reads the status of a discrete input from the Modbus server with a specified ID.
158
+ *
159
+ * This function sends a request to read the status of a discrete input at the specified address
160
+ * from the Modbus server with the given ID using the provided UDP client and port.
161
+ *
162
+ * @param id The ID of the Modbus server.
163
+ * @param address The address of the discrete input to read.
164
+ * @param client A pointer to the Arduino_10BASE_T1S_UDP client used for communication. Default is nullptr.
165
+ * @return int The status of the discrete input (1 for ON, 0 for OFF) or -1 if an error occurs.
166
+ */
167
+ int discreteInputRead (int id, int address, Arduino_10BASE_T1S_UDP * client = nullptr );
168
+
169
+ /* *
170
+ * Reads the value of an input register from the Modbus server.
171
+ *
172
+ * This function sends a request to read the value of an input register at the specified address
173
+ * from the Modbus server using the provided UDP client and port.
174
+ *
175
+ * @param address The address of the input register to read.
176
+ * @param client A pointer to the Arduino_10BASE_T1S_UDP client used for communication. Default is nullptr.
177
+ * @return long The value of the input register or -1 if an error occurs.
178
+ */
179
+ long inputRegisterRead (int address, Arduino_10BASE_T1S_UDP * client = nullptr );
180
+
181
+ /* *
182
+ * Reads the value of an input register from the Modbus server with a specified ID.
183
+ *
184
+ * This function sends a request to read the value of an input register at the specified address
185
+ * from the Modbus server with the given ID using the provided UDP client and port.
186
+ *
187
+ * @param id The ID of the Modbus server.
188
+ * @param address The address of the input register to read.
189
+ * @param client A pointer to the Arduino_10BASE_T1S_UDP client used for communication. Default is nullptr.
190
+ * @return long The value of the input register or -1 if an error occurs.
191
+ */
192
+ long inputRegisterRead (int id, int address, Arduino_10BASE_T1S_UDP * client = nullptr );
193
+
194
+ /* *
195
+ * Writes a value to a holding register on the Modbus server.
196
+ *
197
+ * This function sends a request to write a value to a holding register at the specified address
198
+ * on the Modbus server using the provided UDP client and port.
199
+ *
200
+ * @param address The address of the holding register to write to.
201
+ * @param value The value to write to the holding register.
202
+ * @param client A pointer to the Arduino_10BASE_T1S_UDP client used for communication. Default is nullptr.
203
+ * @return int Returns 1 if the write operation is successful, 0 otherwise.
204
+ */
205
+ int holdingRegisterWrite (int address, uint16_t value, Arduino_10BASE_T1S_UDP * client = nullptr );
206
+
207
+ /* *
208
+ * Writes a value to a holding register on the Modbus server with a specified ID.
209
+ *
210
+ * This function sends a request to write a value to a holding register at the specified address
211
+ * on the Modbus server with the given ID using the provided UDP client and port.
212
+ *
213
+ * @param id The ID of the Modbus server.
214
+ * @param address The address of the holding register to write to.
215
+ * @param value The value to write to the holding register.
216
+ * @param client A pointer to the Arduino_10BASE_T1S_UDP client used for communication. Default is nullptr.
217
+ * @return int Returns 1 if the write operation is successful, 0 otherwise.
218
+ */
219
+ int holdingRegisterWrite (int id, int address, uint16_t value, Arduino_10BASE_T1S_UDP * client = nullptr );
220
+
221
+ /* *
222
+ * Reads the value of a holding register from the Modbus server.
223
+ *
224
+ * This function sends a request to read the value of a holding register at the specified address
225
+ * from the Modbus server using the provided UDP client and port.
226
+ *
227
+ * @param address The address of the holding register to read.
228
+ * @param client A pointer to the Arduino_10BASE_T1S_UDP client used for communication. Default is nullptr.
229
+ * @return long The value of the holding register or -1 if an error occurs.
230
+ */
231
+ long holdingRegisterRead (int address, Arduino_10BASE_T1S_UDP * client = nullptr );
232
+
233
+ /* *
234
+ * Reads the value of a holding register from the Modbus server with a specified ID.
235
+ *
236
+ * This function sends a request to read the value of a holding register at the specified address
237
+ * from the Modbus server with the given ID using the provided UDP client and port.
238
+ *
239
+ * @param id The ID of the Modbus server.
240
+ * @param address The address of the holding register to read.
241
+ * @param client A pointer to the Arduino_10BASE_T1S_UDP client used for communication. Default is nullptr.
242
+ * @return long The value of the holding register or -1 if an error occurs.
243
+ */
244
+ long holdingRegisterRead (int id, int address, Arduino_10BASE_T1S_UDP * client = nullptr );
245
+
246
+ /* *
247
+ * Sets the T1S client for the Modbus communication.
248
+ *
249
+ * This function assigns a 10BASE-T1S UDP client to be used for Modbus communication.
250
+ *
251
+ * @param client A reference to an Arduino_10BASE_T1S_UDP object that represents the T1S client.
252
+ */
253
+ void setT1SClient (Arduino_10BASE_T1S_UDP & client);
254
+
255
+ /* *
256
+ * Sets the gateway IP address for the Modbus client.
257
+ *
258
+ * This function sets the gateway IP address for the Modbus client.
259
+ *
260
+ * @param gateway The gateway IP address.
261
+ */
262
+
263
+ void setGateway (IPAddress gateway = IPAddress(0 , 0 , 0 , 0 ));
264
+
265
+ /* *
266
+ * Sets the timeout for receiving a response from the Modbus server.
267
+ *
268
+ * This function sets the timeout for receiving a response from the Modbus server.
269
+ *
270
+ * @param timeout The timeout value in milliseconds.
271
+ */
272
+ void setRxTimeout (unsigned long timeout = RX_TIMEOUT);
273
+
274
+ /* *
275
+ * Sets the port to use for communication.
276
+ *
277
+ * This function sets the port to use for communication.
278
+ *
279
+ * @param port The port to use.
280
+ */
281
+ void setT1SPort (int port = 8889 );
282
+
283
+ /* *
284
+ * Polls the Modbus client for incoming data.
285
+ *
286
+ * This function polls the Modbus client for incoming data.
287
+ *
288
+ * @return int The number of bytes read from the client.
289
+ */
290
+ void update ();
291
+
292
+ /* *
293
+ * Sets the callback function to be used by the ModbusT1SClient.
294
+ *
295
+ * This function allows you to specify a callback function that will be called
296
+ * when certain events occur in the ModbusT1SClient. If no callback function is
297
+ * provided, the default value of nullptr will be used, meaning no callback
298
+ * will be executed.
299
+ *
300
+ * @param cb The callback function to be set. The default value is nullptr.
301
+ */
302
+ void setCallback (callback_f cb = nullptr );
303
+
304
+ /* *
305
+ * Enables Power Over Ethernet (POE) on the Modbus client.
306
+ *
307
+ * This function enables Power Over Ethernet (POE) on the Modbus client and sets the device as the power source.
308
+ */
309
+ void enablePOE ();
310
+
311
+ /* *
312
+ * Disables Power Over Ethernet (POE) on the Modbus client.
313
+ *
314
+ * This function disables Power Over Ethernet (POE) on the Modbus client and set the USB as power source.
315
+ */
316
+ void disablePOE ();
246
317
247
318
248
319
private:
0 commit comments