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,573 @@
1
+ .. _nodbus_tcp_master:
2
+
3
+ ======================
4
+ Class: NodbusTcpClient
5
+ ======================
6
+
7
+ **Nodbus-Plus v1.0 Documentation**
8
+
9
+ .. contents:: Table of Contents
10
+ :depth: 3
11
+
12
+ This class extends :ref:`ModbusTcpClient Class <modbus_tcp_master>`. It provides ready to use Modbus TCP Client.
13
+
14
+
15
+ Creating a NodbusTcpClient Instance
16
+ ===================================
17
+
18
+ new NodbusTcpClient(channelClass)
19
+ -------------------------------------
20
+
21
+ * **channelClass:** <Class>: This argument define the constructor for the net layer. See :ref:`NetChannel Class <nodbus_net_channel>`.
22
+ * **Returns:** <NodbusTcpClient>
23
+
24
+ NodbusPlus expose the function createTcpClient([netConstructor]) to create new instances for NodbusTcpClient.
25
+
26
+ * **netConstructor** <string>: Can be 'tcp' or'udp'. Default 'tcp'.
27
+
28
+ .. code-block:: javascript
29
+
30
+ const nodbus = require('nodbus-plus');
31
+ let nodbusTcpClient = nodbus.createTcpClient('tcp'); //default settings, net layer is tcp
32
+
33
+ However new NodbusTcpClient instance can be created with customs :ref:`NetChannel <nodbus_net_channel>` importing the NodbusTcpClient Class.
34
+
35
+ .. code-block:: javascript
36
+
37
+ const NodbusTcpClient = require('nodbus-plus').NodbusTcpClient;
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 nodbusTcpClient = new NodbusTcpClient(NetChannel);
42
+
43
+
44
+
45
+ NodbusTcpClient's Events
46
+ ========================
47
+
48
+
49
+ Event: 'connection'
50
+ -------------------
51
+
52
+ * **id** <string>: Channel's name
53
+
54
+ Emitted when the client succesfully connect to a server.
55
+
56
+ Event: 'connection-closed'
57
+ ---------------------------
58
+
59
+ * **id** <string>: Channel's name
60
+
61
+ Emitted when the channel close the connection.
62
+
63
+
64
+ Event: 'data'
65
+ ---------------------
66
+
67
+ * **id** <string>: Channel's name.
68
+
69
+ * **data** <Buffer>: Data received.
70
+
71
+ Emitted when the channel emit the data event.
72
+
73
+
74
+
75
+ Event: 'error'
76
+ --------------
77
+
78
+ * **e** <Error>: The error object.
79
+
80
+ Emitted when a error occurs.
81
+
82
+
83
+ Event: 'req-timeout'
84
+ --------------------
85
+
86
+ * **transactionId** <number>: Indicate wich request fires the timeout event.
87
+ * **vreq** <Buffer>: Modbus request adu buffer.
88
+
89
+ .. code-block:: javascript
90
+
91
+ nodbusTcpClient.on('req-timeout', (id, req) ->{
92
+ console.log('Timeout error from request: ' + id + '\n');
93
+ })
94
+
95
+ This event is emmited when the number of milliseconds pass to :ref:`Method: modbusTcpClient.setReqTimer(transactionId, [timeout])` ends without call
96
+ :ref:`Method: modbusTcpClient.clearReqTimer(transactionId)`
97
+
98
+
99
+ Event: 'request'
100
+ ----------------
101
+
102
+ * **id** <string>: Channel's name.
103
+
104
+ * **request** <object>: A with following properties:
105
+
106
+ * *timeStamp* <number>: A timestamp for the request.
107
+
108
+ * *transactionId* <number>: The header's transaction id field value.
109
+
110
+ * *unitId* <number>: The header's unit id field value.
111
+
112
+ * *functionCode* <number>: The modbus request's function code.
113
+
114
+ * *data* <Buffer>: The pdu's data.
115
+
116
+ Emited after the client send data to the server.
117
+
118
+
119
+ Event: 'response'
120
+ ----------------
121
+
122
+ * **id** <string>: Channel's name.
123
+
124
+ * **response** <object>: A with following properties:
125
+
126
+ * *timeStamp* <number>: A timestamp for the request.
127
+
128
+ * *transactionId* <number>: The header's transaction id field value.
129
+
130
+ * *unitId* <number>: The header's unit id field value.
131
+
132
+ * *functionCode* <number>: The modbus request's function code.
133
+
134
+ * *data* <Buffer>: The pdu's data.
135
+
136
+ Emited when data received fron server has been validated.
137
+
138
+
139
+ Event: 'transaction'
140
+ --------------------
141
+
142
+ * **req** <Buffer>: Modbus Tcp request adu.
143
+ * **res** <Buffer>: Modbus Tcp request adu.
144
+
145
+ This event is emmited when the :ref:`Method: modbusTcpClient.processResAdu(bufferAdu)` is called to manage a server response.
146
+
147
+
148
+ Event: 'write'
149
+ ---------------------
150
+
151
+ * **id** <string>: Channel's name.
152
+
153
+ * **reqAdu** <Buffer>: Client request, a modbus tcp adu.
154
+
155
+ Emited after the client send data to the server.
156
+
157
+
158
+ NodbusTcpClient's Atributes
159
+ ===========================
160
+
161
+
162
+ Atribute: nodbusTcpClient._transactionCount
163
+ --------------------------------------------
164
+
165
+ * <number>
166
+
167
+ This property stores the tcp client's transactions counter. It should be not us directly instead through the accessor property transactionCount.
168
+
169
+
170
+ Atribute: nodbusTcpClient.maxNumberOfTransaction
171
+ -------------------------------------------------
172
+
173
+ * <number>
174
+
175
+ This property stores the maximum value of simultaneously open transactions allowed for the client. Default value is 64.
176
+
177
+ Atribute: nodbusTcpClient.channelType
178
+ --------------------------------------
179
+
180
+ * <Map> Map with types of channels.
181
+ * *key* <string> type id.
182
+ * *value* <object>: A channel class. See :ref:`NetChannel Class <nodbus_net_channel>` to be used as constructor.
183
+
184
+ This property store the client's channel constructor. Built in channel for Nodbus-Plus tcp client are 'tcp1' and 'udp1'.
185
+
186
+ Atribute: nodbusTcpClient.channels
187
+ -------------------------------------
188
+
189
+ * <Map> Map with client's channel list.
190
+ * *key* <string> Channel's id.
191
+ * *value* <object>: A channel object. See :ref:`NetChannel Class <nodbus_net_channel>`
192
+
193
+
194
+ Atribute: nodbusTcpClient.reqPool
195
+ -----------------------------------------
196
+
197
+ * <Map>
198
+ * *key* <number>: Transaction ID
199
+ * *value* <Buffer>: Modbus Tcp Adu.
200
+
201
+ A map to store active request. Each request is stored with his transaction's id as key.
202
+
203
+
204
+ Atribute: nodbusTcpClient.reqTimersPool
205
+ ----------------------------------------------
206
+
207
+ * <Map>
208
+ * *key* <number>: Transaction ID
209
+ * *value* <Buffer>: timer's id.
210
+
211
+ A map to store active request's timer. Each request start a timeout timer when is sended to server. This map store the timers is for each request using her transaction's id as key.
212
+
213
+
214
+ Atribute: nodbusTcpClient.transactionCount
215
+ -------------------------------------------
216
+
217
+ * <number>
218
+
219
+ Accesor property to get and set the transaction counter.
220
+
221
+
222
+ NodbusTcpClient's Methods
223
+ =========================
224
+
225
+
226
+ See :ref:`ModbusTcpClient Class Methods <modbus_tcp_client_methods>` for all base class inherited methods.
227
+
228
+
229
+
230
+ Method: nodbusTcpClient.addChannel(id, type, channelCfg)
231
+ ---------------------------------------------------------
232
+
233
+ * **id** <String>: Channel's name. Must be unique for each channel.
234
+
235
+ * **type** <string>: Channel's constructor id stored on channelType property. Default value is 'tcp1'.
236
+
237
+ * **channelCfg** <object>: Configuration object for the channel with following properties:
238
+
239
+ * *ip* <String>: Modbus server's ip address. Defaul 'localhost'.
240
+
241
+ * *port* <number> Port where the modbus server's is listening.
242
+
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: nodbusTcpClient.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
+ nodbusTcpClient.addChannel('device1', 'tcp1', device1);
255
+
256
+
257
+ Method: nodbusTcpClient.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.
263
+
264
+
265
+
266
+ Method: nodbusTcpClient.delChannel(id)
267
+ ----------------------------------------
268
+
269
+ * **id** <String>: Channels's name.
270
+
271
+ This method remove a channel from the channels list :ref:`Atribute: nodbusTcpClient.channels`.
272
+
273
+
274
+
275
+ Method: nodbusTcpClient.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.
281
+
282
+
283
+
284
+ Method: nodbusTcpClient.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
+ Method: nodbusTcpClient.parseHeader(bufferHeader)
294
+ ---------------------------------------------------------
295
+
296
+ * **bufferHeader** <Buffer>: Legacy modbus address for being using for a gateway. Modbus spec recomend using 255.
297
+ * **Returns** <object>: return a object with header's fields as properties:
298
+ * *transactionId* <number>: the transaction id.
299
+ * *protocolId* <number>: Must be 0 for modbus tcp protocol.
300
+ * *length* <number>: the number a bytes following the header including the unit id byte.
301
+ * *unitId* <number>: The unit id field, using by gateways to transalte modbus tcp adu to modbus serial adu.
302
+
303
+ This functions create a modbus tcp header's object. It throws a TypeError if argument is not a buffer instance and throw a RangeError if his length is diferent than 7. Example:
304
+
305
+ .. code-block:: javascript
306
+
307
+ let rawHeader = Buffer.from([0x00, 0x10, 0x00, 0x00, 0x00, 0x07, 0x05]);
308
+ let header = nodbusTcpClient.parseHeader(rawHeader);
309
+ console.log(header.transactionId);
310
+ console.log(header.protocolId);
311
+ console.log(header.length);
312
+ console.log(header.unitId);
313
+ //Output
314
+ //16
315
+ //0
316
+ //7
317
+ //5
318
+
319
+
320
+ Method: nodbusTcpClient.makeRequest(unitId, pdu)
321
+ ---------------------------------------------------------
322
+
323
+ * **unitId** <number>: Legacy modbus address for being using for a gateway. Modbus spec recomend using 255.
324
+ * **pdu** <Buffer>: The pdu's buffer.
325
+ * **Returns** <Buffer>: return a tcp adu request's buffer
326
+
327
+ This functions first increment the transaction counter and create a modbus tcp request ready to be send to the client.
328
+
329
+
330
+ Method: nodbusTcpClient.forceSingleCoil(value, channelId, unitId, startCoil)
331
+ --------------------------------------------------------------------------------------------
332
+
333
+ * **value** <boolean>: Value to force.
334
+ * **channelId** <string>: Channels's name.
335
+ * **unitId** <number>: Legacy modbus address for being using for a gateway. Modbus spec recomend using 255.
336
+ * **startCoil** <number>: Coil to force at 0 address.
337
+ * **Returns** <boolean>: true if success
338
+
339
+ This functions create the force coil (function 05) request and sended to server.
340
+
341
+ .. code-block:: javascript
342
+
343
+ //forcing coil to 1 on channel device1, unitId 255 define device itself.
344
+ //If device is a modbus gateway then unitId define the modbus address for desire station.
345
+ //coils 10.
346
+ successStatus = nodbusTcpClient.forceSingleCoil(1, 'device1', 255, 10);
347
+
348
+
349
+ Method: nodbusTcpClient.forceMultipleCoils(values, channelId, unitId, startCoil)
350
+ --------------------------------------------------------------------------------------------
351
+
352
+ * **value** <Array>: Array of booleans with values to force.
353
+ * **channelId** <string>: Channels's name.
354
+ * **unitId** <number>: Legacy modbus address for being using for a gateway. Modbus spec recomend using 255.
355
+ * **startCoil** <number>: First coil to force starting at 0 address.
356
+ * **Returns** <boolean>: true if success
357
+
358
+ This functions create the force multiples coils (function 15) request and sended to server.
359
+
360
+ .. code-block:: javascript
361
+
362
+ //forcing 6 coils to desire values 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
+ //starting at coil 10.
365
+ vals = [1, 0, 1, 1, 0, 1]
366
+ successStatus = nodbusTcpClient.forceMultipleCoils(val, 'device1', 255, 10);
367
+
368
+
369
+ Method: nodbusTcpClient.maskHoldingRegister(values, channelId, unitId, startRegister)
370
+ --------------------------------------------------------------------------------------------
371
+
372
+ * **values** <Array> An array of 16 numbers with values to force. Index 0 is de less significant bit.
373
+ A value off 1 force to 1 the corresponding bit, 0 force to 0, other values don't change the bit value.
374
+ * **channelId** <string>: Channels's name.
375
+ * **unitId** <number>: Legacy modbus address for being using for a gateway. Modbus spec recomend using 255.
376
+ * **startRegister** <number>: Register to write at 0 address.
377
+ * **Returns** <boolean>: true if success
378
+
379
+ This functions create the mask holding register (function 22) request and sended to server.
380
+
381
+ .. code-block:: javascript
382
+
383
+ //forcing register on channel device1, unitId 255 define device itself.
384
+ //If device is a modbus gateway then unitId define the modbus address for desire station.
385
+ //register 99 startint at 0.
386
+
387
+ let vals = [1, 0, 1, 0, 2, 2, 1, 1, 2, 2, 0, 0, 0, 1, 2, 2]
388
+ successStatus = nodbusTcpClient.maskHoldingRegister(vals, 'device1', 255, 99);
389
+
390
+
391
+
392
+ Method: nodbusTcpClient.presetSingleRegister(value, channelId, unitId, startRegister)
393
+ --------------------------------------------------------------------------------------------
394
+
395
+ * **value** <Buffer> a two Bytes length buffer.
396
+ * **channelId** <string>: Channels's name.
397
+ * **unitId** <number>: Legacy modbus address for being using for a gateway. Modbus spec recomend using 255.
398
+ * **startRegister** <number>: Register to write at 0 address.
399
+ * **Returns** <boolean>: true if success
400
+
401
+ This functions create the preset single register (function 06) request and sended to server.
402
+
403
+ .. code-block:: javascript
404
+
405
+ //forcing register on channel device1, unitId 255 define device itself.
406
+ //If device is a modbus gateway then unitId define the modbus address for desire station.
407
+ //register 99 startint at 0.
408
+
409
+ let val = Buffer.alloc(2);
410
+ val.writeInt16BE(4567);
411
+ successStatus = nodbusTcpClient.presetSingleRegister(val, 'device1', 255, 99);
412
+
413
+
414
+ Method: nodbusTcpClient.presetMultiplesRegisters(values, channelId, unitId, startRegister)
415
+ --------------------------------------------------------------------------------------------
416
+
417
+ * **values** <Buffer> a two Bytes length buffer.
418
+ * **channelId** <string>: Channels's name.
419
+ * **unitId** <number>: Legacy modbus address for being using for a gateway. Modbus spec recomend using 255.
420
+ * **startRegister** <number>: Register to write at 0 address.
421
+ * **Returns** <boolean>: true if success
422
+
423
+ This functions create the preset multiple registers (function 16) request and sended to server. The amount ofregister to write is the
424
+ values's buffer half length.
425
+
426
+ .. code-block:: javascript
427
+
428
+ //writing 3 registers on channel device1, unitId 255 define device itself.
429
+ //If device is a modbus gateway then unitId define the modbus address for desire station.
430
+ //register 99 startint at 0.
431
+
432
+ let vals = Buffer.alloc(6);
433
+ let tempRegister = Buffer.alloc(2);
434
+ tempRegister.writeUInt16BE(245);
435
+ nodbusTcpClient.setWordToBuffer(tempRegister, vals, 0);
436
+ tempRegister.writeUInt16BE(8965);
437
+ nodbusTcpClient.setWordToBuffer(tempRegister, vals, 1);
438
+ tempRegister.writeUInt16BE(1045);
439
+ nodbusTcpClient.setWordToBuffer(tempRegister, vals, 2);
440
+ successStatus = nodbusTcpClient.presetMultipleRegisters(vals, 'device1', 255, 99);
441
+
442
+
443
+
444
+ Method: nodbusTcpClient.readCoils(channelId, unitId, startCoil, coilsCuantity)
445
+ ------------------------------------------------------------------------------
446
+
447
+ * **channelId** <string>: Channels's name.
448
+ * **unitId** <number>: Legacy modbus address for being using for a gateway. Modbus spec recomend using 255.
449
+ * **startCoil** <number>: Starting coil to read at 0 address.
450
+ * **coilsCuantity** <number>: Number of coils to read.
451
+ * **Returns** <boolean>: true if success
452
+
453
+ This functions create the read coil (function 01) request and sended to server.
454
+
455
+ .. code-block:: javascript
456
+
457
+ //Reading coil on channel device1, unitId 255 define device itself.
458
+ //If device is a modbus gateway then unitId define the modbus address for desire station.
459
+ //coils 10 startint at 0.
460
+ //Read 14 coils
461
+ successStatus = nodbusTcpClient.readCoils('device1', 255, 10, 14);
462
+
463
+
464
+ Method: nodbusTcpClient.readHoldingRegisters(channelId, unitId, startRegister, registersCuantity)
465
+ --------------------------------------------------------------------------------------------------
466
+
467
+ * **channelId** <string>: Channels's name.
468
+ * **unitId** <number>: Legacy modbus address for being using for a gateway. Modbus spec recomend using 255.
469
+ * **startRegister** <number>: Starting input to read at 0 address.
470
+ * **registerCuantity** <number>: Number of registers to read.
471
+ * **Returns** <boolean>: true if success
472
+
473
+ This functions create the read holding register (function 03) request and sended to server.
474
+
475
+ .. code-block:: javascript
476
+
477
+ //Reading input on channel device1, unitId 255 define device itself.
478
+ //If device is a modbus gateway then unitId define the modbus address for desire station.
479
+ //register 10 .
480
+ //Read 4 register
481
+ successStatus = nodbusTcpClient.readHoldingRegisters('device1', 255, 10, 4);
482
+
483
+
484
+
485
+ Method: nodbusTcpClient.readInputs(channelId, unitId, startInput, inputsCuantity)
486
+ ---------------------------------------------------------------------------------
487
+
488
+ * **channelId** <string>: Channels's name.
489
+ * **unitId** <number>: Legacy modbus address for being using for a gateway. Modbus spec recomend using 255.
490
+ * **startInput** <number>: Starting input to read at 0 address.
491
+ * **inputsCuantity** <number>: Number of inputs to read.
492
+ * **Returns** <boolean>: true if success
493
+
494
+ This functions create the read inputs (function 02) request and sended to server.
495
+
496
+ .. code-block:: javascript
497
+
498
+ //Reading input on channel device1, unitId 255 define device itself.
499
+ //If device is a modbus gateway then unitId define the modbus address for desire station.
500
+ //input 0 .
501
+ //Read 6 inputs
502
+ successStatus = nodbusTcpClient.readInputs('device1', 255, 0, 6);
503
+
504
+
505
+ Method: nodbusTcpClient.readInputRegisters(channelId, unitId, startRegister, registersCuantity)
506
+ --------------------------------------------------------------------------------------------------
507
+
508
+ * **channelId** <string>: Channels's name.
509
+ * **unitId** <number>: Legacy modbus address for being using for a gateway. Modbus spec recomend using 255.
510
+ * **startRegister** <number>: Starting input to read at 0 address.
511
+ * **registerCuantity** <number>: Number of inputs to read.
512
+ * **Returns** <boolean>: true if success
513
+
514
+ This functions create the read input register (function 04) request and sended to server.
515
+
516
+ .. code-block:: javascript
517
+
518
+ //Reading input on channel device1, unitId 255 define device itself.
519
+ //If device is a modbus gateway then unitId define the modbus address for desire station.
520
+ //register 10 .
521
+ //Read 4 register
522
+ successStatus = nodbusTcpClient.readInputRegisters('device1', 255, 10, 4);
523
+
524
+
525
+
526
+ Method: nodbusTcpClient.readWriteMultiplesRegisters(values, channelId, unitId, readStartingRegister, readRegisterCuantity, writeStartingRegister)
527
+ -----------------------------------------------------------------------------------------------------------------------------------------------------
528
+
529
+ * **values** <Buffer> a two Bytes length buffer.
530
+ * **channelId** <string>: Channels's name.
531
+ * **unitId** <number>: Legacy modbus address for being using for a gateway. Modbus spec recomend using 255.
532
+ * **readStartingRegister** <number>: Starting input to read at 0 address.
533
+ * **readRegisterCuantity** <number>: Number of registers to read.
534
+ * **writeStartingRegister** <number>: Register to write at 0 address.
535
+ * **Returns** <boolean>: true if success
536
+
537
+ This functions create the read and write holding registers (function 23) request and sended to server.
538
+
539
+ .. code-block:: javascript
540
+
541
+ //writing 3 registers on channel device1, unitId 255 define device itself and reading five registers from register 10
542
+ //If device is a modbus gateway then unitId define the modbus address for desire station.
543
+ //register 99 startint at 0.
544
+
545
+ let vals = Buffer.alloc(6);
546
+ let tempRegister = Buffer.alloc(2);
547
+ tempRegister.writeUInt16BE(245);
548
+ nodbusTcpClient.setWordToBuffer(tempRegister, vals, 0);
549
+ tempRegister.writeUInt16BE(8965);
550
+ nodbusTcpClient.setWordToBuffer(tempRegister, vals, 1);
551
+ tempRegister.writeUInt16BE(1045);
552
+ nodbusTcpClient.setWordToBuffer(tempRegister, vals, 2);
553
+ successStatus = nodbusTcpClient.readWriteMultiplesRegisters(vals, 'device1', 255, 10, 5, 99);
554
+
555
+
556
+ Method: modbusClient.getWordFromBuffer(targetBuffer, [offset])
557
+ --------------------------------------------------------------
558
+
559
+ * **targetBuffer** <Buffer>: Buffer with the objetive 16 bits register to read.
560
+ * **offset** <number>: A number with register's offset inside the buffer.
561
+ * **Return** <Buffer>: A two bytes length buffer.
562
+
563
+ 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
564
+
565
+
566
+ Method: modbusClient.setWordToBuffer(value, targetBuffer, [offset])
567
+ -------------------------------------------------------------------
568
+
569
+ * **value** <Buffer>: two bytes length buffer.
570
+ * **targetBuffer** <Buffer>: Buffer with the objetive 16 bits register to write.
571
+ * **offset** <number>: A number with register's offset inside the buffer.
572
+
573
+ This method write a 16 bits register inside a buffer. The offset is 16 bits aligned.
package/docs/conf.py ADDED
@@ -0,0 +1,41 @@
1
+ # Configuration file for the Sphinx documentation builder.
2
+ #
3
+ # For the full list of built-in configuration values, see the documentation:
4
+ # https://www.sphinx-doc.org/en/master/usage/configuration.html
5
+
6
+ import os
7
+ import sys
8
+
9
+ # -- Project information -----------------------------------------------------
10
+ # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
11
+
12
+ project = 'Nodbus-Plus'
13
+ copyright = '2023, Hector E. Socarras'
14
+ author = 'Hector E. Socarras'
15
+ release = '1.0.0'
16
+
17
+ # -- General configuration ---------------------------------------------------
18
+ # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
19
+
20
+ extensions = ['sphinx.ext.autosectionlabel']
21
+
22
+ templates_path = ['_templates']
23
+
24
+ exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
25
+
26
+
27
+
28
+ # -- Options for HTML output -------------------------------------------------
29
+ # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
30
+
31
+ # on_rtd is whether we are on readthedocs.org
32
+ #on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
33
+
34
+ #if not on_rtd: # only import and set the theme if we're building docs locally
35
+ #import sphinx_rtd_theme
36
+
37
+
38
+
39
+ #import sphinx_rtd_theme
40
+ html_theme = "sphinx_rtd_theme"
41
+ html_static_path = ['static']
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
package/docs/index.rst ADDED
@@ -0,0 +1,30 @@
1
+ .. Nodbus-Plus documentation master file, created by
2
+ sphinx-quickstart on Sat Apr 29 11:08:38 2023.
3
+ You can adapt this file completely to your liking, but it should at least
4
+ contain the root `toctree` directive.
5
+
6
+ =======================================
7
+ Welcome to Nodbus-Plus's documentation!
8
+ =======================================
9
+
10
+ Nodbus-plus is a library written entirely in JavaScript for creating Modbus clients and servers applications.
11
+
12
+ It supports both Modbus TCP and Modbus Serial, as well as different transport protocols such as TCP, UDP and serial line communication.
13
+
14
+ .. toctree::
15
+ :maxdepth: 2
16
+ :caption: Contents:
17
+
18
+ starting
19
+ protocol/modbus_master.rst
20
+ protocol/modbus_master_serial.rst
21
+ protocol/modbus_master_tcp.rst
22
+ protocol/modbus_server.rst
23
+ protocol/modbus_server_serial.rst
24
+ protocol/modbus_server_tcp.rst
25
+ server/nodbus_tcp_server.rst
26
+ server/nodbus_serial_server.rst
27
+ client/nodbus_master_tcp.rst
28
+ client/nodbus_master_serial.rst
29
+
30
+ The source code is available on `Github <https://github.com/hsocarras/nodbus-plus>`_ under MIT License.