node-red-contrib-modbus-modpackqt 3.3.2 → 3.3.4
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.
- package/CHANGELOG.md +37 -0
- package/nodes/lib/probe-runtime.js +1 -1
- package/nodes/modpackqt-slave-read.html +37 -27
- package/nodes/modpackqt-slave-read.js +12 -18
- package/nodes/modpackqt-slave-server.html +153 -0
- package/nodes/modpackqt-slave-server.js +136 -0
- package/nodes/modpackqt-slave-write.html +40 -24
- package/nodes/modpackqt-slave-write.js +12 -17
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,43 @@ All notable changes to **node-red-contrib-modbus-modpackqt** are documented
|
|
|
4
4
|
here. This project follows [Semantic Versioning](https://semver.org/) — pin a
|
|
5
5
|
major version (`^2.0.0`) in production.
|
|
6
6
|
|
|
7
|
+
## [3.3.4] — 2026-05-10
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
|
|
11
|
+
- **`modpackqt-slave-server` is now a visible palette node** (was a hidden
|
|
12
|
+
config node). Drop it on the canvas like any other node — it shows up in
|
|
13
|
+
the ModPackQT section of the palette as **modbus slave server**.
|
|
14
|
+
- **`slave-read` and `slave-write`** now have a **Slave Server** dropdown
|
|
15
|
+
that lists all `modbus slave server` nodes on the canvas. Select one to
|
|
16
|
+
point at its register store.
|
|
17
|
+
- **`modpackqt-slave-probe` removed** from the palette (old node type gone).
|
|
18
|
+
|
|
19
|
+
## [3.3.3] — 2026-05-10
|
|
20
|
+
|
|
21
|
+
### Added
|
|
22
|
+
|
|
23
|
+
- **`modpackqt-slave-server` config node** — a dedicated Modbus TCP slave
|
|
24
|
+
server with its own register store (65 536 per type). This replaces the
|
|
25
|
+
confusing embedded slave hidden inside the runtime config. Drop one per
|
|
26
|
+
fake device; `slave-read` and `slave-write` nodes point at it directly.
|
|
27
|
+
- Account Key + **My Slaves** picker load saved slave configs from
|
|
28
|
+
modpackqt.com (pre-fills port and unit ID).
|
|
29
|
+
- Register layout and limits are managed from the modpackqt.com web
|
|
30
|
+
console — click **Open in ModPackQT Console** inside the config dialog.
|
|
31
|
+
- Registers with the probe runtime so the web console finds it automatically.
|
|
32
|
+
|
|
33
|
+
### Changed
|
|
34
|
+
|
|
35
|
+
- **`slave-read` and `slave-write`** now have a **Slave Server** picker
|
|
36
|
+
(type `modpackqt-slave-server`) as their primary config reference. The old
|
|
37
|
+
`server` field (pointing to `modpackqt-config`) is kept as a hidden fallback
|
|
38
|
+
so existing flows with the embedded slave keep working.
|
|
39
|
+
- **Embedded slave section removed from runtime config dialog** — the
|
|
40
|
+
`modpackqt-config` dialog is now purely master/transport settings. The
|
|
41
|
+
embedded slave JS stays in the runtime for backward compat with old flows.
|
|
42
|
+
- `modpackqt-slave-probe` kept as-is for full backward compatibility.
|
|
43
|
+
|
|
7
44
|
## [3.3.2] — 2026-05-10
|
|
8
45
|
|
|
9
46
|
### Changed
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
const http = require('http');
|
|
19
19
|
const { URL } = require('url');
|
|
20
20
|
|
|
21
|
-
const PALETTE_VERSION = '3.3.
|
|
21
|
+
const PALETTE_VERSION = '3.3.4';
|
|
22
22
|
const DEFAULT_PORT = parseInt(process.env.MODPACKQT_PROBE_PORT, 10) || 8502;
|
|
23
23
|
const BIND_HOST = process.env.MODPACKQT_PROBE_HOST || '127.0.0.1';
|
|
24
24
|
const PORT_RETRY = 5;
|
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
category: 'ModPackQT',
|
|
4
4
|
color: '#15803d',
|
|
5
5
|
defaults: {
|
|
6
|
-
name:
|
|
7
|
-
|
|
8
|
-
registerType:
|
|
9
|
-
address:
|
|
10
|
-
quantity:
|
|
11
|
-
pollInterval:
|
|
6
|
+
name: { value: '' },
|
|
7
|
+
slaveServerId: { value: '' }, // ID of a modpackqt-slave-server node on the canvas
|
|
8
|
+
registerType: { value: 'holding', required: true },
|
|
9
|
+
address: { value: 0, required: true, validate: RED.validators.number() },
|
|
10
|
+
quantity: { value: 1, required: true, validate: RED.validators.number() },
|
|
11
|
+
pollInterval: { value: 0, validate: RED.validators.number() }
|
|
12
12
|
},
|
|
13
13
|
inputs: 1,
|
|
14
14
|
outputs: 1,
|
|
@@ -16,7 +16,17 @@
|
|
|
16
16
|
label: function () {
|
|
17
17
|
return this.name || ('Slave Read ' + (this.registerType || 'holding') + ' @' + this.address);
|
|
18
18
|
},
|
|
19
|
-
paletteLabel: 'modbus slave read'
|
|
19
|
+
paletteLabel: 'modbus slave read',
|
|
20
|
+
oneditprepare: function () {
|
|
21
|
+
const $sel = $('#node-input-slaveServerId');
|
|
22
|
+
$sel.empty().append('<option value="">— select a slave server node —</option>');
|
|
23
|
+
RED.nodes.eachNode(function (n) {
|
|
24
|
+
if (n.type === 'modpackqt-slave-server') {
|
|
25
|
+
const label = (n.name || (':' + n.bindPort + ' #' + n.unitId));
|
|
26
|
+
$('<option>').val(n.id).text(label).appendTo($sel);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
20
30
|
});
|
|
21
31
|
</script>
|
|
22
32
|
|
|
@@ -26,8 +36,11 @@
|
|
|
26
36
|
<input type="text" id="node-input-name" placeholder="Name">
|
|
27
37
|
</div>
|
|
28
38
|
<div class="form-row">
|
|
29
|
-
<label for="node-input-
|
|
30
|
-
<
|
|
39
|
+
<label for="node-input-slaveServerId"><i class="fa fa-server"></i> Slave Server</label>
|
|
40
|
+
<select id="node-input-slaveServerId" style="width:70%"></select>
|
|
41
|
+
</div>
|
|
42
|
+
<div class="form-tips" style="font-size:11px;color:#6b7280;margin:-8px 0 12px 105px">
|
|
43
|
+
Pick a <b>modbus slave server</b> node from the canvas. Deploy the flow first if the list is empty.
|
|
31
44
|
</div>
|
|
32
45
|
<div class="form-row">
|
|
33
46
|
<label for="node-input-registerType"><i class="fa fa-list"></i> Register Type</label>
|
|
@@ -51,30 +64,27 @@
|
|
|
51
64
|
<input type="number" id="node-input-pollInterval" min="0" placeholder="0 = trigger only">
|
|
52
65
|
</div>
|
|
53
66
|
<div class="form-tips">
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
<code>msg.quantity</code>, or <code>msg.registerType</code>.
|
|
67
|
+
Reads from the slave server's register store. Override at runtime via
|
|
68
|
+
<code>msg.address</code>, <code>msg.quantity</code>, or <code>msg.registerType</code>.
|
|
57
69
|
</div>
|
|
58
70
|
<div class="form-row" style="margin-top:18px;padding-top:14px;border-top:1px solid #e5e7eb;text-align:center;">
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
71
|
+
<a href="https://modpackqt.com" target="_blank" rel="noopener noreferrer"
|
|
72
|
+
style="display:inline-block;padding:8px 20px;background:#2563eb;color:#fff;
|
|
73
|
+
text-decoration:none;border-radius:6px;font-weight:600;font-size:13px;
|
|
74
|
+
box-shadow:0 1px 2px rgba(0,0,0,0.08);">
|
|
75
|
+
Premium Advanced Modbus Tester <i class="fa fa-external-link" style="margin-left:6px;"></i>
|
|
76
|
+
</a>
|
|
77
|
+
<div style="margin-top:6px;font-size:11px;color:#6b7280;">by ModPackQT — full-featured web tester, simulator & AI helper</div>
|
|
78
|
+
</div>
|
|
79
|
+
</script>
|
|
68
80
|
|
|
69
81
|
<script type="text/html" data-help-name="modpackqt-slave-read">
|
|
70
|
-
<p>
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
</p>
|
|
74
|
-
<p>Enable the slave server in the <b>modpackqt-config</b> node first.</p>
|
|
82
|
+
<p>Reads registers from a <b>modbus slave server</b> node's local store.</p>
|
|
83
|
+
<h3>Setup</h3>
|
|
84
|
+
<p>Drop a <b>modbus slave server</b> node on the canvas first, then select it here.</p>
|
|
75
85
|
<h3>Outputs</h3>
|
|
76
86
|
<dl class="message-properties">
|
|
77
87
|
<dt>payload <span class="property-type">array</span></dt>
|
|
78
|
-
<dd>
|
|
88
|
+
<dd>Register values (integers for holding/input, booleans for coils/discrete).</dd>
|
|
79
89
|
</dl>
|
|
80
90
|
</script>
|
|
@@ -1,42 +1,36 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* ModPackQT Slave Read —
|
|
3
|
-
* The slave server itself runs in the modpackqt-config node (when enabled).
|
|
4
|
-
* Outputs raw register values.
|
|
2
|
+
* ModPackQT Slave Read — reads from a modpackqt-slave-server node's register store.
|
|
5
3
|
*/
|
|
6
4
|
module.exports = function (RED) {
|
|
7
5
|
function ModPackQTSlaveReadNode(config) {
|
|
8
6
|
RED.nodes.createNode(this, config);
|
|
9
7
|
const node = this;
|
|
10
|
-
const server = RED.nodes.getNode(config.server);
|
|
11
8
|
|
|
12
9
|
node.registerType = config.registerType || 'holding';
|
|
13
10
|
node.address = parseInt(config.address, 10) || 0;
|
|
14
11
|
node.quantity = parseInt(config.quantity, 10) || 1;
|
|
15
12
|
node.pollInterval = parseInt(config.pollInterval, 10) || 0;
|
|
16
13
|
|
|
14
|
+
function getSlave() {
|
|
15
|
+
return RED.nodes.getNode(config.slaveServerId);
|
|
16
|
+
}
|
|
17
|
+
|
|
17
18
|
let timer = null;
|
|
18
19
|
|
|
19
20
|
function doRead(msg) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (!server.slaveEnabled) {
|
|
25
|
-
node.status({ fill: 'red', shape: 'ring', text: 'slave server disabled in config' });
|
|
26
|
-
node.error('Embedded slave is disabled — enable it in the modpackqt-config node.', msg);
|
|
21
|
+
const slave = getSlave();
|
|
22
|
+
if (!slave || !slave.slaveEnabled) {
|
|
23
|
+
node.status({ fill: 'red', shape: 'ring', text: 'no slave server' });
|
|
24
|
+
node.error('No slave server selected or it is not running.', msg);
|
|
27
25
|
return;
|
|
28
26
|
}
|
|
29
27
|
try {
|
|
30
28
|
const registerType = (msg && msg.registerType) || node.registerType;
|
|
31
29
|
const address = (msg && msg.address !== undefined) ? parseInt(msg.address, 10) : node.address;
|
|
32
30
|
const quantity = (msg && msg.quantity !== undefined) ? parseInt(msg.quantity, 10) : node.quantity;
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
node.status({
|
|
37
|
-
fill: 'green', shape: 'dot',
|
|
38
|
-
text: server.brandStatus(`slave ${registerType} @${address} [${values.length}] · ${now}`)
|
|
39
|
-
});
|
|
31
|
+
const values = slave.slaveGet(registerType, address, quantity);
|
|
32
|
+
const now = new Date().toLocaleTimeString();
|
|
33
|
+
node.status({ fill: 'green', shape: 'dot', text: `${registerType} @${address} [${values.length}] · ${now}` });
|
|
40
34
|
node.send({
|
|
41
35
|
payload: values,
|
|
42
36
|
topic: `modpackqt/slave/${registerType}/${address}`,
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
<script type="text/javascript">
|
|
2
|
+
RED.nodes.registerType('modpackqt-slave-server', {
|
|
3
|
+
category: 'ModPackQT',
|
|
4
|
+
color: '#7c3aed',
|
|
5
|
+
defaults: {
|
|
6
|
+
name: { value: '' },
|
|
7
|
+
bindHost: { value: '0.0.0.0' },
|
|
8
|
+
bindPort: { value: 1502, validate: RED.validators.number() },
|
|
9
|
+
unitId: { value: 1, validate: RED.validators.number() }
|
|
10
|
+
},
|
|
11
|
+
credentials: {
|
|
12
|
+
apiKey: { type: 'password' }
|
|
13
|
+
},
|
|
14
|
+
inputs: 0,
|
|
15
|
+
outputs: 0,
|
|
16
|
+
icon: 'font-awesome/fa-server',
|
|
17
|
+
label: function () {
|
|
18
|
+
return this.name || `:${this.bindPort} #${this.unitId}`;
|
|
19
|
+
},
|
|
20
|
+
paletteLabel: 'modbus slave server',
|
|
21
|
+
oneditprepare: function () {
|
|
22
|
+
const node = this;
|
|
23
|
+
|
|
24
|
+
// ── My Slaves picker
|
|
25
|
+
const $sel = $('#node-input-modpackqt-slave-picker');
|
|
26
|
+
const reload = function () {
|
|
27
|
+
$sel.empty().append('<option value="">— Loading… —</option>');
|
|
28
|
+
if (!node.id) {
|
|
29
|
+
$sel.empty().append('<option value="">— Save this node first, then reopen —</option>');
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
$.getJSON('modpackqt/slaves?probe=' + encodeURIComponent(node.id))
|
|
33
|
+
.done(function (rows) {
|
|
34
|
+
$sel.empty().append('<option value="">— Manual entry —</option>');
|
|
35
|
+
(rows || [])
|
|
36
|
+
.filter(function (s) { return s && (s.protocol === 'tcp' || !s.protocol); })
|
|
37
|
+
.forEach(function (s) {
|
|
38
|
+
const label = (s.name || '(unnamed)') + ' — :' + (s.port || 1502) + ' #' + (s.unitId || 1);
|
|
39
|
+
$('<option>').val(s.id).text(label).data('row', s).appendTo($sel);
|
|
40
|
+
});
|
|
41
|
+
})
|
|
42
|
+
.fail(function (xhr) {
|
|
43
|
+
const msg = (xhr.responseJSON && xhr.responseJSON.error) || ('HTTP ' + xhr.status);
|
|
44
|
+
$sel.empty().append($('<option>').val('').text('— ' + msg + ' —'));
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
$('#modpackqt-slave-server-picker-refresh').on('click', function (e) { e.preventDefault(); reload(); });
|
|
48
|
+
$sel.on('change', function () {
|
|
49
|
+
const row = $(this).find('option:selected').data('row');
|
|
50
|
+
if (!row) return;
|
|
51
|
+
if (!node.name) $('#node-input-name').val(row.name || '');
|
|
52
|
+
$('#node-input-bindPort').val(row.port || 1502);
|
|
53
|
+
$('#node-input-unitId').val(row.unitId || 1);
|
|
54
|
+
buildLink();
|
|
55
|
+
});
|
|
56
|
+
reload();
|
|
57
|
+
|
|
58
|
+
// ── Probe deep-link
|
|
59
|
+
const buildLink = function () {
|
|
60
|
+
$.getJSON('modpackqt-probe/info')
|
|
61
|
+
.done(renderLink).fail(function () { renderLink({}); });
|
|
62
|
+
};
|
|
63
|
+
const renderLink = function (info) {
|
|
64
|
+
const probeHost = (info && info.host) || '127.0.0.1';
|
|
65
|
+
const probePort = (info && info.port) || 8502;
|
|
66
|
+
const bindPort = $('#node-input-bindPort').val() || node.bindPort || 1502;
|
|
67
|
+
const unitId = $('#node-input-unitId').val() || node.unitId || 1;
|
|
68
|
+
const name = $('#node-input-name').val() || node.name || '';
|
|
69
|
+
const url = 'https://modpackqt.com/slave'
|
|
70
|
+
+ '?probe=' + encodeURIComponent(node.id || '')
|
|
71
|
+
+ '&probeHost=' + encodeURIComponent(probeHost)
|
|
72
|
+
+ '&probePort=' + probePort
|
|
73
|
+
+ '&port=' + bindPort
|
|
74
|
+
+ '&unitId=' + unitId
|
|
75
|
+
+ (name ? '&name=' + encodeURIComponent(name) : '');
|
|
76
|
+
$('#modpackqt-slave-server-link').attr('href', url);
|
|
77
|
+
$('#modpackqt-slave-server-runtime').text(probeHost + ':' + probePort);
|
|
78
|
+
$('#modpackqt-slave-server-target').text(':' + bindPort + ' · unit ' + unitId);
|
|
79
|
+
};
|
|
80
|
+
buildLink();
|
|
81
|
+
$('#node-input-bindPort, #node-input-unitId').on('change input', buildLink);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
</script>
|
|
85
|
+
|
|
86
|
+
<script type="text/html" data-template-name="modpackqt-slave-server">
|
|
87
|
+
<div class="form-row">
|
|
88
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
89
|
+
<input type="text" id="node-input-name" placeholder="e.g. Fake Inverter">
|
|
90
|
+
</div>
|
|
91
|
+
|
|
92
|
+
<div class="form-row">
|
|
93
|
+
<label for="node-input-apiKey"><i class="fa fa-key"></i> Account Key</label>
|
|
94
|
+
<input type="password" id="node-input-apiKey" placeholder="Paste your ModPackQT tunnel key">
|
|
95
|
+
</div>
|
|
96
|
+
<div class="form-tips" style="font-size:11px;color:#6b7280;margin:-8px 0 12px 105px">
|
|
97
|
+
Generate at <a href="https://modpackqt.com/settings" target="_blank" rel="noopener">modpackqt.com → Settings → Cloud Gateways</a>.
|
|
98
|
+
Loads your saved slave configs in the picker below.
|
|
99
|
+
</div>
|
|
100
|
+
|
|
101
|
+
<div class="form-row">
|
|
102
|
+
<label for="node-input-modpackqt-slave-picker"><i class="fa fa-cloud-download"></i> My Slaves</label>
|
|
103
|
+
<select id="node-input-modpackqt-slave-picker" style="width:65%"></select>
|
|
104
|
+
<button type="button" id="modpackqt-slave-server-picker-refresh" class="red-ui-button" title="Reload" style="margin-left:4px"><i class="fa fa-refresh"></i></button>
|
|
105
|
+
</div>
|
|
106
|
+
<div class="form-tips" style="font-size:11px;color:#6b7280;margin:-8px 0 12px 105px">
|
|
107
|
+
Picks a saved slave from modpackqt.com — auto-fills port and unit.
|
|
108
|
+
Register layout and limits are managed from the web console.
|
|
109
|
+
</div>
|
|
110
|
+
|
|
111
|
+
<div class="form-row">
|
|
112
|
+
<label for="node-input-bindPort"><i class="fa fa-hashtag"></i> Port</label>
|
|
113
|
+
<input type="number" id="node-input-bindPort" min="1024" max="65535" placeholder="1502">
|
|
114
|
+
</div>
|
|
115
|
+
<div class="form-row">
|
|
116
|
+
<label for="node-input-unitId"><i class="fa fa-id-card"></i> Unit ID</label>
|
|
117
|
+
<input type="number" id="node-input-unitId" min="1" max="247" placeholder="1">
|
|
118
|
+
</div>
|
|
119
|
+
|
|
120
|
+
<input type="hidden" id="node-input-bindHost">
|
|
121
|
+
|
|
122
|
+
<div class="form-row" style="margin-top:18px;padding-top:14px;border-top:1px solid #e5e7eb;text-align:center;">
|
|
123
|
+
<a id="modpackqt-slave-server-link" href="https://modpackqt.com" target="_blank" rel="noopener noreferrer"
|
|
124
|
+
style="display:inline-block;padding:10px 24px;background:#7c3aed;color:#fff;
|
|
125
|
+
text-decoration:none;border-radius:6px;font-weight:600;font-size:14px;
|
|
126
|
+
box-shadow:0 1px 2px rgba(0,0,0,0.08);">
|
|
127
|
+
Open in ModPackQT Console <i class="fa fa-external-link" style="margin-left:6px;"></i>
|
|
128
|
+
</a>
|
|
129
|
+
<div style="margin-top:6px;font-size:11px;color:#6b7280;">
|
|
130
|
+
Target: <span id="modpackqt-slave-server-target">—</span> · runtime <span id="modpackqt-slave-server-runtime">starting…</span>
|
|
131
|
+
</div>
|
|
132
|
+
</div>
|
|
133
|
+
</script>
|
|
134
|
+
|
|
135
|
+
<script type="text/html" data-help-name="modpackqt-slave-server">
|
|
136
|
+
<p>
|
|
137
|
+
Runs a Modbus TCP slave server with its own full register store.
|
|
138
|
+
Drop one on the canvas per fake device. <b>Slave-read</b> and
|
|
139
|
+
<b>slave-write</b> nodes target it by node ID to read and write
|
|
140
|
+
registers from the flow.
|
|
141
|
+
</p>
|
|
142
|
+
<h3>Setup</h3>
|
|
143
|
+
<ol>
|
|
144
|
+
<li>Drop this node, set Port and Unit ID (or pick from <b>My Slaves</b>).</li>
|
|
145
|
+
<li>On your slave-read / slave-write nodes, select this node in the <b>Slave Server</b> dropdown.</li>
|
|
146
|
+
<li>Click <b>Open in ModPackQT Console</b> to manage the register layout from the web.</li>
|
|
147
|
+
</ol>
|
|
148
|
+
<h3>Account Key</h3>
|
|
149
|
+
<p>Generate at <a href="https://modpackqt.com/settings" target="_blank" rel="noopener">modpackqt.com → Settings → Cloud Gateways</a>.
|
|
150
|
+
Lets the web console connect and loads your saved slave configs.</p>
|
|
151
|
+
<h3>Port note</h3>
|
|
152
|
+
<p>Use ports above 1024 (e.g. 1502, 1503) to avoid needing root privileges. Each server must use a unique port.</p>
|
|
153
|
+
</script>
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ModPackQT Slave Server — Modbus TCP slave with a full register store.
|
|
3
|
+
*
|
|
4
|
+
* Drop one on the canvas per fake device. Each server:
|
|
5
|
+
* - Binds its own TCP port and listens for external Modbus masters
|
|
6
|
+
* - Owns 65 536 registers per type (coils, discrete, holding, input)
|
|
7
|
+
* - Exposes slaveGet() / slaveSet() so slave-read / slave-write nodes
|
|
8
|
+
* can push and pull values from the flow side
|
|
9
|
+
* - Registers with the probe runtime so modpackqt.com can open a live
|
|
10
|
+
* register editor for it
|
|
11
|
+
*
|
|
12
|
+
* Register limits and layout are managed from the modpackqt.com web
|
|
13
|
+
* console — this node only needs port and unit ID to bind.
|
|
14
|
+
*/
|
|
15
|
+
module.exports = function (RED) {
|
|
16
|
+
const ModbusRTU = require('modbus-serial');
|
|
17
|
+
const { getRuntime } = require('./lib/probe-runtime');
|
|
18
|
+
|
|
19
|
+
function SlaveServerNode(config) {
|
|
20
|
+
RED.nodes.createNode(this, config);
|
|
21
|
+
const node = this;
|
|
22
|
+
|
|
23
|
+
node.name = config.name || '';
|
|
24
|
+
node.bindHost = config.bindHost || '0.0.0.0';
|
|
25
|
+
node.bindPort = parseInt(config.bindPort, 10) || 1502;
|
|
26
|
+
node.unitId = parseInt(config.unitId, 10) || 1;
|
|
27
|
+
|
|
28
|
+
// ── Register store
|
|
29
|
+
const store = {
|
|
30
|
+
coils: new Array(65536).fill(false),
|
|
31
|
+
discrete: new Array(65536).fill(false),
|
|
32
|
+
holding: new Array(65536).fill(0),
|
|
33
|
+
input: new Array(65536).fill(0)
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// ── Flow-side API — used by slave-read and slave-write nodes
|
|
37
|
+
node.slaveEnabled = true;
|
|
38
|
+
|
|
39
|
+
node.slaveGet = function (type, address, quantity) {
|
|
40
|
+
const arr = store[type];
|
|
41
|
+
if (!arr) throw new Error(`Unknown register type: ${type}`);
|
|
42
|
+
return arr.slice(address, address + quantity);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
node.slaveSet = function (type, address, values) {
|
|
46
|
+
const arr = store[type];
|
|
47
|
+
if (!arr) throw new Error(`Unknown register type: ${type}`);
|
|
48
|
+
const isBool = (type === 'coils' || type === 'discrete');
|
|
49
|
+
const stored = values.map((v) => isBool ? Boolean(v) : (parseInt(v, 10) & 0xFFFF));
|
|
50
|
+
stored.forEach((v, i) => { arr[address + i] = v; });
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// ── Modbus TCP server
|
|
54
|
+
let server = null;
|
|
55
|
+
try {
|
|
56
|
+
const vector = {
|
|
57
|
+
getCoil: (addr, _u, cb) => cb(null, store.coils[addr]),
|
|
58
|
+
getDiscreteInput: (addr, _u, cb) => cb(null, store.discrete[addr]),
|
|
59
|
+
getHoldingRegister: (addr, _u, cb) => cb(null, store.holding[addr]),
|
|
60
|
+
getInputRegister: (addr, _u, cb) => cb(null, store.input[addr]),
|
|
61
|
+
setCoil: (addr, val, _u, cb) => { store.coils[addr] = !!val; cb(null); },
|
|
62
|
+
setRegister: (addr, val, _u, cb) => { store.holding[addr] = val & 0xFFFF; cb(null); }
|
|
63
|
+
};
|
|
64
|
+
server = new ModbusRTU.ServerTCP(vector, {
|
|
65
|
+
host: node.bindHost,
|
|
66
|
+
port: node.bindPort,
|
|
67
|
+
debug: false,
|
|
68
|
+
unitID: node.unitId
|
|
69
|
+
});
|
|
70
|
+
server.on('socketError', (err) => node.warn(`[slave-server] socket: ${err.message}`));
|
|
71
|
+
server.on('serverError', (err) => node.error(`[slave-server] server: ${err.message}`));
|
|
72
|
+
node.log(`[modpackqt] slave server listening on ${node.bindHost}:${node.bindPort} #${node.unitId}`);
|
|
73
|
+
node.status({ fill: 'green', shape: 'dot', text: `listening :${node.bindPort} #${node.unitId}` });
|
|
74
|
+
} catch (err) {
|
|
75
|
+
node.error(`Failed to start slave server: ${err.message}`);
|
|
76
|
+
node.status({ fill: 'red', shape: 'ring', text: 'failed to start' });
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// ── Probe runtime — lets the web console find and control this server
|
|
80
|
+
const probe = {
|
|
81
|
+
id: node.id,
|
|
82
|
+
kind: 'slave',
|
|
83
|
+
describe(_detailed = false) {
|
|
84
|
+
return {
|
|
85
|
+
id: node.id,
|
|
86
|
+
kind: 'slave',
|
|
87
|
+
name: node.name || `Slave :${node.bindPort} #${node.unitId}`,
|
|
88
|
+
target: {
|
|
89
|
+
mode: 'tcp',
|
|
90
|
+
host: node.bindHost,
|
|
91
|
+
port: node.bindPort,
|
|
92
|
+
unitId: node.unitId
|
|
93
|
+
},
|
|
94
|
+
status: server ? 'listening' : 'error'
|
|
95
|
+
};
|
|
96
|
+
},
|
|
97
|
+
async handleRead() { throw new Error('slave server — use GET /store to inspect registers'); },
|
|
98
|
+
async handleWrite() { throw new Error('slave server — use PUT /store to set registers'); },
|
|
99
|
+
async handleStoreGet(searchParams) {
|
|
100
|
+
const type = searchParams.get('type') || 'holding';
|
|
101
|
+
const addr = parseInt(searchParams.get('address') || '0', 10);
|
|
102
|
+
const qty = parseInt(searchParams.get('quantity') || '10', 10);
|
|
103
|
+
if (!store[type]) throw new Error(`unknown register type: ${type}`);
|
|
104
|
+
return { type, address: addr, values: store[type].slice(addr, addr + qty) };
|
|
105
|
+
},
|
|
106
|
+
async handleStorePut(body) {
|
|
107
|
+
const type = body.type || 'holding';
|
|
108
|
+
const addr = parseInt(body.address, 10) || 0;
|
|
109
|
+
const values = body.values || [];
|
|
110
|
+
if (!store[type]) throw new Error(`unknown register type: ${type}`);
|
|
111
|
+
if (!Array.isArray(values)) throw new Error('values must be an array');
|
|
112
|
+
const isBool = (type === 'coils' || type === 'discrete');
|
|
113
|
+
const stored = values.map((v) => isBool ? Boolean(v) : (parseInt(v, 10) & 0xFFFF));
|
|
114
|
+
stored.forEach((v, i) => { store[type][addr + i] = v; });
|
|
115
|
+
return { ok: true, type, address: addr, written: stored.length };
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const runtime = getRuntime();
|
|
120
|
+
runtime.ensureAdminRoutes(RED);
|
|
121
|
+
runtime.register(probe);
|
|
122
|
+
|
|
123
|
+
node.on('close', function (done) {
|
|
124
|
+
runtime.unregister(node.id);
|
|
125
|
+
if (server) {
|
|
126
|
+
try { server.close(() => done()); } catch (_) { done(); }
|
|
127
|
+
} else {
|
|
128
|
+
done();
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
RED.nodes.registerType('modpackqt-slave-server', SlaveServerNode, {
|
|
134
|
+
credentials: { apiKey: { type: 'password' } }
|
|
135
|
+
});
|
|
136
|
+
};
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
category: 'ModPackQT',
|
|
4
4
|
color: '#15803d',
|
|
5
5
|
defaults: {
|
|
6
|
-
name:
|
|
7
|
-
|
|
8
|
-
registerType:
|
|
9
|
-
address:
|
|
6
|
+
name: { value: '' },
|
|
7
|
+
slaveServerId: { value: '' }, // ID of a modpackqt-slave-server node on the canvas
|
|
8
|
+
registerType: { value: 'holding', required: true },
|
|
9
|
+
address: { value: 0, required: true, validate: RED.validators.number() }
|
|
10
10
|
},
|
|
11
11
|
inputs: 1,
|
|
12
12
|
outputs: 1,
|
|
@@ -14,7 +14,17 @@
|
|
|
14
14
|
label: function () {
|
|
15
15
|
return this.name || ('Slave Write ' + (this.registerType || 'holding') + ' @' + this.address);
|
|
16
16
|
},
|
|
17
|
-
paletteLabel: 'modbus slave write'
|
|
17
|
+
paletteLabel: 'modbus slave write',
|
|
18
|
+
oneditprepare: function () {
|
|
19
|
+
const $sel = $('#node-input-slaveServerId');
|
|
20
|
+
$sel.empty().append('<option value="">— select a slave server node —</option>');
|
|
21
|
+
RED.nodes.eachNode(function (n) {
|
|
22
|
+
if (n.type === 'modpackqt-slave-server') {
|
|
23
|
+
const label = (n.name || (':' + n.bindPort + ' #' + n.unitId));
|
|
24
|
+
$('<option>').val(n.id).text(label).appendTo($sel);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
18
28
|
});
|
|
19
29
|
</script>
|
|
20
30
|
|
|
@@ -24,8 +34,11 @@
|
|
|
24
34
|
<input type="text" id="node-input-name" placeholder="Name">
|
|
25
35
|
</div>
|
|
26
36
|
<div class="form-row">
|
|
27
|
-
<label for="node-input-
|
|
28
|
-
<
|
|
37
|
+
<label for="node-input-slaveServerId"><i class="fa fa-server"></i> Slave Server</label>
|
|
38
|
+
<select id="node-input-slaveServerId" style="width:70%"></select>
|
|
39
|
+
</div>
|
|
40
|
+
<div class="form-tips" style="font-size:11px;color:#6b7280;margin:-8px 0 12px 105px">
|
|
41
|
+
Pick a <b>modbus slave server</b> node from the canvas. Deploy the flow first if the list is empty.
|
|
29
42
|
</div>
|
|
30
43
|
<div class="form-row">
|
|
31
44
|
<label for="node-input-registerType"><i class="fa fa-list"></i> Register Type</label>
|
|
@@ -41,26 +54,29 @@
|
|
|
41
54
|
<input type="number" id="node-input-address" min="0" max="65535" placeholder="0">
|
|
42
55
|
</div>
|
|
43
56
|
<div class="form-tips">
|
|
44
|
-
|
|
45
|
-
|
|
57
|
+
Pushes values into the slave server's register store. External Modbus masters
|
|
58
|
+
connecting to that port will read whatever you last wrote.
|
|
46
59
|
Send <code>msg.payload</code> as a number, array, or JSON string.
|
|
47
60
|
</div>
|
|
48
61
|
<div class="form-row" style="margin-top:18px;padding-top:14px;border-top:1px solid #e5e7eb;text-align:center;">
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
62
|
+
<a href="https://modpackqt.com" target="_blank" rel="noopener noreferrer"
|
|
63
|
+
style="display:inline-block;padding:8px 20px;background:#2563eb;color:#fff;
|
|
64
|
+
text-decoration:none;border-radius:6px;font-weight:600;font-size:13px;
|
|
65
|
+
box-shadow:0 1px 2px rgba(0,0,0,0.08);">
|
|
66
|
+
Premium Advanced Modbus Tester <i class="fa fa-external-link" style="margin-left:6px;"></i>
|
|
67
|
+
</a>
|
|
68
|
+
<div style="margin-top:6px;font-size:11px;color:#6b7280;">by ModPackQT — full-featured web tester, simulator & AI helper</div>
|
|
69
|
+
</div>
|
|
70
|
+
</script>
|
|
58
71
|
|
|
59
72
|
<script type="text/html" data-help-name="modpackqt-slave-write">
|
|
60
|
-
<p>
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
</
|
|
65
|
-
<
|
|
73
|
+
<p>Writes values into a <b>modbus slave server</b> node's register store.
|
|
74
|
+
External Modbus masters connecting to that slave's port will read whatever was last written.</p>
|
|
75
|
+
<h3>Setup</h3>
|
|
76
|
+
<p>Drop a <b>modbus slave server</b> node on the canvas first, then select it here.</p>
|
|
77
|
+
<h3>Input</h3>
|
|
78
|
+
<dl class="message-properties">
|
|
79
|
+
<dt>payload <span class="property-type">number | array | string</span></dt>
|
|
80
|
+
<dd>Value(s) to write. Arrays write multiple consecutive registers.</dd>
|
|
81
|
+
</dl>
|
|
66
82
|
</script>
|
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* ModPackQT Slave Write —
|
|
3
|
-
* External Modbus masters connecting to the slave port
|
|
4
|
-
* modpackqt-config) will read whatever was last written here.
|
|
2
|
+
* ModPackQT Slave Write — writes into a modpackqt-slave-server node's register store.
|
|
3
|
+
* External Modbus masters connecting to the slave port will read whatever was last written.
|
|
5
4
|
*/
|
|
6
5
|
module.exports = function (RED) {
|
|
7
6
|
function ModPackQTSlaveWriteNode(config) {
|
|
8
7
|
RED.nodes.createNode(this, config);
|
|
9
8
|
const node = this;
|
|
10
|
-
const server = RED.nodes.getNode(config.server);
|
|
11
9
|
|
|
12
10
|
node.registerType = config.registerType || 'holding';
|
|
13
11
|
node.address = parseInt(config.address, 10) || 0;
|
|
14
12
|
|
|
13
|
+
function getSlave() {
|
|
14
|
+
return RED.nodes.getNode(config.slaveServerId);
|
|
15
|
+
}
|
|
16
|
+
|
|
15
17
|
node.on('input', function (msg) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (!server.slaveEnabled) {
|
|
21
|
-
node.status({ fill: 'red', shape: 'ring', text: 'slave server disabled in config' });
|
|
22
|
-
node.error('Embedded slave is disabled — enable it in the modpackqt-config node.', msg);
|
|
18
|
+
const slave = getSlave();
|
|
19
|
+
if (!slave || !slave.slaveEnabled) {
|
|
20
|
+
node.status({ fill: 'red', shape: 'ring', text: 'no slave server' });
|
|
21
|
+
node.error('No slave server selected or it is not running.', msg);
|
|
23
22
|
return;
|
|
24
23
|
}
|
|
25
24
|
try {
|
|
@@ -36,13 +35,9 @@ module.exports = function (RED) {
|
|
|
36
35
|
throw new Error(`Invalid payload — expected number or array, got: ${JSON.stringify(msg.payload)}`);
|
|
37
36
|
}
|
|
38
37
|
const address = msg.address !== undefined ? parseInt(msg.address, 10) : node.address;
|
|
39
|
-
|
|
40
|
-
server.slaveSet(registerType, address, values);
|
|
38
|
+
slave.slaveSet(registerType, address, values);
|
|
41
39
|
const now = new Date().toLocaleTimeString();
|
|
42
|
-
node.status({
|
|
43
|
-
fill: 'green', shape: 'dot',
|
|
44
|
-
text: server.brandStatus(`slave wrote ${values.length} @${address} · ${now}`)
|
|
45
|
-
});
|
|
40
|
+
node.status({ fill: 'green', shape: 'dot', text: `wrote ${values.length} → ${registerType} @${address} · ${now}` });
|
|
46
41
|
msg.success = true;
|
|
47
42
|
msg.valuesWritten = values;
|
|
48
43
|
node.send(msg);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-red-contrib-modbus-modpackqt",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.4",
|
|
4
4
|
"description": "Modbus commissioning, testing & analysis tools for Node-RED. Embedded Modbus TCP/RTU master + slave server, FC1/FC2/FC3/FC4 reads, FC5/FC6/FC15/FC16 writes, built-in slave register store, and a passive traffic monitor for debugging. 100% free, MIT, no usage limits. By ModPackQT — open the matching web console at modpackqt.com for register decoding, simulation and AI assistance.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"node-red",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"modpackqt-slave-write": "nodes/modpackqt-slave-write.js",
|
|
52
52
|
"modpackqt-traffic": "nodes/modpackqt-traffic.js",
|
|
53
53
|
"modpackqt-master-probe": "nodes/modpackqt-master-probe.js",
|
|
54
|
-
"modpackqt-slave-
|
|
54
|
+
"modpackqt-slave-server": "nodes/modpackqt-slave-server.js"
|
|
55
55
|
}
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|