node-red-contrib-s7-rust 1.2.2 → 1.3.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 CHANGED
@@ -6,6 +6,55 @@ All notable changes to this project are documented here. The format follows
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.3.0] - 2026-11-13
10
+
11
+ ### Added
12
+
13
+ - `s7 alarms`: acknowledges alarms. An input message with `msg.ack` (an alarm id `"0x…"`, a list of
14
+ ids, or `"all"` / `true`: every alarm that waits for acknowledgement) acknowledges the coming
15
+ state, as the TIA Portal alarm display does. The node sends `state: "acknowledged"` or
16
+ `"ackFailed"` (`payload.ackResult`: the PLC refuses an alarm whose class needs no
17
+ acknowledgement) per alarm. Alarm messages have `payload.acknowledged`. An alarm that went
18
+ before its acknowledgement stays in the node list until it is acknowledged (the PLC keeps it
19
+ too); the status shows the active alarms and how many wait for acknowledgement.
20
+ - `s7 info`: action `acknowledge {ids, all}` (writes; the admin API refuses it).
21
+ - Rust crate `s7plus`: `Client::acknowledge_alarms` (CreateObject of an AckJob, class 3636, under
22
+ the alarm subsystem; at most 100 alarms per job, like TIA Portal), `decode_ack_job`,
23
+ `AckResult`; arrays of structs (dynamic array, flags 0x20) are encoded and decoded with the
24
+ struct id once after the datatype, then the count and the members of each element. The fake
25
+ PLC has alarms with acknowledgement (`raise_alarm_ack`) and answers AckJobs.
26
+ - `test/plcsim`: `set-alarm-class.ps1` and `alarm-classes.xlsx` give `alReq` the alarm class
27
+ "Acknowledgement"; `live_alarms.js` acknowledges it. Tested on PLCSIM Advanced V8 (S7-1500,
28
+ FW S4.1): acknowledged in about 15 ms; an alarm of a class without acknowledgement gives
29
+ `ackFailed` (0x8005).
30
+ - BSEND / BRCV (S7 communication over an S7 connection): the endpoint protocol "S7 partner" and
31
+ two nodes. `s7 brcv` sends a message for each block of a PLC `BSEND` (`msg.payload` Buffer,
32
+ `msg.rid`; filter by R_ID); `s7 bsend` sends `msg.payload` (Buffer, byte array or string) to a
33
+ PLC `BRCV` with the R_ID of the node or `msg.rid`. Blocks up to 65534 bytes, in fragments of
34
+ the PDU size. Node-RED connects actively with the TSAPs of the S7 connection and connects again
35
+ after a loss. Blocks that come before the first `s7 brcv` node starts go to that node.
36
+ - Rust crate `s7`: `partner::Partner` (connect, `recv`, `send`) and a fake PLC
37
+ (`partner_fake`). The acknowledgement of a fragmented block carries the IDSeq of the fragments
38
+ as its sequence and the PDU reference of the request, as an S7-1500 does (snap7 uses a new
39
+ sequence; PLCSIM then stops after the first fragment).
40
+ - `test/plcsim`: FB `PartnerComm`, DBs `PartnerData` / `PartnerComm_DB`, `add-s7-connection.ps1`
41
+ (TIA Portal Openness: S7 connection to an unspecified partner), `download-hw-sw.ps1` (download
42
+ with the hardware configuration; the TIA Portal MCP loads the software only) and
43
+ `live_partner.js`. Tested on PLCSIM Advanced V8 (S7-1500, FW S4.1): 16 and 1800 bytes both
44
+ ways.
45
+ - Example flow "06 - BSEND and BRCV".
46
+ - `s7 info` (S7CommPlus), read only, also in the admin API:
47
+ - `resolve {name}`: the object id (RID) of a DB, FB, FC, OB or technology object by its name,
48
+ asked to the PLC (GetVariablesAddress 0x0590 with the object path
49
+ `ASRoot.PLCProgram.<name>`, as TIA Portal does for technology objects); `{path}` takes any
50
+ object path (`"ASRoot"`, `"ASRoot.PLCProgram"`). `rid` is null when the PLC has no such
51
+ object.
52
+ - `links {rid, aid}`: the objects that a relation of an object points to (GetLink 0x0524), for
53
+ example rid 8, aid 2667: the active alarm instances.
54
+ - Rust crate `s7plus`: `Client::resolve_object`, `Client::get_links`, `program_object_path`. The
55
+ request and response layouts were found on PLCSIM Advanced V8 (S7-1500, FW S4.1); the fake PLC
56
+ answers both with the PLCSIM bytes.
57
+
9
58
  ## [1.2.2] - 2026-11-12
10
59
 
11
60
  ### Fixed
@@ -187,7 +236,8 @@ First release: the next generation of `@oriolrius/node-red-contrib-s7`.
187
236
  - CI: tests on Node-RED 4 and 5, gitleaks, GitGuardian, RustSec and npm audit, CodeQL,
188
237
  OpenSSF Scorecard, Dependabot. License LGPL-3.0-only.
189
238
 
190
- [Unreleased]: https://github.com/oriolrius/node-red-contrib-s7-rust/compare/v1.2.2...HEAD
239
+ [Unreleased]: https://github.com/oriolrius/node-red-contrib-s7-rust/compare/v1.3.0...HEAD
240
+ [1.3.0]: https://github.com/oriolrius/node-red-contrib-s7-rust/compare/v1.2.2...v1.3.0
191
241
  [1.2.2]: https://github.com/oriolrius/node-red-contrib-s7-rust/compare/v1.2.1...v1.2.2
192
242
  [1.2.1]: https://github.com/oriolrius/node-red-contrib-s7-rust/compare/v1.2.0...v1.2.1
193
243
  [1.2.0]: https://github.com/oriolrius/node-red-contrib-s7-rust/compare/v1.1.0...v1.2.0
package/README.md CHANGED
@@ -83,8 +83,10 @@ Then restart Node-RED. The nodes are in the **network** category of the palette.
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
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). |
87
- | `s7 info` | Diagnostics. Both protocols: `status`, `cpuState`. S7comm: `identify`, `szl`, `szlList`, `clock`, `setClock`, `syncClock`, `blocks`, `listBlocks`, `blockInfo`. S7CommPlus: `info`, `certificate`, `dbs`, `browse`, `alarms`, `limits`. |
86
+ | `s7 alarms` | S7CommPlus: a message when a PLC alarm comes or goes (alarm subscription; the active alarms at start). `msg.ack` acknowledges alarms. |
87
+ | `s7 info` | Diagnostics. Both protocols: `status`, `cpuState`. S7comm: `identify`, `szl`, `szlList`, `clock`, `setClock`, `syncClock`, `blocks`, `listBlocks`, `blockInfo`. S7CommPlus: `info`, `certificate`, `dbs`, `browse`, `alarms`, `limits`, `resolve`, `links`. |
88
+ | `s7 bsend` | Sends `msg.payload` as a block to a PLC `BRCV` (S7 connection, protocol "S7 partner"). Writes to the PLC. |
89
+ | `s7 brcv` | A message for each block of a PLC `BSEND` (S7 connection, protocol "S7 partner"). |
88
90
 
89
91
  Every node has full help in the editor sidebar. Bad tags never stop the other tags: they give
90
92
  `null` and an entry in `msg.s7.errors`, or `msg.quality = "bad"` in a watch.
@@ -131,7 +133,8 @@ This map shows each protocol function and where it is available. It is strict: a
131
133
  | Alarms and messages | userdata group 4 alarm subfunctions, NOTIFY, ALARM_S/ALARM_8 | ❌ | — |
132
134
  | Protection level password | userdata group 5 (security) | ❌ | — |
133
135
  | Programmer commands, force | userdata group 1 | ❌ | — |
134
- | BSEND/BRCV, USEND/URCV | userdata group 6 | ❌ | — |
136
+ | BSEND/BRCV | userdata group 6 (type/group 0x46 / 0x86), fragments of the PDU size, blocks up to 65534 bytes, over an S7 connection (Node-RED active, TSAPs of the connection) | ✅ | `s7 bsend`, `s7 brcv` (endpoint protocol "S7 partner") |
137
+ | USEND/URCV | userdata group 6, unacknowledged | ❌ | — |
135
138
  | S7 routing to other subnets | COTP with routing parameters | ❌ | — |
136
139
 
137
140
  ### S7CommPlus (crate `s7plus`)
@@ -152,11 +155,13 @@ This map shows each protocol function and where it is available. It is strict: a
152
155
  | Communication limits | read of the PLC limit attributes | ✅ | `s7 info`: `limits`, `info` |
153
156
  | Active alarms | alarm objects and text libraries | ✅ | `s7 info`: `alarms` |
154
157
  | Alarm subscription | CreateObject alarm subscription (TIA Portal or S7CommPlusDriver layout), DAI notifications | ✅ | `s7 alarms` |
158
+ | Alarm acknowledgement | CreateObject AckJob (class 3636) under the alarm subsystem, AcknowledgementList (dynamic array of struct 7604); the result comes back as an AckJob notification | ✅ | `s7 alarms` (`msg.ack`), `s7 info`: `acknowledge` |
155
159
  | Variable subscription | CreateObject subscription with a cycle time, notifications, credit limit | ✅ | `s7 watch` (mode "PLC subscription") |
156
160
  | Set CPU operating state (RUN/STOP) | SetVariable 0x04F2 | 🔒 | — |
157
161
  | Block upload / download, program changes | BeginSequence 0x0556, EndSequence 0x0560, Invoke 0x056B | ❌ | — |
158
- | Links | AddLink 0x0506, RemoveLink 0x051A, GetLink 0x0524 | ❌ | — |
159
- | GetVariablesAddress | 0x0590 | ❌ | — |
162
+ | Object relations (read) | GetLink 0x0524: object id, relation id → linked object ids | ✅ | `s7 info`: `links` |
163
+ | Object path resolution | GetVariablesAddress 0x0590: OMS object path (`ASRoot.PLCProgram.<name>`) → object id | ✅ | `s7 info`: `resolve` |
164
+ | Add / remove relations | AddLink 0x0506, RemoveLink 0x051A | ❌ | — (change the object model; no TIA Portal tool uses them) |
160
165
 
161
166
  ## Prepare the PLC
162
167
 
@@ -192,6 +197,15 @@ check fails, the endpoint stays disconnected and the error shows the fingerprint
192
197
  from the PLC* then shows the refused certificate with a warning (`refused: true`), so a new PLC
193
198
  certificate can be checked and taken over.
194
199
 
200
+ **S7 partner (BSEND/BRCV)**: the PLC program sends and receives data blocks with `BSEND` /
201
+ `BRCV` over an S7 connection; Node-RED is the partner. In TIA Portal, add an S7 connection to an
202
+ unspecified partner (Devices & networks → Connections), with the active connection establishment on
203
+ the partner side, clear "SIMATIC-ACC" to get numeric TSAPs, and set the partner address to the
204
+ address the PLC sees for Node-RED. Load the hardware configuration (the connection is part of it).
205
+ In the endpoint select "S7 partner" and enter the TSAPs of the connection: local = the partner
206
+ TSAP (for example `03.00`), remote = the PLC TSAP (for example `10.01`). `BSEND` / `BRCV` use the
207
+ connection ID of TIA Portal and an R_ID that both sides agree on.
208
+
195
209
  ## Addresses
196
210
 
197
211
  One address per line in the node, or in `msg.tags` / `msg.topic`.
@@ -256,6 +270,10 @@ All examples use the address `192.168.0.1`. Change it in the endpoint.
256
270
  - The nodes **cannot** stop or start the CPU and **cannot** upload blocks. The Rust crates have
257
271
  these functions, but the addon does not expose them.
258
272
  - `setClock` and `syncClock` change the PLC clock. The admin API refuses them.
273
+ - `s7 alarms` acknowledges alarms when a message with `msg.ack` arrives (a write to the PLC), never
274
+ by itself. `s7 info` action `acknowledge` does the same; the admin API refuses it.
275
+ - `s7 bsend` sends a data block to a `BRCV` of the PLC program (the program decides what to do
276
+ with it).
259
277
  - `s7 write` writes to the PLC at once. Test on a simulator (for example PLCSIM Advanced) before
260
278
  you write to a machine.
261
279
 
Binary file
Binary file
@@ -0,0 +1,119 @@
1
+ [
2
+ {
3
+ "id": "c6",
4
+ "type": "comment",
5
+ "name": "BSEND / BRCV with an S7 connection",
6
+ "info": "In TIA Portal: Devices & networks > Connections: add an S7 connection to an unspecified partner\n(partner address = the Node-RED host), not 'active connection setup' on the PLC side.\nSet the endpoint protocol to 'S7 partner' and the TSAPs of the connection\n(local = the partner TSAP, for example 03.00; remote = the PLC TSAP, for example 10.01).\n\ns7 brcv sends a message for each block of a PLC BSEND (msg.payload Buffer, msg.rid).\ns7 bsend sends msg.payload (Buffer, byte array or string) to a PLC BRCV with R_ID 1.\nThe bsend node writes to the PLC.",
7
+ "x": 240,
8
+ "y": 40,
9
+ "wires": []
10
+ },
11
+ {
12
+ "id": "rx6",
13
+ "type": "s7rs-brcv",
14
+ "name": "",
15
+ "endpoint": "ep6",
16
+ "rid": "",
17
+ "x": 140,
18
+ "y": 100,
19
+ "wires": [
20
+ [
21
+ "d6"
22
+ ]
23
+ ]
24
+ },
25
+ {
26
+ "id": "d6",
27
+ "type": "debug",
28
+ "name": "blocks from the PLC",
29
+ "active": true,
30
+ "tosidebar": true,
31
+ "console": false,
32
+ "tostatus": false,
33
+ "complete": "true",
34
+ "targetType": "full",
35
+ "statusVal": "",
36
+ "statusType": "auto",
37
+ "x": 380,
38
+ "y": 100,
39
+ "wires": []
40
+ },
41
+ {
42
+ "id": "i6",
43
+ "type": "inject",
44
+ "name": "send 4 bytes",
45
+ "props": [
46
+ {
47
+ "p": "payload"
48
+ }
49
+ ],
50
+ "repeat": "",
51
+ "crontab": "",
52
+ "once": false,
53
+ "onceDelay": 0.1,
54
+ "topic": "",
55
+ "payload": "[1,2,3,4]",
56
+ "payloadType": "json",
57
+ "x": 150,
58
+ "y": 160,
59
+ "wires": [
60
+ [
61
+ "tx6"
62
+ ]
63
+ ]
64
+ },
65
+ {
66
+ "id": "tx6",
67
+ "type": "s7rs-bsend",
68
+ "name": "",
69
+ "endpoint": "ep6",
70
+ "rid": "1",
71
+ "x": 340,
72
+ "y": 160,
73
+ "wires": [
74
+ [
75
+ "d7"
76
+ ]
77
+ ]
78
+ },
79
+ {
80
+ "id": "d7",
81
+ "type": "debug",
82
+ "name": "sent",
83
+ "active": true,
84
+ "tosidebar": true,
85
+ "console": false,
86
+ "tostatus": false,
87
+ "complete": "s7",
88
+ "targetType": "msg",
89
+ "statusVal": "",
90
+ "statusType": "auto",
91
+ "x": 520,
92
+ "y": 160,
93
+ "wires": []
94
+ },
95
+ {
96
+ "id": "ep6",
97
+ "type": "s7rs-endpoint",
98
+ "name": "PLC (S7 partner)",
99
+ "protocol": "s7partner",
100
+ "host": "192.168.0.1",
101
+ "port": 102,
102
+ "cpu": "1500",
103
+ "rack": "",
104
+ "slot": "",
105
+ "link": "",
106
+ "localTsap": "03.00",
107
+ "remoteTsap": "10.01",
108
+ "pdu": "",
109
+ "timeout": 5000,
110
+ "attempts": 3,
111
+ "reconnect": 5000,
112
+ "gap": 5,
113
+ "byteOrder": "big",
114
+ "logLevel": "warn",
115
+ "tsap": "SIMATIC-ROOT-HMI",
116
+ "tls": false,
117
+ "username": ""
118
+ }
119
+ ]
@@ -56,6 +56,7 @@ class NapiBridge extends EventEmitter {
56
56
  this.setMaxListeners(0);
57
57
  this.native = null;
58
58
  this.subTags = new Map(); // sub -> tags (the addon sends columns, not tag names)
59
+ this.blockSubs = new Set(); // s7 brcv subscriptions (S7 partner endpoints)
59
60
  }
60
61
 
61
62
  start() {
@@ -67,6 +68,10 @@ class NapiBridge extends EventEmitter {
67
68
  if (ev.alarms !== undefined) {
68
69
  if (!this.subTags.has(ev.sub)) return; // unsubscribed meanwhile
69
70
  const a = JSON.parse(ev.alarms);
71
+ if (this.blockSubs.has(ev.sub)) {
72
+ for (const b of a.alarms) this.emit('blocks', { event: 'blocks', sub: ev.sub, conn: ev.conn, rid: b.rid, data: Buffer.from(b.data, 'hex'), ts: ev.ts });
73
+ return;
74
+ }
70
75
  this.emit('alarms', { event: 'alarms', sub: ev.sub, conn: ev.conn, alarms: a.alarms, snapshot: a.snapshot, ts: ev.ts });
71
76
  return;
72
77
  }
@@ -126,8 +131,18 @@ class NapiBridge extends EventEmitter {
126
131
  this.native.subscribeAlarms(p);
127
132
  }
128
133
 
134
+ // subscribeBlocks({conn, sub}): 'blocks' events {sub, conn, rid, data (Buffer), ts}: the blocks
135
+ // of the PLC BSEND on an S7 partner endpoint
136
+ async subscribeBlocks(p) {
137
+ this.start();
138
+ this.subTags.set(p.sub, []);
139
+ this.blockSubs.add(p.sub);
140
+ this.native.subscribeBlocks(p.conn, p.sub);
141
+ }
142
+
129
143
  async unsubscribe(sub) {
130
144
  this.subTags.delete(sub);
145
+ this.blockSubs.delete(sub);
131
146
  if (this.native) this.native.unsubscribe(sub);
132
147
  }
133
148
 
@@ -1,18 +1,29 @@
1
1
  <script type="text/html" data-help-name="s7rs-alarms">
2
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>
3
+ alarms: there is no polling. An input message acknowledges alarms.</p>
4
+ <h3>Inputs</h3>
5
+ <dl class="message-properties">
6
+ <dt>ack <span class="property-type">string | array | boolean</span></dt>
7
+ <dd>acknowledges alarms (the coming state): an alarm id (<code>msg.topic</code> of an alarm
8
+ message, <code>"0x…"</code>), a list of ids, or <code>"all"</code> / <code>true</code>: every
9
+ active alarm that waits for acknowledgement. <b>This writes to the PLC.</b> The result comes as
10
+ output messages.</dd>
11
+ </dl>
4
12
  <h3>Outputs</h3>
5
13
  <dl class="message-properties">
6
14
  <dt>topic <span class="property-type">string</span></dt>
7
15
  <dd>the alarm id (CPU alarm id, hex): source block RID and alarm number.</dd>
8
16
  <dt>state <span class="property-type">string</span></dt>
9
- <dd><code>coming</code> (the alarm is active) or <code>going</code>.</dd>
17
+ <dd><code>coming</code> (the alarm is active), <code>going</code>, <code>acknowledged</code> or
18
+ <code>ackFailed</code> (the result of <code>msg.ack</code>; <code>payload.ackResult</code> is the
19
+ PLC code: the PLC refuses an alarm whose class needs no acknowledgement).</dd>
10
20
  <dt>payload <span class="property-type">object</span></dt>
11
21
  <dd>the alarm: <code>id</code>, <code>name</code>, <code>state</code>, <code>allStates</code>,
12
22
  <code>coming</code> and <code>going</code> (<code>time</code>, <code>ackTime</code>,
13
23
  <code>values</code>: the associated values as PLC bytes), <code>priority</code>,
14
24
  <code>alarmClass</code>, <code>seq</code>, <code>texts</code> (<code>lang</code>, <code>id</code>,
15
- <code>text</code>).</dd>
25
+ <code>text</code>), <code>acknowledged</code> (false: the alarm waits for acknowledgement; always
26
+ true for an alarm class without acknowledgement).</dd>
16
27
  <dt class="optional">initial <span class="property-type">boolean</span></dt>
17
28
  <dd>true for the alarms that were active when the subscription started.</dd>
18
29
  <dt>ts <span class="property-type">string</span></dt>
@@ -31,5 +42,11 @@
31
42
  TIA Portal layout but sends no alarms with it). Select a layout when the automatic one gets no
32
43
  alarms.</p>
33
44
  <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>
45
+ instance).</p>
46
+ <h4>Acknowledgement</h4>
47
+ <p>Only alarms of an alarm class with acknowledgement (TIA Portal class "Acknowledgement") need it.
48
+ The PLC acknowledges the coming state, as the TIA Portal alarm display does. An alarm that went
49
+ before the acknowledgement still waits for it (the PLC keeps it in its list). The node status shows
50
+ the active alarms and how many alarms wait for acknowledgement. The PLC sends no new coming/going message for
51
+ the acknowledgement: the node sends <code>acknowledged</code> and updates its list.</p>
35
52
  </script>
@@ -12,13 +12,17 @@
12
12
  "reference": "S7CommPlusDriver layout (S7-1500)"
13
13
  },
14
14
  "portLabel": {
15
+ "in": "msg.ack: acknowledge",
15
16
  "out": "alarm events"
16
17
  },
17
18
  "status": {
18
- "active": "__n__ active"
19
+ "active": "__n__ active",
20
+ "unack": "__n__ active, __u__ to acknowledge"
19
21
  },
20
22
  "errors": {
21
- "subscribe": "alarm subscription: __error__"
23
+ "subscribe": "alarm subscription: __error__",
24
+ "ack": "acknowledge: __error__",
25
+ "noAck": "no msg.ack: set an alarm id (\"0x…\"), a list of ids, or \"all\""
22
26
  }
23
27
  }
24
28
  }
@@ -0,0 +1,22 @@
1
+ <script type="text/html" data-help-name="s7rs-brcv">
2
+ <p>Receives the data blocks that the PLC sends with <code>BSEND</code> (S7 communication over an
3
+ S7 connection). One message per block. The endpoint must use the protocol <i>S7 partner
4
+ (BSEND/BRCV)</i>.</p>
5
+ <h3>Outputs</h3>
6
+ <dl class="message-properties">
7
+ <dt>payload <span class="property-type">Buffer</span></dt>
8
+ <dd>the bytes of the block (up to 65534).</dd>
9
+ <dt>rid <span class="property-type">number</span></dt>
10
+ <dd>the R_ID of the BSEND call; also in <code>msg.topic</code> as text.</dd>
11
+ <dt>ts <span class="property-type">string</span></dt>
12
+ <dd>receive time (ISO, UTC).</dd>
13
+ </dl>
14
+ <h3>Details</h3>
15
+ <p><b>R_ID</b>: only blocks with this R_ID; empty: every block. Several nodes on one endpoint each
16
+ get every block.</p>
17
+ <p>The PLC sends only while Node-RED is connected: a BSEND without a connection ends with an error
18
+ in the PLC (STATUS of BSEND). Blocks that come before the first <code>s7 brcv</code> node of the
19
+ endpoint starts go to that node (at most 100).</p>
20
+ <p>Decode the bytes with a function node (<code>msg.payload.readInt16BE(0)</code>, …): the PLC sends
21
+ the memory of its BSEND area in S7 byte order (big endian).</p>
22
+ </script>
@@ -0,0 +1,8 @@
1
+ {
2
+ "s7rs-brcv": {
3
+ "label": { "name": "Name", "endpoint": "PLC (S7 partner)" },
4
+ "placeholder": { "rid": "empty: every R_ID" },
5
+ "status": { "count": "__n__ blocks" },
6
+ "errors": { "subscribe": "BRCV: __error__" }
7
+ }
8
+ }
@@ -0,0 +1,22 @@
1
+ <script type="text/html" data-help-name="s7rs-bsend">
2
+ <p>Sends <code>msg.payload</code> as a data block to a PLC <code>BRCV</code> (S7 communication over
3
+ an S7 connection). <b>This writes to the PLC.</b> The endpoint must use the protocol <i>S7 partner
4
+ (BSEND/BRCV)</i>.</p>
5
+ <h3>Inputs</h3>
6
+ <dl class="message-properties">
7
+ <dt>payload <span class="property-type">Buffer | array | string</span></dt>
8
+ <dd>the block: a Buffer, an array of bytes, or a string (sent as UTF-8); 1..65534 bytes.</dd>
9
+ <dt class="optional">rid <span class="property-type">number</span></dt>
10
+ <dd>the R_ID of the BRCV call in the PLC (when the node has no R_ID).</dd>
11
+ </dl>
12
+ <h3>Outputs</h3>
13
+ <dl class="message-properties">
14
+ <dt>s7 <span class="property-type">object</span></dt>
15
+ <dd><code>rid</code>, <code>bytes</code>, <code>ms</code>: the message passes when the PLC
16
+ acknowledged every fragment.</dd>
17
+ </dl>
18
+ <h3>Details</h3>
19
+ <p>The PLC must call <code>BRCV</code> with <code>EN_R = TRUE</code> and the same R_ID; otherwise
20
+ it refuses the block and the node reports an error. Blocks larger than one PDU are sent in
21
+ fragments.</p>
22
+ </script>
@@ -0,0 +1,11 @@
1
+ {
2
+ "s7rs-bsend": {
3
+ "label": { "name": "Name", "endpoint": "PLC (S7 partner)" },
4
+ "placeholder": { "rid": "empty: msg.rid" },
5
+ "errors": {
6
+ "noEndpoint": "no S7 endpoint configured",
7
+ "rid": "no R_ID: set it in the node or in msg.rid (0..4294967295)",
8
+ "payload": "msg.payload must be a Buffer, a byte array or a string of 1..65534 bytes"
9
+ }
10
+ }
11
+ }
@@ -35,6 +35,15 @@
35
35
  certificate).</p>
36
36
  <p>Some CPUs accept only TLS sessions (for example PLCSIM Advanced V8, FW S4.1). If the
37
37
  connection fails with "the PLC refused the session without TLS", turn on TLS.</p>
38
+ <h4>S7 partner (BSEND/BRCV)</h4>
39
+ <p>Block transfer with the PLC instructions <code>BSEND</code> / <code>BRCV</code> over an S7
40
+ connection, for the nodes <code>s7 bsend</code> and <code>s7 brcv</code>. In TIA Portal: add an S7
41
+ connection to an unspecified partner, with the active connection establishment on the partner
42
+ side (not on the PLC), and use its ID in BSEND / BRCV. Node-RED connects to the PLC with the
43
+ TSAPs of that connection: local = the partner TSAP, remote = the PLC TSAP (S7-1500 numeric
44
+ TSAPs: clear "SIMATIC-ACC" in the connection properties). The partner address of the connection
45
+ must be the address the PLC sees for Node-RED. The connection is loaded with the hardware
46
+ configuration.</p>
38
47
  <h4>Log</h4>
39
48
  <p>Messages go to the Node-RED log. <code>trace</code> logs every frame in hex.</p>
40
49
  <h3>References</h3>
@@ -27,7 +27,8 @@
27
27
  },
28
28
  "protocol": {
29
29
  "s7": "S7comm (classic, PUT/GET)",
30
- "s7plus": "S7CommPlus (S7-1200/1500, symbols)"
30
+ "s7plus": "S7CommPlus (S7-1200/1500, symbols)",
31
+ "s7partner": "S7 partner (BSEND/BRCV over an S7 connection)"
31
32
  },
32
33
  "certVerify": {
33
34
  "none": "not checked",
@@ -60,7 +61,8 @@
60
61
  "certName": "empty: the host (IP address or DNS name)"
61
62
  },
62
63
  "hint": {
63
- "gap": "merge reads closer than N bytes; -1 = off"
64
+ "gap": "merge reads closer than N bytes; -1 = off",
65
+ "partner": "TSAPs of the S7 connection in TIA Portal: local = partner TSAP (e.g. 03.00), remote = PLC TSAP (e.g. 10.01)"
64
66
  },
65
67
  "errors": {
66
68
  "open": "S7 __host__: __error__"
@@ -37,6 +37,15 @@
37
37
  (then <code>error</code> has the reason)</li>
38
38
  <li><code>dbs</code>: data blocks; <code>browse</code>: all symbols with their types</li>
39
39
  <li><code>alarms {all}</code>: active alarms; <code>limits</code>: system limits</li>
40
+ <li><code>acknowledge {ids, all}</code>: acknowledges alarms (ids <code>"0x…"</code>, or
41
+ <code>all: true</code> for every alarm that waits). <b>Writes to the PLC.</b> Returns
42
+ <code>sent</code>; the result comes through <code>s7 alarms</code>.</li>
43
+ <li><code>resolve {name}</code>: the object id (RID) of a DB, FB, FC, OB or technology object
44
+ by its name, from the PLC (<code>{path}</code>: an object path such as
45
+ <code>"ASRoot.PLCProgram"</code>); <code>rid</code> is null when the PLC has no such object.
46
+ Variables inside a DB are not objects.</li>
47
+ <li><code>links {rid, aid}</code>: the objects that a relation of an object points to (for
48
+ example rid 8, aid 2667: the active alarm instances).</li>
40
49
  </ul>
41
50
  <p><code>setClock</code> and <code>syncClock</code> change the PLC clock. STOP/START of the CPU and
42
51
  block upload are not available.</p>
@@ -8,13 +8,16 @@
8
8
  initial: { value: true },
9
9
  layout: { value: 'auto' },
10
10
  },
11
- inputs: 0,
11
+ inputs: 1,
12
12
  outputs: 1,
13
13
  icon: 'font-awesome/fa-bell',
14
14
  paletteLabel: 's7 alarms',
15
15
  label: function () {
16
16
  return this.name || 's7 alarms';
17
17
  },
18
+ inputLabels: function () {
19
+ return this._('s7rs-alarms.portLabel.in');
20
+ },
18
21
  outputLabels: function () {
19
22
  return this._('s7rs-alarms.portLabel.out');
20
23
  },
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
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.
3
+ // event (coming / going / acknowledged); the active alarms first, and again
4
+ // after a reconnect. An input msg.ack acknowledges alarms (a write to the PLC).
4
5
 
5
6
  const { text, getEndpoint } = require('../lib/common');
6
7
 
@@ -12,16 +13,28 @@ module.exports = function (RED) {
12
13
  if (!ep) return;
13
14
  const active = new Map(); // id -> alarm
14
15
 
15
- const showCount = () =>
16
- node.status({ fill: active.size ? 'yellow' : 'green', shape: 'dot', text: text(RED, 's7rs-alarms.status.active', { n: active.size }) });
16
+ // the list holds the coming alarms and the alarms that went but still wait
17
+ // for acknowledgement (the PLC keeps them until they are acknowledged)
18
+ const showCount = () => {
19
+ const all = [...active.values()];
20
+ const n = all.filter((a) => a.state === 'coming').length;
21
+ const unack = all.filter((a) => a.acknowledged === false).length;
22
+ const t = unack ? text(RED, 's7rs-alarms.status.unack', { n, u: unack }) : text(RED, 's7rs-alarms.status.active', { n });
23
+ node.status({ fill: unack ? 'red' : n ? 'yellow' : 'green', shape: 'dot', text: t });
24
+ };
17
25
 
18
26
  const onAlarms = (ev) => {
19
27
  if (ev.sub !== node.id) return;
20
28
  // a new subscription (start or reconnect): the alarms that went meanwhile are gone
21
29
  if (ev.snapshot) active.clear();
22
30
  for (const a of ev.alarms) {
23
- if (a.state === 'coming') active.set(a.id, a);
24
- else active.delete(a.id);
31
+ if (a.state === 'coming' || (a.state === 'going' && a.acknowledged === false)) active.set(a.id, a);
32
+ else if (a.state === 'going') active.delete(a.id);
33
+ else if (a.state === 'acknowledged' && active.has(a.id)) {
34
+ const x = active.get(a.id);
35
+ if (x.state === 'going') active.delete(a.id);
36
+ else x.acknowledged = true;
37
+ }
25
38
  const msg = { topic: a.id, payload: a, state: a.state, ts: ev.ts };
26
39
  if (a.initial) msg.initial = true;
27
40
  node.send(msg);
@@ -30,6 +43,23 @@ module.exports = function (RED) {
30
43
  };
31
44
  ep.bridge.on('alarms', onAlarms);
32
45
 
46
+ // msg.ack: an alarm id ("0x…", the msg.topic of an alarm message), a list of
47
+ // ids, or true / "all" (every active alarm that waits for acknowledgement)
48
+ node.on('input', async (msg, send, done) => {
49
+ if (msg.ack === undefined || msg.ack === false || msg.ack === null) {
50
+ done(new Error(text(RED, 's7rs-alarms.errors.noAck')));
51
+ return;
52
+ }
53
+ const all = msg.ack === true || msg.ack === 'all';
54
+ try {
55
+ await ep.ready;
56
+ await ep.bridge.call(ep.id, 'acknowledge', all ? { all: true } : { ids: [].concat(msg.ack) });
57
+ done();
58
+ } catch (err) {
59
+ done(new Error(text(RED, 's7rs-alarms.errors.ack', { error: err.message })));
60
+ }
61
+ });
62
+
33
63
  ep.ready
34
64
  .then(() =>
35
65
  ep.bridge.subscribeAlarms({ conn: ep.id, sub: node.id, initial: config.initial !== false, layout: config.layout || 'auto' }),
@@ -0,0 +1,33 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('s7rs-brcv', {
3
+ category: 'network',
4
+ color: '#3FADB5',
5
+ defaults: {
6
+ name: { value: '' },
7
+ endpoint: { value: '', type: 's7rs-endpoint', required: true },
8
+ rid: { value: '', validate: function (v) { return v === '' || v === undefined || /^\d+$/.test(String(v)); } },
9
+ },
10
+ inputs: 0,
11
+ outputs: 1,
12
+ icon: 'font-awesome/fa-download',
13
+ paletteLabel: 's7 brcv',
14
+ label: function () {
15
+ return this.name || ('s7 brcv' + (this.rid !== '' && this.rid !== undefined ? ' R_ID ' + this.rid : ''));
16
+ },
17
+ });
18
+ </script>
19
+
20
+ <script type="text/html" data-template-name="s7rs-brcv">
21
+ <div class="form-row">
22
+ <label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="s7rs-brcv.label.name"></span></label>
23
+ <input type="text" id="node-input-name" />
24
+ </div>
25
+ <div class="form-row">
26
+ <label for="node-input-endpoint"><i class="fa fa-plug"></i> <span data-i18n="s7rs-brcv.label.endpoint"></span></label>
27
+ <input type="text" id="node-input-endpoint" />
28
+ </div>
29
+ <div class="form-row">
30
+ <label for="node-input-rid">R_ID</label>
31
+ <input type="text" id="node-input-rid" data-i18n="[placeholder]s7rs-brcv.placeholder.rid" style="width: 150px" />
32
+ </div>
33
+ </script>
@@ -0,0 +1,38 @@
1
+ 'use strict';
2
+ // s7rs-brcv: receives the blocks of a PLC BSEND over an S7 partner endpoint
3
+ // (S7 connection, BSEND/BRCV). One message per block.
4
+
5
+ const { text, getEndpoint } = require('../lib/common');
6
+
7
+ module.exports = function (RED) {
8
+ function S7rsBrcv(config) {
9
+ RED.nodes.createNode(this, config);
10
+ const node = this;
11
+ const ep = getEndpoint(RED, node, config);
12
+ if (!ep) return;
13
+ const want = String(config.rid ?? '').trim() === '' ? null : Number(config.rid);
14
+ let count = 0;
15
+
16
+ const onBlocks = (ev) => {
17
+ if (ev.sub !== node.id) return;
18
+ if (want !== null && ev.rid !== want) return;
19
+ count += 1;
20
+ node.status({ fill: 'green', shape: 'dot', text: text(RED, 's7rs-brcv.status.count', { n: count }) });
21
+ node.send({ topic: String(ev.rid), payload: ev.data, rid: ev.rid, ts: ev.ts });
22
+ };
23
+ ep.bridge.on('blocks', onBlocks);
24
+
25
+ ep.ready
26
+ .then(() => ep.bridge.subscribeBlocks({ conn: ep.id, sub: node.id }))
27
+ .catch((err) => node.error(text(RED, 's7rs-brcv.errors.subscribe', { error: err.message })));
28
+
29
+ node.on('close', (removed, done) => {
30
+ ep.bridge.off('blocks', onBlocks);
31
+ ep.bridge
32
+ .unsubscribe(node.id)
33
+ .catch(() => {})
34
+ .finally(() => done());
35
+ });
36
+ }
37
+ RED.nodes.registerType('s7rs-brcv', S7rsBrcv);
38
+ };
@@ -0,0 +1,33 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('s7rs-bsend', {
3
+ category: 'network',
4
+ color: '#3FADB5',
5
+ defaults: {
6
+ name: { value: '' },
7
+ endpoint: { value: '', type: 's7rs-endpoint', required: true },
8
+ rid: { value: '', validate: function (v) { return v === '' || v === undefined || /^\d+$/.test(String(v)); } },
9
+ },
10
+ inputs: 1,
11
+ outputs: 1,
12
+ icon: 'font-awesome/fa-upload',
13
+ paletteLabel: 's7 bsend',
14
+ label: function () {
15
+ return this.name || ('s7 bsend' + (this.rid !== '' && this.rid !== undefined ? ' R_ID ' + this.rid : ''));
16
+ },
17
+ });
18
+ </script>
19
+
20
+ <script type="text/html" data-template-name="s7rs-bsend">
21
+ <div class="form-row">
22
+ <label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="s7rs-bsend.label.name"></span></label>
23
+ <input type="text" id="node-input-name" />
24
+ </div>
25
+ <div class="form-row">
26
+ <label for="node-input-endpoint"><i class="fa fa-plug"></i> <span data-i18n="s7rs-bsend.label.endpoint"></span></label>
27
+ <input type="text" id="node-input-endpoint" />
28
+ </div>
29
+ <div class="form-row">
30
+ <label for="node-input-rid">R_ID</label>
31
+ <input type="text" id="node-input-rid" data-i18n="[placeholder]s7rs-bsend.placeholder.rid" style="width: 150px" />
32
+ </div>
33
+ </script>
@@ -0,0 +1,42 @@
1
+ 'use strict';
2
+ // s7rs-bsend: sends msg.payload as a block to a PLC BRCV over an S7 partner
3
+ // endpoint (S7 connection, BSEND/BRCV). A write to the PLC.
4
+
5
+ const { text, elapsedMs, getEndpoint } = require('../lib/common');
6
+
7
+ // Buffer as is; a byte array; a string as UTF-8.
8
+ function toBlock(p) {
9
+ if (Buffer.isBuffer(p)) return p;
10
+ if (Array.isArray(p) && p.every((x) => Number.isInteger(x) && x >= 0 && x <= 255)) return Buffer.from(p);
11
+ if (typeof p === 'string') return Buffer.from(p, 'utf8');
12
+ return null;
13
+ }
14
+
15
+ module.exports = function (RED) {
16
+ function S7rsBsend(config) {
17
+ RED.nodes.createNode(this, config);
18
+ const node = this;
19
+ const ep = getEndpoint(RED, node, config);
20
+ const cfgRid = String(config.rid ?? '').trim();
21
+
22
+ node.on('input', async (msg, send, done) => {
23
+ if (!ep) return done(new Error(text(RED, 's7rs-bsend.errors.noEndpoint')));
24
+ const ridIn = msg.rid !== undefined ? msg.rid : cfgRid;
25
+ const rid = Number(ridIn);
26
+ if (ridIn === '' || !Number.isInteger(rid) || rid < 0 || rid > 0xffffffff) return done(new Error(text(RED, 's7rs-bsend.errors.rid')));
27
+ const data = toBlock(msg.payload);
28
+ if (!data || data.length === 0 || data.length > 65534) return done(new Error(text(RED, 's7rs-bsend.errors.payload')));
29
+ try {
30
+ await ep.ready;
31
+ const t0 = process.hrtime.bigint();
32
+ await ep.bridge.call(ep.id, 'bsend', { rid, data: data.toString('hex') });
33
+ msg.s7 = { rid, bytes: data.length, ms: elapsedMs(t0) };
34
+ send(msg);
35
+ done();
36
+ } catch (err) {
37
+ done(err);
38
+ }
39
+ });
40
+ }
41
+ RED.nodes.registerType('s7rs-bsend', S7rsBsend);
42
+ };
@@ -31,17 +31,21 @@
31
31
  password: { type: 'password' },
32
32
  },
33
33
  label: function () {
34
- const p = this.protocol === 's7plus' ? 'S7+' : `S7-${this.cpu}`;
34
+ const p = this.protocol === 's7plus' ? 'S7+' : this.protocol === 's7partner' ? 'S7 partner' : `S7-${this.cpu}`;
35
35
  return this.name || (this.host ? `${p} ${this.host}:${this.port || 102}` : 's7 endpoint');
36
36
  },
37
37
  oneditprepare: function () {
38
38
  const node = this;
39
39
  const sync = () => {
40
- const plus = $('#node-config-input-protocol').val() === 's7plus';
40
+ const proto = $('#node-config-input-protocol').val();
41
+ const plus = proto === 's7plus';
42
+ const partner = proto === 's7partner';
41
43
  const tls = plus && $('#node-config-input-tls').prop('checked');
42
44
  const v = $('#node-config-input-certVerify').val();
43
- $('.s7rs-classic').toggle(!plus);
45
+ $('.s7rs-classic').toggle(!plus && !partner);
44
46
  $('.s7rs-plus').toggle(plus);
47
+ $('.s7rs-tsap').toggle(!plus);
48
+ $('.s7rs-partner').toggle(partner);
45
49
  $('.s7rs-tls').toggle(tls);
46
50
  $('.s7rs-cert-fp').toggle(tls && v === 'fingerprint');
47
51
  $('.s7rs-cert-trusted').toggle(tls && v === 'trusted');
@@ -81,6 +85,7 @@
81
85
  <select id="node-config-input-protocol">
82
86
  <option value="s7" data-i18n="s7rs-endpoint.protocol.s7"></option>
83
87
  <option value="s7plus" data-i18n="s7rs-endpoint.protocol.s7plus"></option>
88
+ <option value="s7partner" data-i18n="s7rs-endpoint.protocol.s7partner"></option>
84
89
  </select>
85
90
  </div>
86
91
  <div class="form-row">
@@ -115,12 +120,16 @@
115
120
  <option value="3" data-i18n="s7rs-endpoint.link.basic"></option>
116
121
  </select>
117
122
  </div>
118
- <div class="form-row s7rs-classic">
123
+ <div class="form-row s7rs-tsap">
119
124
  <label for="node-config-input-localTsap" data-i18n="s7rs-endpoint.label.tsaps"></label>
120
125
  <input type="text" id="node-config-input-localTsap" placeholder="10.00" style="width: 100px" />
121
126
  <input type="text" id="node-config-input-remoteTsap" placeholder="20.00" style="width: 100px" />
122
127
  </div>
123
- <div class="form-row s7rs-classic">
128
+ <div class="form-row s7rs-partner">
129
+ <label>&nbsp;</label>
130
+ <span style="opacity: 0.7" data-i18n="s7rs-endpoint.hint.partner"></span>
131
+ </div>
132
+ <div class="form-row s7rs-tsap">
124
133
  <label for="node-config-input-pdu" data-i18n="s7rs-endpoint.label.pdu"></label>
125
134
  <input type="text" id="node-config-input-pdu" placeholder="960" style="width: 100px" />
126
135
  </div>
@@ -9,7 +9,7 @@ const { text, intOrUndef } = require('../lib/common');
9
9
  // Diagnostics the editor may call through the admin API (read-only actions).
10
10
  const ADMIN_ACTIONS = new Set([
11
11
  'identify', 'cpuState', 'szl', 'szlList', 'clock', 'blocks', 'listBlocks', 'blockInfo',
12
- 'info', 'certificate', 'limits', 'dbs', 'browse', 'alarms',
12
+ 'info', 'certificate', 'limits', 'dbs', 'browse', 'alarms', 'links', 'resolve',
13
13
  ]);
14
14
 
15
15
  module.exports = function (RED) {
@@ -62,6 +62,9 @@
62
62
  <option value="dbs">dbs</option>
63
63
  <option value="browse">browse</option>
64
64
  <option value="alarms">alarms {all}</option>
65
+ <option value="acknowledge">acknowledge {ids, all} (writes)</option>
66
+ <option value="resolve">resolve {name | path}</option>
67
+ <option value="links">links {rid, aid}</option>
65
68
  <option value="limits">limits</option>
66
69
  </optgroup>
67
70
  </select>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-s7-rust",
3
- "version": "1.2.2",
3
+ "version": "1.3.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",
@@ -16,7 +16,9 @@
16
16
  "industrial",
17
17
  "iiot",
18
18
  "rust",
19
- "napi"
19
+ "napi",
20
+ "bsend",
21
+ "brcv"
20
22
  ],
21
23
  "homepage": "https://github.com/oriolrius/node-red-contrib-s7-rust#readme",
22
24
  "bugs": {
@@ -56,7 +58,9 @@
56
58
  "s7rs-write": "nodes/s7rs-write.js",
57
59
  "s7rs-watch": "nodes/s7rs-watch.js",
58
60
  "s7rs-info": "nodes/s7rs-info.js",
59
- "s7rs-alarms": "nodes/s7rs-alarms.js"
61
+ "s7rs-alarms": "nodes/s7rs-alarms.js",
62
+ "s7rs-bsend": "nodes/s7rs-bsend.js",
63
+ "s7rs-brcv": "nodes/s7rs-brcv.js"
60
64
  }
61
65
  },
62
66
  "scripts": {