node-red-contrib-s7-rust 1.0.5 → 1.1.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.
- package/CHANGELOG.md +40 -1
- package/README.md +7 -4
- package/bin/linux-x64-gnu/s7napi.node +0 -0
- package/bin/linux-x64-musl/s7napi.node +0 -0
- package/examples/05 - S7CommPlus alarms.json +114 -0
- package/lib/napi-bridge.js +16 -2
- package/nodes/locales/en-US/s7rs-alarms.html +35 -0
- package/nodes/locales/en-US/s7rs-alarms.json +24 -0
- package/nodes/locales/en-US/s7rs-watch.html +12 -4
- package/nodes/locales/en-US/s7rs-watch.json +5 -0
- package/nodes/s7rs-alarms.html +46 -0
- package/nodes/s7rs-alarms.js +48 -0
- package/nodes/s7rs-watch.html +20 -3
- package/nodes/s7rs-watch.js +5 -2
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,44 @@ All notable changes to this project are documented here. The format follows
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [1.1.0] - 2026-11-12
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- `s7 watch`: mode "PLC subscription" (S7CommPlus). The node subscribes to the tags with the
|
|
14
|
+
interval as cycle time, and the PLC sends only the values that changed (no read request per
|
|
15
|
+
cycle). `msg.ts` is the PLC time of the notification when the PLC sends one. After a reconnect
|
|
16
|
+
the node subscribes again; when the PLC refuses the subscription (or for S7comm) it reads
|
|
17
|
+
cyclically. Tested on PLCSIM Advanced V8 (FW S4.1) with TLS: first message with all tags, then
|
|
18
|
+
the changes every cycle, and a write is in the next notification. The default stays "read
|
|
19
|
+
cyclically".
|
|
20
|
+
- `s7 alarms` node (S7CommPlus): one message per PLC alarm event (`msg.state` coming / going,
|
|
21
|
+
`msg.topic` the alarm id, `msg.payload` times, associated values, priority, class, texts). At
|
|
22
|
+
start, and again after a reconnect, it sends the active alarms (`msg.initial`). The status shows
|
|
23
|
+
the number of active alarms. Example flow "05 - S7CommPlus alarms". Tested on PLCSIM Advanced
|
|
24
|
+
V8 (FW S4.1): a Program_Alarm comes about 20 ms after its signal is written.
|
|
25
|
+
- Alarm subscriptions: `AlarmSubOptions::for_plc` selects the layout. S7-1500 FW V4.x accepts the
|
|
26
|
+
TIA Portal layout but sends no alarms with it; it needs the S7CommPlusDriver layout (the S7-1200
|
|
27
|
+
keeps the TIA Portal layout). The `s7 info` action `alarms` also returns `state`, `priority`,
|
|
28
|
+
`alarmClass` and the associated values. The fake PLC sends alarm notifications
|
|
29
|
+
(`FakePlc::raise_alarm`, `FakeModel::alarm_needs_reference`); golden tests decode PLCSIM alarm
|
|
30
|
+
notifications.
|
|
31
|
+
- `test/plcsim/`: the PLCSIM Advanced test program (SIMATIC SD documents of the DBs, the alarm FB
|
|
32
|
+
and OB1), how to load it with TIA Portal (Openness MCP), and two manual live-test scripts
|
|
33
|
+
(`s7 watch` push/poll, `s7 alarms`). `npm test` does not use them.
|
|
34
|
+
|
|
35
|
+
### Fixed
|
|
36
|
+
|
|
37
|
+
- S7CommPlus: a Bool member of an optimized S7-1500 DB (softdatatype BBool) could not be written
|
|
38
|
+
("writing BBool is not supported"); reads worked. It is now written like a Bool. Found on
|
|
39
|
+
PLCSIM Advanced V8 (FW S4.1); the fake PLC has a BBool member (`"Data_block_1".BFlag`).
|
|
40
|
+
- S7CommPlus subscriptions on S7-1500 FW V4.x: with cycle time 0 the PLC sends only the first
|
|
41
|
+
notification. `SubOptions::cycle_ms` documents it; the fake PLC models it
|
|
42
|
+
(`FakeModel::sub_needs_cycle`), and golden tests decode FW V4.x notifications (change counter,
|
|
43
|
+
8-byte timestamp).
|
|
44
|
+
- Addon: a data event with every tag in another order than the tag list now carries the index
|
|
45
|
+
list (before, the values went to the wrong tags; only possible with PLC notifications).
|
|
46
|
+
|
|
9
47
|
## [1.0.5] - 2026-11-12
|
|
10
48
|
|
|
11
49
|
### Fixed
|
|
@@ -102,7 +140,8 @@ First release: the next generation of `@oriolrius/node-red-contrib-s7`.
|
|
|
102
140
|
- CI: tests on Node-RED 4 and 5, gitleaks, GitGuardian, RustSec and npm audit, CodeQL,
|
|
103
141
|
OpenSSF Scorecard, Dependabot. License LGPL-3.0-only.
|
|
104
142
|
|
|
105
|
-
[Unreleased]: https://github.com/oriolrius/node-red-contrib-s7-rust/compare/v1.0
|
|
143
|
+
[Unreleased]: https://github.com/oriolrius/node-red-contrib-s7-rust/compare/v1.1.0...HEAD
|
|
144
|
+
[1.1.0]: https://github.com/oriolrius/node-red-contrib-s7-rust/compare/v1.0.5...v1.1.0
|
|
106
145
|
[1.0.5]: https://github.com/oriolrius/node-red-contrib-s7-rust/compare/v1.0.4...v1.0.5
|
|
107
146
|
[1.0.4]: https://github.com/oriolrius/node-red-contrib-s7-rust/compare/v1.0.3...v1.0.4
|
|
108
147
|
[1.0.3]: https://github.com/oriolrius/node-red-contrib-s7-rust/compare/v1.0.2...v1.0.3
|
package/README.md
CHANGED
|
@@ -82,7 +82,8 @@ Then restart Node-RED. The nodes are in the **network** category of the palette.
|
|
|
82
82
|
| `s7 endpoint` (config) | One PLC connection: protocol, host, port. S7comm: CPU family, rack/slot or TSAPs, PDU, gap, byte order. S7CommPlus: remote TSAP, TLS, user, password (stored as a credential). |
|
|
83
83
|
| `s7 read` | Reads tags when a message arrives. Output: one value, `{tag: value}` or an array. |
|
|
84
84
|
| `s7 write` | Writes the tag of the node, the tag in `msg.topic`, or `msg.payload = {tag: value, …}` in one request. |
|
|
85
|
-
| `s7 watch` |
|
|
85
|
+
| `s7 watch` | Sends only the changes. Mode "read cyclically": a Rust thread reads the tags at an interval, with an optional conditional rate ("Fast while" a tag is true). Mode "PLC subscription" (S7CommPlus): the PLC sends the changes. |
|
|
86
|
+
| `s7 alarms` | S7CommPlus: a message when a PLC alarm comes or goes (alarm subscription; the active alarms at start). |
|
|
86
87
|
| `s7 info` | Diagnostics. Both protocols: `status`, `cpuState`. S7comm: `identify`, `szl`, `szlList`, `clock`, `setClock`, `syncClock`, `blocks`, `listBlocks`, `blockInfo`. S7CommPlus: `info`, `dbs`, `browse`, `alarms`, `limits`. |
|
|
87
88
|
|
|
88
89
|
Every node has full help in the editor sidebar. Bad tags never stop the other tags: they give
|
|
@@ -150,8 +151,8 @@ This map shows each protocol function and where it is available. It is strict: a
|
|
|
150
151
|
| CPU operating state | read of the PLC program object | ✅ | `s7 info`: `cpuState` |
|
|
151
152
|
| Communication limits | read of the PLC limit attributes | ✅ | `s7 info`: `limits`, `info` |
|
|
152
153
|
| Active alarms | alarm objects and text libraries | ✅ | `s7 info`: `alarms` |
|
|
153
|
-
| Alarm subscription | CreateObject subscription, notifications |
|
|
154
|
-
| Variable subscription | CreateObject subscription, notifications |
|
|
154
|
+
| Alarm subscription | CreateObject alarm subscription (TIA Portal or S7CommPlusDriver layout), DAI notifications | ✅ | `s7 alarms` |
|
|
155
|
+
| Variable subscription | CreateObject subscription with a cycle time, notifications, credit limit | ✅ | `s7 watch` (mode "PLC subscription") |
|
|
155
156
|
| Set CPU operating state (RUN/STOP) | SetVariable 0x04F2 | 🔒 | — |
|
|
156
157
|
| Block upload / download, program changes | BeginSequence 0x0556, EndSequence 0x0560, Invoke 0x056B | ❌ | — |
|
|
157
158
|
| Links | AddLink 0x0506, RemoveLink 0x051A, GetLink 0x0524 | ❌ | — |
|
|
@@ -262,7 +263,9 @@ S7-1200 on the same LAN).
|
|
|
262
263
|
|
|
263
264
|
- The addon runs in the Node-RED process. A fatal error in native code stops Node-RED. The code
|
|
264
265
|
is safe Rust; the Node-API layer is the only FFI.
|
|
265
|
-
-
|
|
266
|
+
- `s7 watch`, mode "PLC subscription": the cycle time is the interval (100 ms or more; S7-1500
|
|
267
|
+
FW V4.x sends no changes without a cycle time). Each subscription uses one of the PLC
|
|
268
|
+
subscription resources (`s7 info` → `limits`); when the PLC refuses it, the node reads cyclically.
|
|
266
269
|
- S7CommPlus: the PLC certificate is not verified (TLS protects against passive capture only).
|
|
267
270
|
|
|
268
271
|
## Migration from @oriolrius/node-red-contrib-s7
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"id": "c5",
|
|
4
|
+
"type": "comment",
|
|
5
|
+
"name": "PLC alarms with s7 alarms (S7CommPlus)",
|
|
6
|
+
"info": "The node subscribes to the alarms of the CPU (Program_Alarm, ProDiag...).\nAt start it sends the active alarms (msg.initial = true), then one message per coming / going.\nmsg.topic is the alarm id, msg.state is coming or going, msg.payload has the times, the associated values and the texts.\nThe switch sends the coming alarms to the first output and the going alarms to the second one.",
|
|
7
|
+
"x": 230,
|
|
8
|
+
"y": 40,
|
|
9
|
+
"wires": []
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"id": "al5",
|
|
13
|
+
"type": "s7rs-alarms",
|
|
14
|
+
"name": "",
|
|
15
|
+
"endpoint": "ep5",
|
|
16
|
+
"initial": true,
|
|
17
|
+
"layout": "auto",
|
|
18
|
+
"x": 140,
|
|
19
|
+
"y": 100,
|
|
20
|
+
"wires": [
|
|
21
|
+
[
|
|
22
|
+
"sw5"
|
|
23
|
+
]
|
|
24
|
+
]
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"id": "sw5",
|
|
28
|
+
"type": "switch",
|
|
29
|
+
"name": "state",
|
|
30
|
+
"property": "state",
|
|
31
|
+
"propertyType": "msg",
|
|
32
|
+
"rules": [
|
|
33
|
+
{
|
|
34
|
+
"t": "eq",
|
|
35
|
+
"v": "coming",
|
|
36
|
+
"vt": "str"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"t": "eq",
|
|
40
|
+
"v": "going",
|
|
41
|
+
"vt": "str"
|
|
42
|
+
}
|
|
43
|
+
],
|
|
44
|
+
"checkall": "true",
|
|
45
|
+
"repair": false,
|
|
46
|
+
"outputs": 2,
|
|
47
|
+
"x": 310,
|
|
48
|
+
"y": 100,
|
|
49
|
+
"wires": [
|
|
50
|
+
[
|
|
51
|
+
"d5a"
|
|
52
|
+
],
|
|
53
|
+
[
|
|
54
|
+
"d5b"
|
|
55
|
+
]
|
|
56
|
+
]
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"id": "d5a",
|
|
60
|
+
"type": "debug",
|
|
61
|
+
"name": "coming",
|
|
62
|
+
"active": true,
|
|
63
|
+
"tosidebar": true,
|
|
64
|
+
"console": false,
|
|
65
|
+
"tostatus": false,
|
|
66
|
+
"complete": "payload",
|
|
67
|
+
"targetType": "msg",
|
|
68
|
+
"statusVal": "",
|
|
69
|
+
"statusType": "auto",
|
|
70
|
+
"x": 480,
|
|
71
|
+
"y": 80,
|
|
72
|
+
"wires": []
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"id": "d5b",
|
|
76
|
+
"type": "debug",
|
|
77
|
+
"name": "going",
|
|
78
|
+
"active": true,
|
|
79
|
+
"tosidebar": true,
|
|
80
|
+
"console": false,
|
|
81
|
+
"tostatus": false,
|
|
82
|
+
"complete": "payload",
|
|
83
|
+
"targetType": "msg",
|
|
84
|
+
"statusVal": "",
|
|
85
|
+
"statusType": "auto",
|
|
86
|
+
"x": 480,
|
|
87
|
+
"y": 120,
|
|
88
|
+
"wires": []
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
"id": "ep5",
|
|
92
|
+
"type": "s7rs-endpoint",
|
|
93
|
+
"name": "PLC (S7CommPlus, TLS)",
|
|
94
|
+
"protocol": "s7plus",
|
|
95
|
+
"host": "192.168.0.1",
|
|
96
|
+
"port": 102,
|
|
97
|
+
"cpu": "1500",
|
|
98
|
+
"rack": "",
|
|
99
|
+
"slot": "",
|
|
100
|
+
"link": "",
|
|
101
|
+
"localTsap": "",
|
|
102
|
+
"remoteTsap": "",
|
|
103
|
+
"pdu": "",
|
|
104
|
+
"timeout": 5000,
|
|
105
|
+
"attempts": 3,
|
|
106
|
+
"reconnect": 5000,
|
|
107
|
+
"gap": 5,
|
|
108
|
+
"byteOrder": "big",
|
|
109
|
+
"logLevel": "warn",
|
|
110
|
+
"tsap": "SIMATIC-ROOT-HMI",
|
|
111
|
+
"tls": true,
|
|
112
|
+
"username": ""
|
|
113
|
+
}
|
|
114
|
+
]
|
package/lib/napi-bridge.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
//
|
|
6
6
|
// API (Promise based, events 'status', 'data', 'log'):
|
|
7
7
|
// open(params) close(conn) read(conn, tags) write(conn, [{tag, value}])
|
|
8
|
-
// subscribe(params) unsubscribe(sub) status(conn) call(conn, action, args) stop()
|
|
8
|
+
// subscribe(params) subscribeAlarms(params) unsubscribe(sub) status(conn) call(conn, action, args) stop()
|
|
9
9
|
// acquire()/release(): one shared instance per Node-RED runtime.
|
|
10
10
|
|
|
11
11
|
const { EventEmitter } = require('node:events');
|
|
@@ -64,6 +64,12 @@ class NapiBridge extends EventEmitter {
|
|
|
64
64
|
this.native = new S7Native(
|
|
65
65
|
(conn, state, detail) => this.emit('status', { event: 'status', conn, state, detail }),
|
|
66
66
|
(ev) => {
|
|
67
|
+
if (ev.alarms !== undefined) {
|
|
68
|
+
if (!this.subTags.has(ev.sub)) return; // unsubscribed meanwhile
|
|
69
|
+
const a = JSON.parse(ev.alarms);
|
|
70
|
+
this.emit('alarms', { event: 'alarms', sub: ev.sub, conn: ev.conn, alarms: a.alarms, snapshot: a.snapshot, ts: ev.ts });
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
67
73
|
const tags = this.subTags.get(ev.sub);
|
|
68
74
|
if (!tags) return; // unsubscribed meanwhile
|
|
69
75
|
this.emit('data', { event: 'data', sub: ev.sub, conn: ev.conn, values: rows(tags, ev.vals, ev.errs, ev.idx), ts: ev.ts, ms: ev.ms });
|
|
@@ -105,13 +111,21 @@ class NapiBridge extends EventEmitter {
|
|
|
105
111
|
return { results, nativeMs: r.nativeMs };
|
|
106
112
|
}
|
|
107
113
|
|
|
108
|
-
// subscribe({conn, sub, tags, intervalMs, onChange, condTag, condIntervalMs}) -> {invalid}
|
|
114
|
+
// subscribe({conn, sub, tags, intervalMs, onChange, condTag, condIntervalMs, push}) -> {invalid}
|
|
109
115
|
async subscribe(p) {
|
|
110
116
|
this.start();
|
|
111
117
|
this.subTags.set(p.sub, p.tags);
|
|
112
118
|
return { invalid: await this.native.subscribe(p) };
|
|
113
119
|
}
|
|
114
120
|
|
|
121
|
+
// subscribeAlarms({conn, sub, initial, layout}): 'alarms' events {sub, conn, alarms, snapshot, ts};
|
|
122
|
+
// snapshot: a new PLC subscription (start or reconnect), the receiver forgets the alarms it knew
|
|
123
|
+
async subscribeAlarms(p) {
|
|
124
|
+
this.start();
|
|
125
|
+
this.subTags.set(p.sub, []);
|
|
126
|
+
this.native.subscribeAlarms(p);
|
|
127
|
+
}
|
|
128
|
+
|
|
115
129
|
async unsubscribe(sub) {
|
|
116
130
|
this.subTags.delete(sub);
|
|
117
131
|
if (this.native) this.native.unsubscribe(sub);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
<script type="text/html" data-help-name="s7rs-alarms">
|
|
2
|
+
<p>Sends a message when a PLC alarm comes or goes (S7CommPlus, S7-1200/1500). The PLC sends the
|
|
3
|
+
alarms: there is no polling.</p>
|
|
4
|
+
<h3>Outputs</h3>
|
|
5
|
+
<dl class="message-properties">
|
|
6
|
+
<dt>topic <span class="property-type">string</span></dt>
|
|
7
|
+
<dd>the alarm id (CPU alarm id, hex): source block RID and alarm number.</dd>
|
|
8
|
+
<dt>state <span class="property-type">string</span></dt>
|
|
9
|
+
<dd><code>coming</code> (the alarm is active) or <code>going</code>.</dd>
|
|
10
|
+
<dt>payload <span class="property-type">object</span></dt>
|
|
11
|
+
<dd>the alarm: <code>id</code>, <code>name</code>, <code>state</code>, <code>allStates</code>,
|
|
12
|
+
<code>coming</code> and <code>going</code> (<code>time</code>, <code>ackTime</code>,
|
|
13
|
+
<code>values</code>: the associated values as PLC bytes), <code>priority</code>,
|
|
14
|
+
<code>alarmClass</code>, <code>seq</code>, <code>texts</code> (<code>lang</code>, <code>id</code>,
|
|
15
|
+
<code>text</code>).</dd>
|
|
16
|
+
<dt class="optional">initial <span class="property-type">boolean</span></dt>
|
|
17
|
+
<dd>true for the alarms that were active when the subscription started.</dd>
|
|
18
|
+
<dt>ts <span class="property-type">string</span></dt>
|
|
19
|
+
<dd>receive time (ISO, UTC). The PLC time is in <code>payload.coming.time</code> or
|
|
20
|
+
<code>payload.going.time</code>.</dd>
|
|
21
|
+
</dl>
|
|
22
|
+
<h3>Details</h3>
|
|
23
|
+
<p>At start, and again after a reconnect, the node subscribes to the alarms of the CPU and
|
|
24
|
+
(option) sends the active alarms with <code>msg.initial</code>. Then one message per alarm
|
|
25
|
+
event. The node status shows the number of active alarms; it starts again from the PLC list on
|
|
26
|
+
each new subscription (alarms that went while the PLC was not reachable are gone). Without "send
|
|
27
|
+
the active alarms at start" it counts only the alarms that came since the last subscription.</p>
|
|
28
|
+
<h4>Subscription</h4>
|
|
29
|
+
<p>The CPU families need different subscription layouts. <b>automatic</b> uses the TIA Portal layout
|
|
30
|
+
for an S7-1200 and the S7CommPlusDriver layout for the other CPUs (an S7-1500 FW V4.x accepts the
|
|
31
|
+
TIA Portal layout but sends no alarms with it). Select a layout when the automatic one gets no
|
|
32
|
+
alarms.</p>
|
|
33
|
+
<p>Alarm texts come from the PLC when the project has them (alarm text of the Program_Alarm
|
|
34
|
+
instance). Acknowledging alarms is not supported.</p>
|
|
35
|
+
</script>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"s7rs-alarms": {
|
|
3
|
+
"label": {
|
|
4
|
+
"name": "Name",
|
|
5
|
+
"endpoint": "PLC",
|
|
6
|
+
"initial": "send the active alarms at start",
|
|
7
|
+
"layout": "Subscription"
|
|
8
|
+
},
|
|
9
|
+
"layout": {
|
|
10
|
+
"auto": "automatic (by CPU)",
|
|
11
|
+
"tia": "TIA Portal layout (S7-1200)",
|
|
12
|
+
"reference": "S7CommPlusDriver layout (S7-1500)"
|
|
13
|
+
},
|
|
14
|
+
"portLabel": {
|
|
15
|
+
"out": "alarm events"
|
|
16
|
+
},
|
|
17
|
+
"status": {
|
|
18
|
+
"active": "__n__ active"
|
|
19
|
+
},
|
|
20
|
+
"errors": {
|
|
21
|
+
"subscribe": "alarm subscription: __error__"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
<script type="text/html" data-help-name="s7rs-watch">
|
|
2
|
-
<p>
|
|
2
|
+
<p>Sends a message when a tag value changes: it reads the tags at a fixed interval, or
|
|
3
|
+
(S7CommPlus) the PLC sends the changes.</p>
|
|
3
4
|
<h3>Outputs</h3>
|
|
4
5
|
<dl class="message-properties">
|
|
5
6
|
<dt>payload <span class="property-type">any | object</span></dt>
|
|
@@ -10,7 +11,8 @@
|
|
|
10
11
|
<dt class="optional">changed <span class="property-type">array</span></dt>
|
|
11
12
|
<dd>all tags mode only: the tags that changed in this cycle.</dd>
|
|
12
13
|
<dt>ts <span class="property-type">string</span></dt>
|
|
13
|
-
<dd>start time of the read cycle (ISO, UTC)
|
|
14
|
+
<dd>start time of the read cycle (ISO, UTC). PLC subscription: the PLC time of the
|
|
15
|
+
notification, when the PLC sends one (S7-1500), else the receive time.</dd>
|
|
14
16
|
</dl>
|
|
15
17
|
<h3>Details</h3>
|
|
16
18
|
<p>A Rust thread reads the tags and compares the raw PLC bytes. Node-RED gets no message when
|
|
@@ -19,6 +21,12 @@
|
|
|
19
21
|
<h4>Fast while</h4>
|
|
20
22
|
<p>Conditional rate: while this tag is true (or not zero), the node reads every <code>N</code> ms
|
|
21
23
|
instead of the interval. The node does not send the condition tag, unless it is also in the list.</p>
|
|
22
|
-
<h4>
|
|
23
|
-
<p>
|
|
24
|
+
<h4>Mode</h4>
|
|
25
|
+
<p><b>read cyclically</b>: the node reads every interval (all protocols).</p>
|
|
26
|
+
<p><b>PLC subscription</b> (S7CommPlus): the node subscribes to the tags with the interval as
|
|
27
|
+
cycle time (100 ms or more). The PLC checks the tags each cycle and sends only the values that
|
|
28
|
+
changed, so there is no read request per cycle. The first message has all tags. "Fast while" and
|
|
29
|
+
"send only values that changed" do not apply. After a reconnect the node subscribes again. If
|
|
30
|
+
the PLC refuses the subscription (for example, no free subscription resources) or the protocol is
|
|
31
|
+
S7comm, the node reads cyclically and logs a warning (S7CommPlus).</p>
|
|
24
32
|
</script>
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
"name": "Name",
|
|
5
5
|
"endpoint": "PLC",
|
|
6
6
|
"tags": "Tags",
|
|
7
|
+
"mode": "Mode",
|
|
7
8
|
"interval": "Interval (ms)",
|
|
8
9
|
"condTag": "Fast while",
|
|
9
10
|
"onChange": "send only values that changed",
|
|
@@ -15,6 +16,10 @@
|
|
|
15
16
|
"condTag": "optional condition tag, e.g. M0.0",
|
|
16
17
|
"topic": "object mode only"
|
|
17
18
|
},
|
|
19
|
+
"mode": {
|
|
20
|
+
"poll": "read cyclically",
|
|
21
|
+
"push": "PLC subscription (S7CommPlus)"
|
|
22
|
+
},
|
|
18
23
|
"output": {
|
|
19
24
|
"each": "one message per tag (topic = tag)",
|
|
20
25
|
"object": "one message with all tags"
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
<script type="text/javascript">
|
|
2
|
+
RED.nodes.registerType('s7rs-alarms', {
|
|
3
|
+
category: 'network',
|
|
4
|
+
color: '#3FADB5',
|
|
5
|
+
defaults: {
|
|
6
|
+
name: { value: '' },
|
|
7
|
+
endpoint: { value: '', type: 's7rs-endpoint', required: true },
|
|
8
|
+
initial: { value: true },
|
|
9
|
+
layout: { value: 'auto' },
|
|
10
|
+
},
|
|
11
|
+
inputs: 0,
|
|
12
|
+
outputs: 1,
|
|
13
|
+
icon: 'font-awesome/fa-bell',
|
|
14
|
+
paletteLabel: 's7 alarms',
|
|
15
|
+
label: function () {
|
|
16
|
+
return this.name || 's7 alarms';
|
|
17
|
+
},
|
|
18
|
+
outputLabels: function () {
|
|
19
|
+
return this._('s7rs-alarms.portLabel.out');
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
</script>
|
|
23
|
+
|
|
24
|
+
<script type="text/html" data-template-name="s7rs-alarms">
|
|
25
|
+
<div class="form-row">
|
|
26
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="s7rs-alarms.label.name"></span></label>
|
|
27
|
+
<input type="text" id="node-input-name" />
|
|
28
|
+
</div>
|
|
29
|
+
<div class="form-row">
|
|
30
|
+
<label for="node-input-endpoint"><i class="fa fa-plug"></i> <span data-i18n="s7rs-alarms.label.endpoint"></span></label>
|
|
31
|
+
<input type="text" id="node-input-endpoint" />
|
|
32
|
+
</div>
|
|
33
|
+
<div class="form-row">
|
|
34
|
+
<label for="node-input-initial"> </label>
|
|
35
|
+
<input type="checkbox" id="node-input-initial" style="width: auto; display: inline-block" />
|
|
36
|
+
<span data-i18n="s7rs-alarms.label.initial"></span>
|
|
37
|
+
</div>
|
|
38
|
+
<div class="form-row">
|
|
39
|
+
<label for="node-input-layout" data-i18n="s7rs-alarms.label.layout"></label>
|
|
40
|
+
<select id="node-input-layout">
|
|
41
|
+
<option value="auto" data-i18n="s7rs-alarms.layout.auto"></option>
|
|
42
|
+
<option value="tia" data-i18n="s7rs-alarms.layout.tia"></option>
|
|
43
|
+
<option value="reference" data-i18n="s7rs-alarms.layout.reference"></option>
|
|
44
|
+
</select>
|
|
45
|
+
</div>
|
|
46
|
+
</script>
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// s7rs-alarms: a PLC alarm subscription (S7CommPlus). One message per alarm
|
|
3
|
+
// event (coming / going); the active alarms first, and again after a reconnect.
|
|
4
|
+
|
|
5
|
+
const { text, getEndpoint } = require('../lib/common');
|
|
6
|
+
|
|
7
|
+
module.exports = function (RED) {
|
|
8
|
+
function S7rsAlarms(config) {
|
|
9
|
+
RED.nodes.createNode(this, config);
|
|
10
|
+
const node = this;
|
|
11
|
+
const ep = getEndpoint(RED, node, config);
|
|
12
|
+
if (!ep) return;
|
|
13
|
+
const active = new Map(); // id -> alarm
|
|
14
|
+
|
|
15
|
+
const showCount = () =>
|
|
16
|
+
node.status({ fill: active.size ? 'yellow' : 'green', shape: 'dot', text: text(RED, 's7rs-alarms.status.active', { n: active.size }) });
|
|
17
|
+
|
|
18
|
+
const onAlarms = (ev) => {
|
|
19
|
+
if (ev.sub !== node.id) return;
|
|
20
|
+
// a new subscription (start or reconnect): the alarms that went meanwhile are gone
|
|
21
|
+
if (ev.snapshot) active.clear();
|
|
22
|
+
for (const a of ev.alarms) {
|
|
23
|
+
if (a.state === 'coming') active.set(a.id, a);
|
|
24
|
+
else active.delete(a.id);
|
|
25
|
+
const msg = { topic: a.id, payload: a, state: a.state, ts: ev.ts };
|
|
26
|
+
if (a.initial) msg.initial = true;
|
|
27
|
+
node.send(msg);
|
|
28
|
+
}
|
|
29
|
+
showCount();
|
|
30
|
+
};
|
|
31
|
+
ep.bridge.on('alarms', onAlarms);
|
|
32
|
+
|
|
33
|
+
ep.ready
|
|
34
|
+
.then(() =>
|
|
35
|
+
ep.bridge.subscribeAlarms({ conn: ep.id, sub: node.id, initial: config.initial !== false, layout: config.layout || 'auto' }),
|
|
36
|
+
)
|
|
37
|
+
.catch((err) => node.error(text(RED, 's7rs-alarms.errors.subscribe', { error: err.message })));
|
|
38
|
+
|
|
39
|
+
node.on('close', (removed, done) => {
|
|
40
|
+
ep.bridge.off('alarms', onAlarms);
|
|
41
|
+
ep.bridge
|
|
42
|
+
.unsubscribe(node.id)
|
|
43
|
+
.catch(() => {})
|
|
44
|
+
.finally(() => done());
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
RED.nodes.registerType('s7rs-alarms', S7rsAlarms);
|
|
48
|
+
};
|
package/nodes/s7rs-watch.html
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
topic: { value: '' },
|
|
13
13
|
condTag: { value: '' },
|
|
14
14
|
condInterval: { value: 100, validate: RED.validators.number(true) },
|
|
15
|
+
mode: { value: 'poll' },
|
|
15
16
|
},
|
|
16
17
|
inputs: 0,
|
|
17
18
|
outputs: 1,
|
|
@@ -19,7 +20,16 @@
|
|
|
19
20
|
paletteLabel: 's7 watch',
|
|
20
21
|
label: function () {
|
|
21
22
|
const n = (this.tags || '').split('\n').filter((s) => s.trim()).length;
|
|
22
|
-
|
|
23
|
+
const how = this.mode === 'push' ? 'sub' : '@';
|
|
24
|
+
return this.name || `s7 watch (${n} ${how} ${this.interval} ms)`;
|
|
25
|
+
},
|
|
26
|
+
oneditprepare: function () {
|
|
27
|
+
// a PLC subscription has no conditional rate and sends changes only
|
|
28
|
+
$('#node-input-mode')
|
|
29
|
+
.on('change', function () {
|
|
30
|
+
$('.s7rs-watch-poll').toggle($(this).val() !== 'push');
|
|
31
|
+
})
|
|
32
|
+
.trigger('change');
|
|
23
33
|
},
|
|
24
34
|
outputLabels: function () {
|
|
25
35
|
return this._('s7rs-watch.portLabel.out');
|
|
@@ -41,16 +51,23 @@
|
|
|
41
51
|
<textarea id="node-input-tags" rows="8" style="width: 70%; font-family: monospace"
|
|
42
52
|
data-i18n="[placeholder]s7rs-watch.placeholder.tags"></textarea>
|
|
43
53
|
</div>
|
|
54
|
+
<div class="form-row">
|
|
55
|
+
<label for="node-input-mode"><i class="fa fa-exchange"></i> <span data-i18n="s7rs-watch.label.mode"></span></label>
|
|
56
|
+
<select id="node-input-mode">
|
|
57
|
+
<option value="poll" data-i18n="s7rs-watch.mode.poll"></option>
|
|
58
|
+
<option value="push" data-i18n="s7rs-watch.mode.push"></option>
|
|
59
|
+
</select>
|
|
60
|
+
</div>
|
|
44
61
|
<div class="form-row">
|
|
45
62
|
<label for="node-input-interval"><i class="fa fa-clock-o"></i> <span data-i18n="s7rs-watch.label.interval"></span></label>
|
|
46
63
|
<input type="text" id="node-input-interval" style="width: 80px" />
|
|
47
64
|
</div>
|
|
48
|
-
<div class="form-row">
|
|
65
|
+
<div class="form-row s7rs-watch-poll">
|
|
49
66
|
<label for="node-input-condTag"><i class="fa fa-bolt"></i> <span data-i18n="s7rs-watch.label.condTag"></span></label>
|
|
50
67
|
<input type="text" id="node-input-condTag" data-i18n="[placeholder]s7rs-watch.placeholder.condTag" style="width: 45%; font-family: monospace" />
|
|
51
68
|
<input type="text" id="node-input-condInterval" style="width: 60px" /> ms
|
|
52
69
|
</div>
|
|
53
|
-
<div class="form-row">
|
|
70
|
+
<div class="form-row s7rs-watch-poll">
|
|
54
71
|
<label for="node-input-onChange"> </label>
|
|
55
72
|
<input type="checkbox" id="node-input-onChange" style="width: auto; display: inline-block" />
|
|
56
73
|
<span data-i18n="s7rs-watch.label.onChange"></span>
|
package/nodes/s7rs-watch.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
// s7rs-watch: a Rust thread reads the tags at a fixed (or conditional) rate
|
|
3
|
-
//
|
|
2
|
+
// s7rs-watch: a Rust thread reads the tags at a fixed (or conditional) rate, or
|
|
3
|
+
// (mode push, S7CommPlus) a PLC subscription sends the changes; the node sends
|
|
4
|
+
// only the values that changed.
|
|
4
5
|
|
|
5
6
|
const { text, parseTags, getEndpoint } = require('../lib/common');
|
|
6
7
|
|
|
@@ -53,6 +54,8 @@ module.exports = function (RED) {
|
|
|
53
54
|
// conditional rate: while condTag is true (or non-zero), read every condInterval ms
|
|
54
55
|
condTag: String(config.condTag || '').trim() || undefined,
|
|
55
56
|
condIntervalMs: Number(config.condInterval) || 100,
|
|
57
|
+
// PLC subscription with the interval as cycle time (falls back to cyclic reads)
|
|
58
|
+
push: config.mode === 'push',
|
|
56
59
|
};
|
|
57
60
|
ep.ready
|
|
58
61
|
.then(() => ep.bridge.subscribe(params))
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-red-contrib-s7-rust",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Siemens S7 nodes for Node-RED: S7comm and S7CommPlus (S7-1200/1500 symbolic access) clients written in Rust, running in-process (Node-API). Linux x64.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"node-red",
|
|
@@ -55,7 +55,8 @@
|
|
|
55
55
|
"s7rs-read": "nodes/s7rs-read.js",
|
|
56
56
|
"s7rs-write": "nodes/s7rs-write.js",
|
|
57
57
|
"s7rs-watch": "nodes/s7rs-watch.js",
|
|
58
|
-
"s7rs-info": "nodes/s7rs-info.js"
|
|
58
|
+
"s7rs-info": "nodes/s7rs-info.js",
|
|
59
|
+
"s7rs-alarms": "nodes/s7rs-alarms.js"
|
|
59
60
|
}
|
|
60
61
|
},
|
|
61
62
|
"scripts": {
|