nodbus-plus 0.8.2 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/.readthedocs.yaml +35 -0
  2. package/LICENSE.md +21 -21
  3. package/README.md +163 -48
  4. package/docs/Makefile +20 -0
  5. package/docs/client/channel.rst +209 -0
  6. package/docs/client/nodbus_master_serial.rst +559 -0
  7. package/docs/client/nodbus_master_tcp.rst +573 -0
  8. package/docs/conf.py +41 -0
  9. package/docs/images/01-readcoils.png +0 -0
  10. package/docs/images/02-readinputs.png +0 -0
  11. package/docs/images/03-readholding.png +0 -0
  12. package/docs/images/04-readinputsreg.png +0 -0
  13. package/docs/images/05-writecoil.png +0 -0
  14. package/docs/images/06-writeregister.png +0 -0
  15. package/docs/images/15-writecoil.png +0 -0
  16. package/docs/images/16.png +0 -0
  17. package/docs/images/22-mask.png +0 -0
  18. package/docs/images/23.png +0 -0
  19. package/docs/images/7.png +0 -0
  20. package/docs/images/modbus_pdu.png +0 -0
  21. package/docs/images/serial_adu.png +0 -0
  22. package/docs/images/tcp_adu.png +0 -0
  23. package/docs/index.rst +30 -0
  24. package/docs/make.bat +35 -0
  25. package/docs/protocol/modbus_master.rst +276 -0
  26. package/docs/protocol/modbus_master_serial.rst +290 -0
  27. package/docs/protocol/modbus_master_tcp.rst +296 -0
  28. package/docs/protocol/modbus_server.rst +469 -0
  29. package/docs/protocol/modbus_server_serial.rst +543 -0
  30. package/docs/protocol/modbus_server_tcp.rst +365 -0
  31. package/docs/requirements.txt +4 -0
  32. package/docs/server/net_server.rst +242 -0
  33. package/docs/server/nodbus_serial_server.rst +652 -0
  34. package/docs/server/nodbus_tcp_server.rst +505 -0
  35. package/docs/starting.rst +192 -0
  36. package/docs/static/simple logo.jpg +0 -0
  37. package/package.json +39 -30
  38. package/samples/mb_serial_server.js +77 -0
  39. package/samples/mb_tcp_client.js +114 -0
  40. package/samples/mb_tcp_server.js +58 -0
  41. package/src/client/net/serialchannel.js +195 -0
  42. package/src/client/net/tcpchannel.js +233 -0
  43. package/src/client/net/udpchannel.js +243 -0
  44. package/src/client/nodbus_serial_client.js +577 -0
  45. package/src/client/nodbus_tcp_client.js +542 -0
  46. package/src/nodbus-plus.js +157 -110
  47. package/src/protocol/modbus_master.js +298 -961
  48. package/src/protocol/modbus_master_serial.js +247 -0
  49. package/src/protocol/modbus_master_tcp.js +219 -0
  50. package/src/protocol/modbus_server.js +936 -0
  51. package/src/protocol/modbus_server_serial.js +368 -0
  52. package/src/protocol/modbus_server_tcp.js +129 -0
  53. package/src/protocol/utils.js +296 -0
  54. package/src/server/net/serialserver.js +184 -0
  55. package/src/server/net/tcpserver.js +290 -0
  56. package/src/server/net/udpserver.js +242 -0
  57. package/src/server/nodbus_serial_server.js +238 -0
  58. package/src/server/nodbus_tcp_server.js +249 -0
  59. package/test/modbus_master.test.js +279 -0
  60. package/test/modbus_master_serial.test.js +124 -0
  61. package/test/modbus_master_tcp.test.js +178 -0
  62. package/test/modbus_server.test.js +506 -0
  63. package/test/modbus_server_serial.test.js +328 -0
  64. package/test/modbus_server_tcp.test.js +91 -0
  65. package/test/nodbus_client_serial.test.js +307 -0
  66. package/test/nodbus_client_tcp.test.js +334 -0
  67. package/test/nodbus_server_serial.test.js +255 -0
  68. package/test/nodbus_server_tcp.test.js +216 -0
  69. package/CHANGELOG.md +0 -27
  70. package/src/client/m_stcp_client.js +0 -214
  71. package/src/client/m_tcp_client.js +0 -234
  72. package/src/net/tcpclient.js +0 -173
  73. package/src/net/tcpserver.js +0 -329
  74. package/src/protocol/adu.js +0 -40
  75. package/src/protocol/ascii_adu.js +0 -139
  76. package/src/protocol/boolean_register.js +0 -78
  77. package/src/protocol/functions/Force_Multiple_Coils.js +0 -76
  78. package/src/protocol/functions/Force_Single_Coil.js +0 -54
  79. package/src/protocol/functions/Mask_Holding_Register.js +0 -47
  80. package/src/protocol/functions/Preset_Multiple_Registers.js +0 -53
  81. package/src/protocol/functions/Preset_Single_Register.js +0 -39
  82. package/src/protocol/functions/Read_Coil_Status.js +0 -59
  83. package/src/protocol/functions/Read_Holding_Registers.js +0 -52
  84. package/src/protocol/functions/Read_Input_Registers.js +0 -52
  85. package/src/protocol/functions/Read_Input_Status.js +0 -58
  86. package/src/protocol/mbap.js +0 -60
  87. package/src/protocol/modbus_device.js +0 -35
  88. package/src/protocol/modbus_slave.js +0 -522
  89. package/src/protocol/pdu.js +0 -70
  90. package/src/protocol/rtu_adu.js +0 -122
  91. package/src/protocol/serial_adu.js +0 -29
  92. package/src/protocol/tcp_adu.js +0 -84
  93. package/src/protocol/word_register.js +0 -122
  94. package/src/server/m_stcp_server.js +0 -310
  95. package/src/server/m_tcp_server.js +0 -295
  96. package/test/modbus-stcp-server-test.js +0 -72
  97. package/test/modbus-stcp-server-test1.js +0 -72
  98. package/test/modbus-tcp-client-test.js +0 -159
  99. package/test/modbus-tcp-server-test.js +0 -75
  100. package/test/modbus-tcp-server-test2.js +0 -75
  101. package/test/modbus_stcp_client.js +0 -149
@@ -0,0 +1,559 @@
1
+ .. _nodbus_serial_master:
2
+
3
+ ======================
4
+ Class: NodbusSerialClient
5
+ ======================
6
+
7
+ **Nodbus-Plus v1.0 Documentation**
8
+
9
+ .. contents:: Table of Contents
10
+ :depth: 3
11
+
12
+ This class extends :ref:`ModbusSerialClient Class <modbus_serial_master>`. It provides ready to use Modbus RTU/Ascii Client.
13
+
14
+
15
+ Creating a NodbusSerialClient Instance
16
+ ===================================
17
+
18
+ new NodbusSerialClient(channelClass)
19
+ -------------------------------------
20
+
21
+ * **channelClass:** <Class>: This argument define the constructor for the net layer. See :ref:`NetChannel Class <nodbus_net_channel>`.
22
+ * **Returns:** <NodbusSerialClient>
23
+
24
+ NodbusPlus expose the function createSerialClient([netConstructor]) to create new instances for NodbusSerialClient.
25
+
26
+ * **netConstructor** <string>: Can be 'tcp','udp' or serial. Default 'tcp'.
27
+
28
+ .. code-block:: javascript
29
+
30
+ const nodbus = require('nodbus-plus');
31
+ let nodbusSerialClient = nodbus.createSerialClient('tcp'); //default settings, net layer is tcp
32
+
33
+ However new NodbusSerialClient instance can be created with customs :ref:`NetChannel <nodbus_net_channel>` importing the nodbusSerialClient Class.
34
+
35
+ .. code-block:: javascript
36
+
37
+ const NodbusSerialClient = require('nodbus-plus').NodbusSerialClient;
38
+ const NetChannel = require('custom\net\custome_channel.js'); //this is a example file for a user channel, it do not exist on nodbus-plus library
39
+
40
+
41
+ let nodbusSerialClient = new NodbusSerialClient(NetChannel);
42
+
43
+
44
+
45
+ NodbusSerialClient's Events
46
+ ===========================
47
+
48
+
49
+ Event: 'broadcast-timeout'
50
+ -----------------------------------
51
+
52
+ This event indicate that the client has no pending broadcast request and is free to send another request.
53
+
54
+
55
+ Event: 'connection'
56
+ -------------------
57
+
58
+ * **id** <string>: Channel's name
59
+
60
+ Emitted when the client succesfully connect to a server.
61
+
62
+ Event: 'connection-closed'
63
+ ---------------------------
64
+
65
+ * **id** <string>: Channel's name
66
+
67
+ Emitted when the channel close the connection.
68
+
69
+
70
+ Event: 'data'
71
+ ---------------------
72
+
73
+ * **id** <string>: Channel's name.
74
+
75
+ * **data** <Buffer>: Data received.
76
+
77
+ Emitted when the channel emit the data event.
78
+
79
+
80
+
81
+ Event: 'error'
82
+ --------------
83
+
84
+ * **e** <Error>: The error object.
85
+
86
+ Emitted when a error occurs.
87
+
88
+
89
+ Event: 'req-timeout'
90
+ --------------------
91
+
92
+ * **transactionId** <number>: Indicate wich request fires the timeout event.
93
+ * **vreq** <Buffer>: Modbus request adu buffer.
94
+
95
+ .. code-block:: javascript
96
+
97
+ nodbusSerialClient.on('req-timeout', (id, req) ->{
98
+ console.log('Timeout error from request: ' + id + '\n');
99
+ })
100
+
101
+ This event is emmited when the number of milliseconds pass to :ref:`Method: modbusTcpClient.setReqTimer(transactionId, [timeout])` ends without call
102
+ :ref:`Method: modbusTcpClient.clearReqTimer(transactionId)`
103
+
104
+
105
+ Event: 'request'
106
+ ----------------
107
+
108
+ * **id** <string>: Channel's name.
109
+
110
+ * **request** <object>: A with following properties:
111
+
112
+ * *timeStamp* <number>: A timestamp for the request.
113
+
114
+ * *transactionId* <number>: The header's transaction id field value.
115
+
116
+ * *unitId* <number>: The header's unit id field value.
117
+
118
+ * *functionCode* <number>: The modbus request's function code.
119
+
120
+ * *data* <Buffer>: The pdu's data.
121
+
122
+ Emited after the client send data to the server.
123
+
124
+
125
+ Event: 'response'
126
+ ----------------
127
+
128
+ * **id** <string>: Channel's name.
129
+
130
+ * **response** <object>: A with following properties:
131
+
132
+ * *timeStamp* <number>: A timestamp for the request.
133
+
134
+ * *transactionId* <number>: The header's transaction id field value.
135
+
136
+ * *unitId* <number>: The header's unit id field value.
137
+
138
+ * *functionCode* <number>: The modbus request's function code.
139
+
140
+ * *data* <Buffer>: The pdu's data.
141
+
142
+ Emited when data received fron server has been validated.
143
+
144
+
145
+ Event: 'transaction'
146
+ --------------------
147
+
148
+ * **req** <Buffer>: Modbus Tcp request adu.
149
+ * **res** <Buffer>: Modbus Tcp request adu.
150
+
151
+ This event is emmited when the :ref:`Method: modbusTcpClient.processResAdu(bufferAdu)` is called to manage a server response.
152
+
153
+
154
+ Event: 'write'
155
+ ---------------------
156
+
157
+ * **id** <string>: Channel's name.
158
+
159
+ * **reqAdu** <Buffer>: Client request, a modbus tcp adu.
160
+
161
+ Emited after the client send data to the server.
162
+
163
+
164
+ NodbusSerialClient's Atributes
165
+ ===============================
166
+
167
+
168
+ Atribute: nodbusSerialClient.activeRequest
169
+ ------------------------------------------
170
+
171
+ * <Buffer>
172
+
173
+ This property store the current active request, if no request is pending then is null.
174
+
175
+ Atribute: nodbusSerialClient.channelType
176
+ --------------------------------------
177
+
178
+ * <Map> Map with types of channels.
179
+ * *key* <string> type id.
180
+ * *value* <object>: A channel class. See :ref:`NetChannel Class <nodbus_net_channel>` to be used as constructor.
181
+
182
+ This property store the client's channel constructor. Built in channel for Nodbus-Plus tcp client are 'tcp1', 'udp1' and 'serial1'.
183
+
184
+
185
+ Atribute: nodbusSerialClient.channels
186
+ -------------------------------------
187
+
188
+ * <Map> Map with client's channel list.
189
+ * *key* <string> Channel's id.
190
+ * *value* <object>: A channel object. See :ref:`NetChannel Class <nodbus_net_channel>`
191
+
192
+
193
+
194
+
195
+ NodbusSerialClient's Methods
196
+ ==============================
197
+
198
+
199
+ See :ref:`ModbusSerialClient Class Methods <modbus_serial_client_methods>` for all base class inherited methods.
200
+
201
+
202
+
203
+ Method: nodbusSerialClient.addChannel(id, type, channelCfg)
204
+ ------------------------------------------------------------
205
+
206
+ * **id** <String>: Channels's name. Must be unique for each channel.
207
+
208
+ * **type** <string>: Channel's constructor id stored on channelType property. Default value is 'tcp1'.
209
+
210
+ * **channelCfg** <object>: Configuration object for the channel with following properties for tcp and udp:
211
+
212
+ * *ip* <String>: Modbus server's ip address. Defaul 'localhost'.
213
+ * *port* <number> Port where the modbus server's is listening.
214
+ * udpType <string>: Used in udp server to set 'udp4' or 'udp6'. Default 'udp6'.
215
+ * *timeout* <number> Number of milliseconds to await for a response on the channel.
216
+
217
+ * **channelCfg** <object>: Configuration object with the following properties for serial network:
218
+
219
+ * port <string> : The path to the serial port. Example 'COM1.
220
+ * speed <number>: Enum with following baudrates in bps :
221
+
222
+ * 0-110
223
+ * 1-300
224
+ * 2-1200
225
+ * 3-2400
226
+ * 4-4800
227
+ * 5-9600
228
+ * 6-14400
229
+ * 7-19200 Default
230
+ * 8-38400
231
+ * 9-57600
232
+ * 10-115200
233
+
234
+ * dataBits <number>: 7 or 8. Default 8.
235
+ * stopBits <number>: 0 or 1.
236
+ * parity <number>: Enum with following value.
237
+
238
+ * 0-'none'
239
+ * 1-'even' Default
240
+ * 2-'odd'
241
+
242
+ * timeBetweenFrame <number>: Number of millisends to await without receiving data to consider end of modbus frame.
243
+ * *timeout* <number> Number of milliseconds to await for a response on the channel.
244
+
245
+ This method create a channel from the channel's constructor and add to the channels list :ref:`Atribute: nodbusSerialClient.channels`.
246
+
247
+ .. code-block:: javascript
248
+
249
+ let device1 = {
250
+ ip: '127.0.0.1', //server's ip address
251
+ port: 502, //tcp port
252
+ timeout: 500} // miliseconds for timeout event
253
+
254
+ nodbusSerialClient.addChannel('device1', 'tcp1' device1);
255
+
256
+
257
+ Method: nodbusSerialClient.connect(id)
258
+ ----------------------------------------
259
+
260
+ * **id** <String>: Channels's name.
261
+
262
+ This method try to connect to the remote server configured on the channel or open the serial port given.
263
+
264
+
265
+
266
+ Method: nodbusSerialClient.delChannel(id)
267
+ ------------------------------------------
268
+
269
+ * **id** <String>: Channels's name.
270
+
271
+ This method remove a channel from the channels list :ref:`Atribute: nodbusSerialClient.channels`.
272
+
273
+
274
+
275
+ Method: nodbusSerialClient.disconnect(id)
276
+ ------------------------------------------
277
+
278
+ * **id** <String>: Channels's name.
279
+
280
+ This method send the FIN package to the remote server to close the connection or close the serial port guiven.
281
+
282
+
283
+
284
+ Method: nodbusSerialClient.isChannelReady(id)
285
+ ----------------------------------------------
286
+
287
+ * **id** <String>: Channels's name.
288
+ * **return** <boolean>: true if channel is connected and ready to send data to the server, otherwise false.
289
+
290
+ This method return true if channel is connected and ready to send data to the server.
291
+
292
+
293
+
294
+
295
+ Method: nodbusSerialClient.makeRequest(unitId, pdu, asciiMode)
296
+ ---------------------------------------------------------------
297
+
298
+ * **unitId** <number>: modbus address.
299
+ * **pdu** <Buffer>: The pdu's buffer.
300
+ * **asciiMode** <boolean> A flag to indicate if the request must be in ascii format. Default value is false, rtu mode.
301
+ * **Returns** <Buffer>: return a tcp adu request's buffer
302
+
303
+ This functions first increment the transaction counter and create a modbus tcp request ready to be send to the client.
304
+
305
+
306
+ Method: nodbusSerialClient.forceSingleCoil(value, channelId, unitId, startCoil, asciiMode)
307
+ --------------------------------------------------------------------------------------------
308
+
309
+ * **value** <boolean>: Value to force.
310
+ * **channelId** <string>: Channels's name.
311
+ * **unitId** <number>: Legacy modbus address for being using for a gateway. Modbus spec recomend using 255.
312
+ * **startCoil** <number>: Coil to force at 0 address.
313
+ * **asciiMode** <boolean> A flag to indicate if the request must be in ascii format. Default value is false, rtu mode.
314
+ * **Returns** <boolean>: true if success
315
+
316
+ This functions create the force coil (function 05) request and sended to server.
317
+
318
+ .. code-block:: javascript
319
+
320
+ //forcing coil to 1 on channel device1, unitId 255 define device itself.
321
+ //If device is a modbus gateway then unitId define the modbus address for desire station.
322
+ //coils 10.
323
+ successStatus = nodbusSerialClient.forceSingleCoil(1, 'device1', 255, 10);
324
+
325
+
326
+ Method: nodbusSerialClient.forceMultipleCoils(values, channelId, unitId, startCoil, asciiMode)
327
+ -----------------------------------------------------------------------------------------------
328
+
329
+ * **value** <Array>: Array of booleans with values to force.
330
+ * **channelId** <string>: Channels's name.
331
+ * **unitId** <number>: Legacy modbus address for being using for a gateway. Modbus spec recomend using 255.
332
+ * **startCoil** <number>: First coil to force starting at 0 address.
333
+ * **asciiMode** <boolean> A flag to indicate if the request must be in ascii format. Default value is false, rtu mode.
334
+ * **Returns** <boolean>: true if success
335
+
336
+ This functions create the force multiples coils (function 15) request and sended to server.
337
+
338
+ .. code-block:: javascript
339
+
340
+ //forcing 6 coils to desire values on channel device1, unitId 255 define device itself.
341
+ //If device is a modbus gateway then unitId define the modbus address for desire station.
342
+ //starting at coil 10.
343
+ vals = [1, 0, 1, 1, 0, 1]
344
+ successStatus = nodbusSerialClient.forceMultipleCoils(val, 'device1', 255, 10);
345
+
346
+
347
+ Method: nodbusSerialClient.maskHoldingRegister(values, channelId, unitId, startRegister, asciiMode)
348
+ ----------------------------------------------------------------------------------------------------
349
+
350
+ * **values** <Array> An array of 16 numbers with values to force. Index 0 is de less significant bit.
351
+ A value off 1 force to 1 the corresponding bit, 0 force to 0, other values don't change the bit value.
352
+ * **channelId** <string>: Channels's name.
353
+ * **unitId** <number>: Legacy modbus address for being using for a gateway. Modbus spec recomend using 255.
354
+ * **startRegister** <number>: Register to write at 0 address.
355
+ * **asciiMode** <boolean> A flag to indicate if the request must be in ascii format. Default value is false, rtu mode.
356
+ * **Returns** <boolean>: true if success
357
+
358
+ This functions create the mask holding register (function 22) request and sended to server.
359
+
360
+ .. code-block:: javascript
361
+
362
+ //forcing register on channel device1, unitId 255 define device itself.
363
+ //If device is a modbus gateway then unitId define the modbus address for desire station.
364
+ //register 99 startint at 0.
365
+
366
+ let vals = [1, 0, 1, 0, 2, 2, 1, 1, 2, 2, 0, 0, 0, 1, 2, 2]
367
+ successStatus = nodbusSerialClient.maskHoldingRegister(vals, 'device1', 255, 99);
368
+
369
+
370
+
371
+ Method: nodbusSerialClient.presetSingleRegister(value, channelId, unitId, startRegister, asciiMode)
372
+ ----------------------------------------------------------------------------------------------------
373
+
374
+ * **value** <Buffer> a two Bytes length buffer.
375
+ * **channelId** <string>: Channels's name.
376
+ * **unitId** <number>: Legacy modbus address for being using for a gateway. Modbus spec recomend using 255.
377
+ * **startRegister** <number>: Register to write at 0 address.
378
+ * **asciiMode** <boolean> A flag to indicate if the request must be in ascii format. Default value is false, rtu mode.
379
+ * **Returns** <boolean>: true if success
380
+
381
+ This functions create the preset single register (function 06) request and sended to server.
382
+
383
+ .. code-block:: javascript
384
+
385
+ //forcing register on channel device1, unitId 255 define device itself.
386
+ //If device is a modbus gateway then unitId define the modbus address for desire station.
387
+ //register 99 startint at 0.
388
+
389
+ let val = Buffer.alloc(2);
390
+ val.writeInt16BE(4567);
391
+ successStatus = nodbusSerialClient.presetSingleRegister(val, 'device1', 255, 99);
392
+
393
+
394
+ Method: nodbusSerialClient.presetMultiplesRegisters(values, channelId, unitId, startRegister, asciiMode)
395
+ ---------------------------------------------------------------------------------------------------------
396
+
397
+ * **values** <Buffer> a two Bytes length buffer.
398
+ * **channelId** <string>: Channels's name.
399
+ * **unitId** <number>: Legacy modbus address for being using for a gateway. Modbus spec recomend using 255.
400
+ * **startRegister** <number>: Register to write at 0 address.
401
+ * **asciiMode** <boolean> A flag to indicate if the request must be in ascii format. Default value is false, rtu mode.
402
+ * **Returns** <boolean>: true if success
403
+
404
+ This functions create the preset multiple registers (function 16) request and sended to server. The amount ofregister to write is the
405
+ values's buffer half length.
406
+
407
+ .. code-block:: javascript
408
+
409
+ //writing 3 registers on channel device1, unitId 255 define device itself.
410
+ //If device is a modbus gateway then unitId define the modbus address for desire station.
411
+ //register 99 startint at 0.
412
+
413
+ let vals = Buffer.alloc(6);
414
+ let tempRegister = Buffer.alloc(2);
415
+ tempRegister.writeUInt16BE(245);
416
+ nodbusSerialClient.setWordToBuffer(tempRegister, vals, 0);
417
+ tempRegister.writeUInt16BE(8965);
418
+ nodbusSerialClient.setWordToBuffer(tempRegister, vals, 1);
419
+ tempRegister.writeUInt16BE(1045);
420
+ nodbusSerialClient.setWordToBuffer(tempRegister, vals, 2);
421
+ successStatus = nodbusSerialClient.presetMultipleRegisters(vals, 'device1', 255, 99);
422
+
423
+
424
+
425
+ Method: nodbusSerialClient.readCoils(channelId, unitId, startCoil, coilsCuantity, asciiMode)
426
+ ---------------------------------------------------------------------------------------------
427
+
428
+ * **channelId** <string>: Channels's name.
429
+ * **unitId** <number>: Legacy modbus address for being using for a gateway. Modbus spec recomend using 255.
430
+ * **startCoil** <number>: Starting coil to read at 0 address.
431
+ * **coilsCuantity** <number>: Number of coils to read.
432
+ * **asciiMode** <boolean> A flag to indicate if the request must be in ascii format. Default value is false, rtu mode.
433
+ * **Returns** <boolean>: true if success
434
+
435
+ This functions create the read coil (function 01) request and sended to server.
436
+
437
+ .. code-block:: javascript
438
+
439
+ //Reading coil on channel device1, unitId 255 define device itself.
440
+ //If device is a modbus gateway then unitId define the modbus address for desire station.
441
+ //coils 10 startint at 0.
442
+ //Read 14 coils
443
+ successStatus = nodbusSerialClient.readCoils('device1', 255, 10, 14);
444
+
445
+
446
+ Method: nodbusSerialClient.readHoldingRegisters(channelId, unitId, startRegister, registersCuantity, asciiMode)
447
+ ------------------------------------------------------------------------------------------------------------------
448
+
449
+ * **channelId** <string>: Channels's name.
450
+ * **unitId** <number>: Legacy modbus address for being using for a gateway. Modbus spec recomend using 255.
451
+ * **startRegister** <number>: Starting input to read at 0 address.
452
+ * **registerCuantity** <number>: Number of registers to read.
453
+ * **asciiMode** <boolean> A flag to indicate if the request must be in ascii format. Default value is false, rtu mode.
454
+ * **Returns** <boolean>: true if success
455
+
456
+ This functions create the read holding register (function 03) request and sended to server.
457
+
458
+ .. code-block:: javascript
459
+
460
+ //Reading input on channel device1, unitId 255 define device itself.
461
+ //If device is a modbus gateway then unitId define the modbus address for desire station.
462
+ //register 10 .
463
+ //Read 4 register
464
+ successStatus = nodbusSerialClient.readHoldingRegisters('device1', 255, 10, 4);
465
+
466
+
467
+
468
+ Method: nodbusSerialClient.readInputs(channelId, unitId, startInput, inputsCuantity, asciiMode)
469
+ --------------------------------------------------------------------------------------------------
470
+
471
+ * **channelId** <string>: Channels's name.
472
+ * **unitId** <number>: Legacy modbus address for being using for a gateway. Modbus spec recomend using 255.
473
+ * **startInput** <number>: Starting input to read at 0 address.
474
+ * **inputsCuantity** <number>: Number of inputs to read.
475
+ * **asciiMode** <boolean> A flag to indicate if the request must be in ascii format. Default value is false, rtu mode.
476
+ * **Returns** <boolean>: true if success
477
+
478
+ This functions create the read inputs (function 02) request and sended to server.
479
+
480
+ .. code-block:: javascript
481
+
482
+ //Reading input on channel device1, unitId 255 define device itself.
483
+ //If device is a modbus gateway then unitId define the modbus address for desire station.
484
+ //input 0 .
485
+ //Read 6 inputs
486
+ successStatus = nodbusSerialClient.readInputs('device1', 255, 0, 6);
487
+
488
+
489
+ Method: nodbusSerialClient.readInputRegisters(channelId, unitId, startRegister, registersCuantity, asciiMode)
490
+ --------------------------------------------------------------------------------------------------------------
491
+
492
+ * **channelId** <string>: Channels's name.
493
+ * **unitId** <number>: Legacy modbus address for being using for a gateway. Modbus spec recomend using 255.
494
+ * **startRegister** <number>: Starting input to read at 0 address.
495
+ * **registerCuantity** <number>: Number of inputs to read.
496
+ * **asciiMode** <boolean> A flag to indicate if the request must be in ascii format. Default value is false, rtu mode.
497
+ * **Returns** <boolean>: true if success
498
+
499
+ This functions create the read input register (function 04) request and sended to server.
500
+
501
+ .. code-block:: javascript
502
+
503
+ //Reading input on channel device1, unitId 255 define device itself.
504
+ //If device is a modbus gateway then unitId define the modbus address for desire station.
505
+ //register 10 .
506
+ //Read 4 register
507
+ successStatus = nodbusSerialClient.readInputRegisters('device1', 255, 10, 4);
508
+
509
+
510
+
511
+ Method: nodbusSerialClient.readWriteMultiplesRegisters(values, channelId, unitId, readStartingRegister, readRegisterCuantity, writeStartingRegister, asciiMode)
512
+ ---------------------------------------------------------------------------------------------------------------------------------------------------------------
513
+
514
+ * **values** <Buffer> a two Bytes length buffer.
515
+ * **channelId** <string>: Channels's name.
516
+ * **unitId** <number>: Legacy modbus address for being using for a gateway. Modbus spec recomend using 255.
517
+ * **readStartingRegister** <number>: Starting input to read at 0 address.
518
+ * **readRegisterCuantity** <number>: Number of registers to read.
519
+ * **writeStartingRegister** <number>: Register to write at 0 address.
520
+ * **asciiMode** <boolean> A flag to indicate if the request must be in ascii format. Default value is false, rtu mode.
521
+ * **Returns** <boolean>: true if success
522
+
523
+ This functions create the read and write holding registers (function 23) request and sended to server.
524
+
525
+ .. code-block:: javascript
526
+
527
+ //writing 3 registers on channel device1, unitId 255 define device itself and reading five registers from register 10
528
+ //If device is a modbus gateway then unitId define the modbus address for desire station.
529
+ //register 99 startint at 0.
530
+
531
+ let vals = Buffer.alloc(6);
532
+ let tempRegister = Buffer.alloc(2);
533
+ tempRegister.writeUInt16BE(245);
534
+ nodbusSerialClient.setWordToBuffer(tempRegister, vals, 0);
535
+ tempRegister.writeUInt16BE(8965);
536
+ nodbusSerialClient.setWordToBuffer(tempRegister, vals, 1);
537
+ tempRegister.writeUInt16BE(1045);
538
+ nodbusSerialClient.setWordToBuffer(tempRegister, vals, 2);
539
+ successStatus = nodbusSerialClient.readWriteMultiplesRegisters(vals, 'device1', 255, 10, 5, 99);
540
+
541
+
542
+ Method: nodbusSerialClient.getWordFromBuffer(targetBuffer, [offset])
543
+ -----------------------------------------------------------------------
544
+
545
+ * **targetBuffer** <Buffer>: Buffer with the objetive 16 bits register to read.
546
+ * **offset** <number>: A number with register's offset inside the buffer.
547
+ * **Return** <Buffer>: A two bytes length buffer.
548
+
549
+ This method read two bytes from target buffer with 16 bits align. Offset 0 get bytes 0 and 1, offset 4 gets bytes 8 and 9
550
+
551
+
552
+ Method: nodbusSerialClient.setWordToBuffer(value, targetBuffer, [offset])
553
+ ---------------------------------------------------------------------------
554
+
555
+ * **value** <Buffer>: two bytes length buffer.
556
+ * **targetBuffer** <Buffer>: Buffer with the objetive 16 bits register to write.
557
+ * **offset** <number>: A number with register's offset inside the buffer.
558
+
559
+ This method write a 16 bits register inside a buffer. The offset is 16 bits aligned.