-
Notifications
You must be signed in to change notification settings - Fork 3
/
bp-modbus-client.html
425 lines (385 loc) · 17.9 KB
/
bp-modbus-client.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
<!--bufferCommands
Copyright (c) 2016,2017,2018,2019,2020,2021 Klaus Landsdorf (https://bianco-royal.space/)
Copyright 2016 - Jason D. Harper, Argonne National Laboratory
Copyright 2015,2016 - Mika Karaila, Valmet Automation Inc.
All rights reserved.
node-red-contrib-modbus
@author <a href="mailto:[email protected]">Klaus Landsdorf</a> (Bianco Royal)
-->
<script type="text/javascript">
RED.nodes.registerType('bp-modbus-client', {
category: 'config',
defaults: {
name: {value: ''},
clienttype: {value: 'tcp', required: true},
bufferCommands: {value: true},
stateLogEnabled: {value: false},
queueLogEnabled: {value: false},
tcpHost: {value: '127.0.0.1', required: true},
tcpPort: {value: 502, required: true, validate: RED.validators.number()},
tcpType: {value: 'DEFAULT', required: true},
serialPort: {value: '/dev/ttyUSB', required: true},
serialType: {value: 'RTU-BUFFERD', required: true},
serialBaudrate: {value: 9600, required: true, validate: RED.validators.number()},
serialDatabits: {value: 8, required: true, validate: RED.validators.number()},
serialStopbits: {value: 1, required: true, validate: RED.validators.number()},
serialParity: {value: 'none', required: true},
serialConnectionDelay: {value: 100},
serialAsciiResponseStartDelimiter: {value: '0x3A'},
unit_id: {value: 1},
commandDelay: {value: 1},
clientTimeout: {value: 1000},
reconnectOnTimeout: {value: true},
reconnectTimeout: {value: 2000},
parallelUnitIdsAllowed: {value: true},
bpChkShowDebugWarnings: {value: false}
},
color: "#00aeef",
icon: "bitpool.svg",
label: function () {
let node = this
if (node.clienttype == 'tcp') {
return node.name || 'modbus-tcp@' + node.tcpHost + ':' + node.tcpPort
} else {
return node.name || 'modbus-serial@' + node.serialPort + ':' + node.serialBaudrate
}
},
oneditprepare: function () {
let previous = null
let node = this
node.ports = []
let clientTypeSelector = $('#node-config-input-clienttype')
let serialTypeSelector = $('#node-config-input-serialType')
let inputsSerial = $('#node-inputs-modbus-serial')
let inputsSerialExtras = $('#node-inputs-modbus-serial-extras')
let inputsAsciiExtras = $('#node-inputs-ascii-extras')
let inputsTCP = $('#node-inputs-modbus-tcp')
clientTypeSelector.on('focus', function () {
previous = this.value
}).change(function () {
if (previous == null) {
previous = $('#node-config-input-clienttype').val()
}
if (node.unit_id) {
node.unit_id = parseInt(node.unit_id)
}
if (node.commandDelay) {
node.commandDelay = parseInt(node.commandDelay)
}
if (node.clientTimeout) {
node.clientTimeout = parseInt(node.clientTimeout)
}
if (node.reconnectTimeout) {
node.reconnectTimeout = parseInt(node.reconnectTimeout)
}
switch (clientTypeSelector.val()) {
case 'tcp':
inputsSerialExtras.hide()
inputsSerial.hide()
inputsTCP.show()
if (node.tcpHost) {
node.tcpHost.required = true
node.tcpPort.required = true
if (node.tcpType) {
node.tcpType.required = true
}
}
if (node.serialPort) {
node.serialPort.required = false
if (node.serialType) {
node.serialType.required = false
}
node.serialBaudrate.required = false
}
if (node.serialDatabits) {
node.serialDatabits.required = false
node.serialStopbits.required = false
node.serialParity.required = false
}
break
case 'serial':
case 'simpleser':
if (clientTypeSelector.val() === 'simpleser') {
inputsSerialExtras.hide()
node.serialDatabits.value = 8
node.serialStopbits.value = 1
node.serialParity.value = 'none'
} else {
inputsSerialExtras.show()
}
inputsSerial.show()
inputsTCP.hide()
if (node.tcpHost) {
node.tcpHost.required = false
node.tcpPort.required = false
if (node.tcpType) {
node.tcpType.required = false
}
}
if (node.serialPort) {
node.serialPort.required = true
if (node.serialType) {
node.serialType.required = true
}
node.serialBaudrate.required = true
}
if (node.serialDatabits) {
node.serialDatabits.required = true
node.serialStopbits.required = true
node.serialParity.required = true
}
break
default:
break
}
})
serialTypeSelector.on('focus').change(function () {
if (serialTypeSelector.val() === 'ASCII') {
inputsAsciiExtras.show()
if (node.serialAsciiResponseStartDelimiter) {
node.serialAsciiResponseStartDelimiter = node.serialAsciiResponseStartDelimiter
}
} else {
inputsAsciiExtras.hide()
}
})
try {
$('#node-config-input-serialPort').autocomplete('destroy')
}
catch (err) {
}
$('#node-config-lookup-serial').click(function () {
$('#node-config-lookup-serial').addClass('disabled')
$.getJSON('/modbus/serial/ports', function (data) {
$('#node-config-lookup-serial').removeClass('disabled')
node.ports = []
$.each(data, function (i, port) {
node.ports.push(port.path)
})
$('#node-config-input-serialPort').autocomplete({
source: node.ports,
minLength: 0,
close: function (event, ui) {
$('#node-config-input-serialPort').autocomplete('destroy')
}
}).autocomplete('search', '')
})
})
}
})
</script>
<script type="text/html" data-template-name="bp-modbus-client">
<div class="form-row">
<label for="node-config-input-name"><i class="icon-tag"></i> <span data-i18n="node-red:common.label.name"></span></label>
<input type="text" id="node-config-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-config-input-clienttype"><i class="icon-bookmark"></i> <span data-i18n="modbus-contrib.label.type"></span></label>
<select type="text" id="node-config-input-clienttype" style="width:140px;">
<option value="tcp" select>TCP</option>
<option value="simpleser">Serial</option>
<option value="serial">Serial Expert</option>
</select>
</div>
<hr>
<div id="node-inputs-modbus-tcp">
<div class="form-row">
<label for="node-config-input-tcpHost"><i class="icon-bookmark"></i> <span data-i18n="modbus-contrib.label.host"></span></label>
<input type="text" id="node-config-input-tcpHost">
</div>
<div class="form-row">
<label for="node-config-input-tcpPort"><i class="icon-bookmark"></i> <span data-i18n="modbus-contrib.label.port"></span></label>
<input type="text" id="node-config-input-tcpPort" placeholder="502">
</div>
<div class="form-row">
<label for="node-config-input-tcpType"><i class="icon-bookmark"></i> <span data-i18n="modbus-contrib.label.tcpType"></span></label>
<select type="text" id="node-config-input-tcpType" style="width:140px;">
<option value="DEFAULT" select>DEFAULT</option>
<option value="TCP-RTU-BUFFERED">RTU-BUFFERED</option>
<option value="TELNET">TELNET</option>
<option value="C701">C701</option>
</select>
</div>
</div>
<div id="node-inputs-modbus-serial">
<div class="form-row">
<label for="node-config-input-serialPort"><i class="fa fa-random"></i> <span data-i18n="modbus-contrib.label.serialport"></span></label>
<input type="text" id="node-config-input-serialPort" style="width:60%;" placeholder="/dev/ttyUSB or COM4">
<a id="node-config-lookup-serial" class="red-ui-button"><i id="node-config-lookup-serial-icon" class="fa fa-search"></i></a>
</div>
<div class="form-row">
<label for="node-config-input-serialType"><i class="icon-bookmark"></i> <span data-i18n="modbus-contrib.label.serialType"></span></label>
<select type="text" id="node-config-input-serialType" style="width:140px;">
<option value="RTU-BUFFERD" select>RTU-BUFFERD</option>
<option value="RTU">RTU</option>
<option value="ASCII">ASCII</option>
</select>
</div>
<div class="form-row">
<label for="node-config-input-serialBaudrate"><i class="icon-bookmark"></i> <span data-i18n="modbus-contrib.label.baudRate"></span></label>
<select id="node-config-input-serialBaudrate" style="max-width:140px">
<option value="115200">115200</option>
<option value="57600">57600</option>
<option value="38400">38400</option>
<option value="19200">19200</option>
<option value="9600">9600</option>
<option value="4800">4800</option>
<option value="2400">2400</option>
<option value="1200">1200</option>
<option value="300">300</option>
<option value="110">110</option>
<option value="75">75</option>
</select>
</div>
</div>
<div id="node-inputs-modbus-serial-extras">
<div class="form-row">
<label for="node-config-input-serialDatabits"><i class="icon-bookmark"></i> <span data-i18n="modbus-contrib.label.dataBits"></span></label>
<select id="node-config-input-serialDatabits" style="max-width:80px">
<option value="8">8</option>
<option value="7">7</option>
<option value="6">6</option>
<option value="5">5</option>
</select>
</div>
<div class="form-row">
<label for="node-config-input-serialStopbits"><i class="icon-bookmark"></i> <span data-i18n="modbus-contrib.label.stopBits"></span></label>
<select id="node-config-input-serialStopbits" style="max-width:80px">
<option value="1">1</option>
<option value="1.5">1.5</option>
<option value="2">2</option>
</select>
</div>
<div class="form-row">
<label for="node-config-input-serialParity"><i class="icon-bookmark"></i> <span data-i18n="modbus-contrib.label.parity"></span></label>
<select id="node-config-input-serialParity" style="max-width:80px">
<option value="none">None</option>
<option value="even">Even</option>
<option value="mark">Mark</option>
<option value="odd">Odd</option>
<option value="space">Space</option>
</select>
</div>
<div class="form-row">
<label for="node-config-input-serialConnectionDelay">
<i class="fa fa-random"></i>
<span data-i18n="modbus-contrib.label.serialconnectiondelay"></span>
</label>
<input type="text" id="node-config-input-serialConnectionDelay" style="max-width:80px" placeholder="500">
</div>
</div>
<div id="node-inputs-ascii-extras">
<div class="form-row">
<label for="node-config-input-serialAsciiResponseStartDelimiter"><i class="icon-bookmark"></i> <span data-i18n="modbus-contrib.label.serialAsciiResponseStartDelimiter"></span></label>
<input type="text" id="node-config-input-serialAsciiResponseStartDelimiter" style="max-width:80px" placeholder="0x3A (:)">
</div>
</div>
<hr>
<div class="form-row">
<label for="node-config-input-unit_id"><i class="icon-bookmark"></i> <span data-i18n="modbus-contrib.label.unitId"></span></label>
<input type="text" id="node-config-input-unit_id" style="max-width:80px">
</div>
<div class="form-row">
<label for="node-config-input-clientTimeout"><i class="icon-time"></i> <span data-i18n="modbus-contrib.label.timeout"></span></label>
<input type="text" id="node-config-input-clientTimeout" placeholder="1000" style="max-width:80px">
</div>
<!--
<div class="form-row">
<label style="min-width:160px" for="node-config-input-reconnectOnTimeout"><i class="fa fa-th"></i> <span
data-i18n="modbus-contrib.label.reconnectOnTimeout"></span></label>
<input type="checkbox" id="node-config-input-reconnectOnTimeout" style="max-width:30px">
</div> -->
<div class="form-row">
<label for="node-config-input-reconnectTimeout">
<i class="icon-time"></i>
<span data-i18n="modbus-contrib.label.reconnectTimeout"></span>
</label>
<input type="text" id="node-config-input-reconnectTimeout" placeholder="2000" style="max-width:80px">
</div>
<!--
<div class="form-row">
<label style="min-width:160px" for="node-config-input-parallelUnitIdsAllowed"><i class="fa fa-th"></i> <span
data-i18n="modbus-contrib.label.parallelUnitIdsAllowed"></span></label>
<input type="checkbox" id="node-config-input-parallelUnitIdsAllowed" style="max-width:30px">
</div>
<hr>
<div class="form-row">
<label style="min-width:160px" for="node-config-input-stateLogEnabled">
<i class="fa fa-th"></i>
<span data-i18n="modbus-contrib.label.stateLogEnabled"></span>
</label>
<input type="checkbox" id="node-config-input-stateLogEnabled" style="max-width:30px">
</div>
<div class="form-row">
<label style="min-width:160px" for="node-config-input-queueLogEnabled">
<i class="fa fa-th"></i>
<span data-i18n="modbus-contrib.label.queueLogEnabled"></span>
</label>
<input type="checkbox" id="node-config-input-queueLogEnabled" style="max-width:30px">
</div>
<div class="form-row">
<label style="min-width:160px" for="node-config-input-bufferCommands"><i class="fa fa-th"></i> <span
data-i18n="modbus-contrib.label.queueCommands"></span></label>
<input type="checkbox" id="node-config-input-bufferCommands" style="max-width:30px">
</div> -->
<div class="form-row">
<label for="node-config-input-commandDelay"><i class="icon-time"></i> <span
data-i18n="modbus-contrib.label.commandDelay"></span></label>
<input type="text" id="node-config-input-commandDelay" placeholder="1" style="max-width:80px">
</div>
<hr>
<div class="form-row" style="display: flex;">
<div class="form-check" style="width: 8%; display: grid; align-content: space-between;">
<input class="form-check-input" type="checkbox" value="" id="node-config-input-bpChkShowDebugWarnings" unchecked>
</div>
<label id="node-label-bpChkShowDebugWarnings" for="node-config-input-bpChkShowDebugWarnings" style="text-align:left; vertical-align:middle; width: 100%;">Show activity messages in debug tab</label>
</div>
</script>
<script type="text/html" data-help-name="bp-modbus-client">
<p><strong>
If you have many nodes on this communication (see configuration nodes),
think about multiple connections to your Modbus device, please!
Many devices are able to connecting multiple.
</strong></p>
<p>
Add a catch to your flow:
<pre>
[{"id":"cdd076d5.dab728","type":"catch","z":"b245d3e4.b52de","name":"","scope":null,"x":1020,"y":40,
"wires":[["8516d63d.1c29a8"]]},{"id":"8516d63d.1c29a8","type":"debug","z":"b245d3e4.b52de","name":"",
"active":true,"console":"false","complete":"true","x":1170,"y":40,"wires":[]}]
</pre>
</p>
<p>Uses ModbusRTU ('modbus-serial') to read/write by ethernet host:port or TTY register/coil/input addresses.</p>
<p>The Xstate machine ('Xstate/fsm') organizing the states to work with reconnects and a queue of commands.</p>
<p>
<h3>Basics</h3>
<ul>
<li>Type (TCP/Serial)</li>
<li>Queue commands (true/false) - with true it buffers incoming Modbus commands and send them with
delay</li>
<li>Queue Work Delay (default 0 ms) - ms interval to delay sending commands from queue (sumOfWaiting=requestsPerCycle*delay)</li>
<li>Unit-ID (default 1 [serial] or 0 [tcp]) - to set one Unit-ID for all nodes without Unit-ID.
Set the Unit-ID of the Read/Write/Getter node's to empty for using this ID</li>
<li>Timeout (default 1000 ms) - ms for the command timeout on ModbusRTU command</li>
<li>Reconnect timeout (default 2000 ms) - time to wait on reconnect before next sending</li>
<li>Reconnect on timeout - should the client do a reconnect or not on timeouts</li>
<li>Parallel UnitId's allowed - handle commands in parallel per UnitId or not</li>
</ul>
<h3>TCP</h3>
<ul>
<li>Host - IP address</li>
<li>Port (default 502)</li>
</ul>
<h3>Serial</h3>
<ul>
<li>Serial Port (/dev/tty.usbserial | COM[1..n])</li>
<li>Serial Baud rate</li>
<li>Serial Databits</li>
<li>Serial Stopbits</li>
<li>Serial Parity</li>
<li>Serial Type</li>
<li>Serial Connection delay (default 500 ms) - time to delay first command sending after reconnect</li>
<li>ASCII start delimiter (default 0x3A, colon) - Delemiter used to identify start of slave response</li>
</ul>
</p>
</script>