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,577 @@
1
+ /**
2
+ ** Modbus Serial over Tcp Client module.
3
+ * @module client/nodbus_serial_client
4
+ * @author Hector E. Socarras.
5
+ * @version 1.0.0
6
+ */
7
+
8
+ const ModbusSerialMaster = require('../protocol/modbus_master_serial');
9
+ const TcpChannel = require('./net/tcpchannel');
10
+ const UdpChannel = require('./net/udpchannel');
11
+ const SerialChannel = require('./net/serialchannel')
12
+
13
+ /**
14
+ * Class representing a modbus serial client ready to use.
15
+ * @extends ModbusSerialMaster
16
+ */
17
+ class NodbusSerialClient extends ModbusSerialMaster {
18
+
19
+ constructor(){
20
+ super();
21
+
22
+ var self = this;
23
+
24
+ /**
25
+ * channel's constructor
26
+ * @type {object}
27
+ */
28
+ this.channelType = new Map();
29
+ this.channelType.set('tcp1', TcpChannel);
30
+ this.channelType.set('udp1', UdpChannel);
31
+ this.channelType.set('serial1', SerialChannel);
32
+
33
+ this.channels = new Map();
34
+
35
+
36
+ }
37
+
38
+ get isIdle(){
39
+ if (this.activeRequest == null){
40
+ return true
41
+ }
42
+ else return false
43
+ }
44
+
45
+ /**
46
+ * Function to add a channel object to master
47
+ * @param {string} id: channel's id. Unique por channel
48
+ * @param {string} ip: channel's ip address. Default 'localhost'
49
+ * @param {number} port: channel's port. Default 502
50
+ * @param {number} timeout time in miliseconds to emit timeout for a request.
51
+ */
52
+ addChannel(id, type = 'tcp1', channelCfg = {ip: 'localhost', port: 502, timeout:250}){
53
+
54
+ if(channelCfg.ip == undefined){ channelCfg.ip = 'localhost'}
55
+ if(channelCfg.port == undefined){ channelCfg.port = 502}
56
+ if(channelCfg.timeout == undefined){ channelCfg.timeout = 250}
57
+ channelCfg.tcpCoalescingDetection = false;
58
+
59
+ let Channel = this.channelType.get(type);
60
+ if (Channel == undefined){
61
+ Channel = TcpChannel;
62
+ }
63
+
64
+ let channel = new Channel(channelCfg);
65
+
66
+ /**
67
+ * Emit connect and ready events
68
+ * @param {object} target Socket object
69
+ * @fires ModbusTCPClient#connect {object}
70
+ * @fires ModbusTCPClient#ready
71
+ */
72
+ channel.onConnectHook = () => {
73
+ /**
74
+ * connection event.
75
+ * Emited when new connecton is sablished
76
+ * @event NodbusTcpClient#connection
77
+ * @type {object}
78
+ * @see https://nodejs.org/api/net.html
79
+ */
80
+ this.emit('connection', id);
81
+ };
82
+
83
+ channel.onCloseHook = () => {
84
+ /**
85
+ * connection-closed event.
86
+ * @event ModbusnetServer#connection-closed
87
+ * @type {object}
88
+ */
89
+ this.emit('connection-closed', id)
90
+ };
91
+
92
+ channel.onDataHook = (dataFrame) => {
93
+ /**
94
+ * indication event.
95
+ * @event ModbusnetServer#indication
96
+ */
97
+ this.emit('data', id, dataFrame);
98
+ };
99
+
100
+ channel.onMbAduHook = (resAdu) => {
101
+
102
+ let res = {};
103
+
104
+ res.timeStamp = Date.now();
105
+ if(this._asciiRequest) {
106
+ let rtuResAdu = this.aduAsciiToRtu(resAdu);
107
+ let len = rtuResAdu.length;
108
+ res.unitId = rtuResAdu[0];
109
+ res.functionCode = rtuResAdu[1];
110
+ res.data = rtuResAdu.subarray(2, len-2);
111
+ }
112
+ else{
113
+ let len = resAdu.length;
114
+ res.unitId = resAdu[0];
115
+ res.functionCode = resAdu[1];
116
+ res.data = resAdu.subarray(2, len-2);
117
+ }
118
+
119
+ this.processResAdu(resAdu, this._asciiRequest);
120
+
121
+ this.emit('response', id, res)
122
+
123
+ }
124
+
125
+ channel.onErrorHook = (err) =>{
126
+ /**
127
+ * error event.
128
+ * @event ModbusNetServer#error
129
+ */
130
+ this.emit('error', id, err);
131
+ };
132
+
133
+ channel.onWriteHook = (reqAdu) => {
134
+
135
+ let req = {};
136
+
137
+ req.timeStamp = Date.now();
138
+ if(this._asciiRequest){
139
+ let rtuReqAdu = this.aduAsciiToRtu(reqAdu);
140
+ let len = rtuReqAdu.length;
141
+ req.unitId = rtuReqAdu[0];
142
+ req.functionCode = rtuReqAdu[1];
143
+ req.data = rtuReqAdu.subarray(2, len-2);
144
+ }
145
+ else{
146
+ let len = reqAdu.length;
147
+ req.unitId = reqAdu[0];
148
+ req.functionCode = reqAdu[1];
149
+ req.data = reqAdu.subarray(2, len-2);
150
+ }
151
+
152
+ if(req.unitId == 0){
153
+ this.setTurnAroundDelay(channelCfg.timeout); //start the timer for timeout event
154
+ }
155
+ else{
156
+ this.setReqTimer(channelCfg.timeout); //start the timer for timeout event
157
+ }
158
+ this.emit('request', id, req);
159
+
160
+ /**
161
+ * response event.
162
+ * @event ModbusnetServer#response
163
+ */
164
+ this.emit('write', id, reqAdu);
165
+
166
+ };
167
+
168
+ channel.validateFrame = (frame)=>{
169
+ if(frame.length > 3){
170
+
171
+ return true
172
+ }
173
+ return false;
174
+ }
175
+
176
+ this.channels.set(id, channel);
177
+
178
+ }
179
+
180
+ /**
181
+ * Function to delete a channel from the list
182
+ * @param {string} id
183
+ */
184
+ delChannel(id){
185
+
186
+ if(this.channels.has(id)){
187
+ this.channels.delete(id);
188
+ }
189
+ }
190
+
191
+ isChannelReady(id){
192
+
193
+ if(this.channels.has(id)){
194
+ let channel = this.channels.get(id);
195
+ return channel.isConnected();
196
+ }
197
+ else return false;
198
+ }
199
+
200
+ /**
201
+ *Stablish connection
202
+ */
203
+ connect(id){
204
+
205
+ let self = this;
206
+ let successPromise;
207
+ let channel = self.channels.get(id);
208
+
209
+ if(channel == undefined){
210
+ return Promise.reject(channel.ip, channel.port);
211
+ }
212
+ else if(channel.isConnected()){
213
+
214
+ return Promise.resolve(id);
215
+ }
216
+ else{
217
+ successPromise = channel.connect();
218
+ return successPromise
219
+ }
220
+
221
+ }
222
+
223
+ /**
224
+ *disconnect from server
225
+ */
226
+ disconnect(id){
227
+
228
+ let self = this;
229
+ let successPromise;
230
+ let channel = self.channels.get(id)
231
+
232
+ if(channel == undefined){
233
+ return Promise.resolve(id);
234
+
235
+ }
236
+ else if(channel.isConnected()){
237
+ successPromise = channel.disconnect();
238
+ return successPromise;
239
+ }
240
+ else{
241
+ return Promise.resolve(id);
242
+
243
+ }
244
+ }
245
+
246
+ /**
247
+ * Function to send read coils status request to a modbus server.
248
+ * @param {string} channelId Identifier use as key on channels dictionary.
249
+ * @param {number} unitId Modbus address. A value between 1 -255
250
+ * @param {number} startCoil Starting coils at 0 address
251
+ * @param {number} coilsCuantity
252
+ * @param {boolean} asciiMode A flag that indicate the request is build in ascii format. Default false.
253
+ * @returns {Boolean} true if succses otherwise false
254
+ */
255
+ readCoils(channelId, unitId, startCoil, coilsCuantity, asciiMode = false){
256
+ let self = this;
257
+ //check if channel is connected
258
+ if(this.isChannelReady(channelId)){
259
+
260
+ let channel = this.channels.get(channelId);
261
+ let pdu = this.readCoilStatusPdu(startCoil, coilsCuantity);
262
+ let reqAdu = this.makeRequest(unitId, pdu, asciiMode);
263
+
264
+ if(self.storeRequest(reqAdu, asciiMode)){
265
+
266
+ return channel.write(reqAdu);
267
+
268
+ }
269
+ else{
270
+ return false
271
+ }
272
+ }
273
+ else{
274
+ return false
275
+ }
276
+
277
+ }
278
+
279
+ /**
280
+ * Function to send read inputs status request to a modbus server.
281
+ * @param {string} channelId Identifier use as key on channels dictionary.
282
+ * @param {number} unitId Modbus address. A value between 1 -255
283
+ * @param {number} startInput Starting inputs at 0 address
284
+ * @param {number} inputsCuantity
285
+ * @param {boolean} asciiMode A flag that indicate the request is build in ascii format. Default false.
286
+ * @returns {Boolean} true if succses otherwise false
287
+ */
288
+ readInputs(channelId, unitId, startInput, inputsCuantity, asciiMode = false){
289
+ let self = this;
290
+ //check if channel is connected
291
+ if(this.isChannelReady(channelId)){
292
+
293
+ let channel = this.channels.get(channelId);
294
+ let pdu = this.readInputStatusPdu(startInput, inputsCuantity);
295
+ let reqAdu = this.makeRequest(unitId, pdu, asciiMode);
296
+
297
+ if(self.storeRequest(reqAdu, asciiMode)){
298
+
299
+ return channel.write(reqAdu);
300
+
301
+ }
302
+ else{
303
+ return false
304
+ }
305
+ }
306
+ else{
307
+ return false
308
+ }
309
+ }
310
+
311
+ /**
312
+ * Function to send read holding registers request to a modbus server.
313
+ * @param {string} channelId Identifier use as key on channels dictionary.
314
+ * @param {number} unitId Modbus address. A value between 1 -255
315
+ * @param {number} startRegister Starting coils at 0 address
316
+ * @param {number} registersCuantity
317
+ * @param {boolean} asciiMode A flag that indicate the request is build in ascii format. Default false.
318
+ * @returns {Boolean} true if succses otherwise false
319
+ */
320
+ readHoldingRegisters(channelId, unitId, startRegister, registersCuantity, asciiMode = false){
321
+ let self = this;
322
+ //check if channel is connected
323
+ if(this.isChannelReady(channelId)){
324
+
325
+ let channel = this.channels.get(channelId);
326
+ let pdu = this.readHoldingRegistersPdu(startRegister, registersCuantity);
327
+ let reqAdu = this.makeRequest(unitId, pdu, asciiMode);
328
+
329
+ if(self.storeRequest(reqAdu, asciiMode)){
330
+
331
+ return channel.write(reqAdu);
332
+
333
+ }
334
+ else{
335
+ return false
336
+ }
337
+ }
338
+ else{
339
+ return false
340
+ }
341
+ }
342
+
343
+ /**
344
+ * Function to send read inputs registers request to a modbus server.
345
+ * @param {string} channelId Identifier use as key on channels dictionary.
346
+ * @param {number} unitId Modbus address. A value between 1 -255
347
+ * @param {number} startRegister Starting register at 0 address
348
+ * @param {number} registersCuantity
349
+ * @param {boolean} asciiMode A flag that indicate the request is build in ascii format. Default false.
350
+ * @returns {Boolean} true if succses otherwise false
351
+ */
352
+ readInputRegisters(channelId, unitId, startRegister, registersCuantity, asciiMode = false){
353
+ let self = this;
354
+ //check if channel is connected
355
+ if(this.isChannelReady(channelId)){
356
+
357
+ let channel = this.channels.get(channelId);
358
+ let pdu = this.readInputRegistersPdu(startRegister, registersCuantity);
359
+ let reqAdu = this.makeRequest(unitId, pdu, asciiMode);
360
+
361
+ if(self.storeRequest(reqAdu, asciiMode)){
362
+
363
+ return channel.write(reqAdu);
364
+
365
+ }
366
+ else{
367
+ return false
368
+ }
369
+ }
370
+ else{
371
+ return false
372
+ }
373
+ }
374
+
375
+ /**
376
+ * Function to send forse single coil request to a modbus server.
377
+ * @param {boolean} value to force.
378
+ * @param {string} channelId Identifier use as key on channels dictionary.
379
+ * @param {number} unitId Modbus address. A value between 1 -255
380
+ * @param {number} startCoil Starting coils at 0 address
381
+ * @param {boolean} asciiMode A flag that indicate the request is build in ascii format. Default false.
382
+ * @returns {Boolean} true if succses otherwise false
383
+ */
384
+ forceSingleCoil(value, channelId, unitId, startCoil, asciiMode = false){
385
+ let self = this;
386
+ //check if channel is connected
387
+ if(this.isChannelReady(channelId)){
388
+
389
+ let channel = this.channels.get(channelId);
390
+ let bufValue = this.boolToBuffer(value);
391
+ let pdu = this.forceSingleCoilPdu(bufValue, startCoil);
392
+ let reqAdu = this.makeRequest(unitId, pdu, asciiMode);
393
+
394
+ if(self.storeRequest(reqAdu, asciiMode)){
395
+
396
+ return channel.write(reqAdu);
397
+
398
+ }
399
+ else{
400
+ return false
401
+ }
402
+ }
403
+ else{
404
+ return false
405
+ }
406
+ }
407
+
408
+ /**
409
+ * Function to send preset single register request to a modbus server.
410
+ * @param {Buffer} value Two bytes length buffer.
411
+ * @param {string} channelId Identifier use as key on channels dictionary.
412
+ * @param {number} unitId Modbus address. A value between 1 -255
413
+ * @param {number} startRegister Starting coils at 0 address
414
+ * @param {boolean} asciiMode A flag that indicate the request is build in ascii format. Default false.
415
+ * @returns {Boolean} true if succses otherwise false
416
+ */
417
+ presetSingleRegister(value, channelId, unitId, startRegister, asciiMode = false){
418
+ let self = this;
419
+ //check if channel is connected
420
+ if(this.isChannelReady(channelId)){
421
+
422
+ let channel = this.channels.get(channelId);
423
+ let pdu = this.presetSingleRegisterPdu(value, startRegister);
424
+ let reqAdu = this.makeRequest(unitId, pdu, asciiMode);
425
+
426
+ if(self.storeRequest(reqAdu, asciiMode)){
427
+
428
+ return channel.write(reqAdu);
429
+
430
+ }
431
+ else{
432
+ return false
433
+ }
434
+ }
435
+ else{
436
+ return false
437
+ }
438
+ }
439
+
440
+ /**
441
+ * Function to send force multiples coils request to a modbus server.
442
+ * @param {Array} values a boolean array with values to force. arrays index 0 correspond to start coil. Arrays length correspond to numbers of coils to force.
443
+ * @param {string} channelId Identifier use as key on channels dictionary.
444
+ * @param {number} unitId Modbus address. A value between 1 -255
445
+ * @param {number} startCoil Starting coils at 0 address
446
+ * @param {boolean} asciiMode A flag that indicate the request is build in ascii format. Default false.
447
+ * @returns {Boolean} true if succses otherwise false
448
+ */
449
+ forceMultipleCoils(values, channelId, unitId, startCoil, asciiMode = false){
450
+ let self = this;
451
+ //check if channel is connected
452
+ if(this.isChannelReady(channelId)){
453
+
454
+ let channel = this.channels.get(channelId);
455
+ let bufValues = this.boolsToBuffer(values);
456
+ let pdu = this.forceMultipleCoilsPdu(bufValues, startCoil, values.length);
457
+ let reqAdu = this.makeRequest(unitId, pdu, asciiMode);
458
+
459
+ if(self.storeRequest(reqAdu, asciiMode)){
460
+
461
+ return channel.write(reqAdu);
462
+
463
+ }
464
+ else{
465
+ return false
466
+ }
467
+ }
468
+ else{
469
+ return false
470
+ }
471
+ }
472
+
473
+ /**
474
+ * Function to send preset multiples registers request to a modbus server.
475
+ * @param {Buffer} values an buffer with values to force. arrays index 0 correspond to start register.
476
+ * @param {string} channelId Identifier use as key on channels dictionary.
477
+ * @param {number} unitId Modbus address. A value between 1-255
478
+ * @param {number} startRegister Starting register at 0 address.
479
+ * @param {boolean} asciiMode A flag that indicate the request is build in ascii format. Default false.
480
+ * @returns {Boolean} true if succses otherwise false
481
+ */
482
+ presetMultiplesRegisters(values, channelId, unitId, startRegister, asciiMode = false){
483
+ let self = this;
484
+ //check if channel is connected
485
+ if(this.isChannelReady(channelId)){
486
+
487
+ let channel = this.channels.get(channelId);
488
+ let pdu = this.presetMultipleRegistersPdu(values, startRegister, Math.floor(values.length/2));
489
+ let reqAdu = this.makeRequest(unitId, pdu, asciiMode);
490
+
491
+ if(self.storeRequest(reqAdu, asciiMode)){
492
+
493
+ return channel.write(reqAdu);
494
+
495
+ }
496
+ else{
497
+ return false
498
+ }
499
+ }
500
+ else{
501
+ return false
502
+ }
503
+ }
504
+
505
+ /**
506
+ * Function to send preset multiples registers request to a modbus server.
507
+ * @param {Array} values an 16 number length array with values to force. Index 0 is de less significant bit.
508
+ * A value off 1 force to 1 the corresponding bit, 0 force to 0, other values don't change the bit value.
509
+ * @param {string} channelId Identifier use as key on channels dictionary.
510
+ * @param {number} unitId Modbus address. A value between 1-255
511
+ * @param {number} startRegister Starting register at 0 address.
512
+ * @param {boolean} asciiMode A flag that indicate the request is build in ascii format. Default false.
513
+ * @returns true if succses otherwise false
514
+ */
515
+ maskHoldingRegister(values, channelId, unitId, startRegister, asciiMode = false){
516
+ let self = this;
517
+ //check if channel is connected
518
+ if(this.isChannelReady(channelId)){
519
+
520
+ let channel = this.channels.get(channelId);
521
+ let bufValues = this.getMaskRegisterBuffer(values);
522
+ let pdu = this.maskHoldingRegisterPdu(bufValues, startRegister, Math.floor(values.length));
523
+ let reqAdu = this.makeRequest(unitId, pdu, asciiMode);
524
+
525
+ if(self.storeRequest(reqAdu, asciiMode)){
526
+
527
+ return channel.write(reqAdu);
528
+
529
+ }
530
+ else{
531
+ return false
532
+ }
533
+ }
534
+ else{
535
+ return false
536
+ }
537
+ }
538
+
539
+ /**
540
+ * Function to send preset multiples registers request to a modbus server.
541
+ * @param {Buffer} values a buffer with values to writes. arrays index 0 correspond to start register.
542
+ * @param {string} channelId Identifier use as key on channels dictionary.
543
+ * @param {number} unitId Modbus address. A value between 1-255
544
+ * @param {number} readStartingRegister Starting register at 0 address.
545
+ * @param {number} readRegisterCuantity Number of register to read
546
+ * @param {number} writeStartingRegister Starting register at 0 address to write.
547
+ * @param {boolean} asciiMode A flag that indicate the request is build in ascii format. Default false.
548
+ * @returns true if succses otherwise false
549
+ */
550
+ readWriteMultiplesRegisters(values, channelId, unitId, readStartingRegister, readRegisterCuantity, writeStartingRegister, asciiMode = false){
551
+ let self = this;
552
+ //check if channel is connected
553
+ if(this.isChannelReady(channelId)){
554
+
555
+ let channel = this.channels.get(channelId);
556
+ let pdu = this.readWriteMultipleRegistersPdu(values, readStartingRegister, readRegisterCuantity, writeStartingRegister, Math.floor(values.length/2));
557
+ let reqAdu = this.makeRequest(unitId, pdu, asciiMode);
558
+
559
+ if(self.storeRequest(reqAdu, asciiMode)){
560
+
561
+ return channel.write(reqAdu);
562
+
563
+ }
564
+ else{
565
+ return false
566
+ }
567
+ }
568
+ else{
569
+ return false
570
+ }
571
+ }
572
+
573
+ }
574
+
575
+
576
+
577
+ module.exports = NodbusSerialClient;