node-red-contrib-modbus-modpackqt 1.1.4 → 1.1.5
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.
|
@@ -10,7 +10,7 @@ module.exports = function(RED) {
|
|
|
10
10
|
node.functionCode = parseInt(config.functionCode) || 3;
|
|
11
11
|
node.address = parseInt(config.address) || 0;
|
|
12
12
|
node.quantity = parseInt(config.quantity) || 1;
|
|
13
|
-
node.pollInterval = parseInt(config.pollInterval)
|
|
13
|
+
node.pollInterval = config.pollInterval ? parseInt(config.pollInterval, 10) : 0;
|
|
14
14
|
|
|
15
15
|
const FC_TO_REGISTER_TYPE = { 1: 'coil', 2: 'discrete', 3: 'holding', 4: 'input' };
|
|
16
16
|
|
|
@@ -31,7 +31,9 @@ module.exports = function(RED) {
|
|
|
31
31
|
address: node.address,
|
|
32
32
|
quantity: node.quantity
|
|
33
33
|
});
|
|
34
|
-
|
|
34
|
+
const ts = new Date().toLocaleTimeString();
|
|
35
|
+
const pollLabel = node.pollInterval > 0 ? ` (poll ${node.pollInterval}ms)` : '';
|
|
36
|
+
node.status({ fill: 'green', shape: 'dot', text: `FC${node.functionCode} @${node.address} · ${ts}${pollLabel}` });
|
|
35
37
|
node.send({ payload: result, topic: `modbus/read/${node.targetHost}:${node.targetPort}` });
|
|
36
38
|
} catch (err) {
|
|
37
39
|
node.status({ fill: 'red', shape: 'dot', text: err.message });
|
|
@@ -40,11 +42,12 @@ module.exports = function(RED) {
|
|
|
40
42
|
}
|
|
41
43
|
|
|
42
44
|
if (node.pollInterval > 0) {
|
|
45
|
+
node.status({ fill: 'yellow', shape: 'ring', text: `polling every ${node.pollInterval}ms…` });
|
|
43
46
|
timer = setInterval(doRead, node.pollInterval);
|
|
44
47
|
}
|
|
45
48
|
|
|
46
49
|
node.on('input', async function() { await doRead(); });
|
|
47
|
-
node.on('close', function() { if (timer) clearInterval(timer); });
|
|
50
|
+
node.on('close', function() { if (timer) { clearInterval(timer); timer = null; } });
|
|
48
51
|
}
|
|
49
52
|
RED.nodes.registerType('modpackqt-master-read', ModPackQTMasterReadNode);
|
|
50
53
|
};
|
|
@@ -18,8 +18,25 @@ module.exports = function(RED) {
|
|
|
18
18
|
return;
|
|
19
19
|
}
|
|
20
20
|
try {
|
|
21
|
-
|
|
21
|
+
// Accept string JSON (e.g. "[100,200,300]" from inject string type),
|
|
22
|
+
// plain number, or actual array/number from inject JSON type.
|
|
23
|
+
let raw = msg.payload;
|
|
24
|
+
if (typeof raw === 'string') {
|
|
25
|
+
try { raw = JSON.parse(raw); } catch (_) { raw = Number(raw); }
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Always convert every value to an integer to avoid byte-encoding corruption.
|
|
29
|
+
const values = Array.isArray(raw)
|
|
30
|
+
? raw.map(v => parseInt(v, 10))
|
|
31
|
+
: [parseInt(raw, 10)];
|
|
32
|
+
|
|
33
|
+
if (values.some(v => isNaN(v))) {
|
|
34
|
+
throw new Error(`Invalid payload — expected number or array of numbers, got: ${msg.payload}`);
|
|
35
|
+
}
|
|
36
|
+
|
|
22
37
|
const registerType = FC_TO_REGISTER_TYPE[node.functionCode] || 'holding';
|
|
38
|
+
node.status({ fill: 'blue', shape: 'ring', text: `writing ${values.length} value(s)…` });
|
|
39
|
+
|
|
23
40
|
await server.request('POST', '/api/modbus/tcp/write', {
|
|
24
41
|
host: node.targetHost,
|
|
25
42
|
port: node.targetPort,
|
|
@@ -28,8 +45,10 @@ module.exports = function(RED) {
|
|
|
28
45
|
address: node.address,
|
|
29
46
|
values
|
|
30
47
|
});
|
|
31
|
-
|
|
48
|
+
|
|
49
|
+
node.status({ fill: 'green', shape: 'dot', text: `wrote ${values.length} @ addr ${node.address}` });
|
|
32
50
|
msg.success = true;
|
|
51
|
+
msg.valuesWritten = values;
|
|
33
52
|
node.send(msg);
|
|
34
53
|
} catch (err) {
|
|
35
54
|
node.status({ fill: 'red', shape: 'dot', text: err.message });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-red-contrib-modbus-modpackqt",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.5",
|
|
4
4
|
"description": "Node-RED nodes for ModPackQT — read/write Modbus TCP registers (master & slave) via the ModPackQT Gateway app. Supports FC1/FC2/FC3/FC4 reads and FC5/FC6/FC15/FC16 writes.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"node-red",
|