node-red-contrib-s7-rust 1.3.0 → 1.4.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,25 @@ All notable changes to this project are documented here. The format follows
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.4.0] - 2026-11-13
10
+
11
+ ### Added
12
+
13
+ - USEND / URCV on the S7 partner endpoint: two nodes. `s7 urcv` sends a message for each PLC
14
+ `USEND` (`msg.payload` Buffer for one area, an array of Buffers for two to four; `msg.areas`
15
+ with the transport size of each area; filter by R_ID); `s7 usend` sends `msg.payload` (a
16
+ Buffer, byte array or string, or an array of up to four) to a PLC `URCV`. USEND is not
17
+ acknowledged and must fit in one PDU. An S7-1500 URCV takes the data only when each area has
18
+ the exact length of its RD_i.
19
+ - Status of an S7 partner endpoint (`s7 info` action `status`, admin API): `usendsReceived`,
20
+ `usendsDropped` and `receivers` (the number of `s7 brcv` and `s7 urcv` subscriptions).
21
+ - Rust crate `s7`: `partner::Partner::usend`, `Partner::recv` returns `Message::Block` or
22
+ `Message::Usend` (before: `Block`), `Area`, `Usend`; the fake partner PLC sends and receives
23
+ USENDs. The frame layout was taken from PLCSIM Advanced V8 (S7-1500, FW S4.1): parameters
24
+ `00 01 12 06 13 00 <R_ID>`, data `FF 02 <count>` and per area `00 <transport size> <length>`.
25
+ - `test/plcsim`: USEND R_ID 3 / URCV R_ID 4 in FB `PartnerComm`, `live_usend.js`; example flow
26
+ "07 - USEND and URCV". Tested on PLCSIM Advanced V8: both ways.
27
+
9
28
  ## [1.3.0] - 2026-11-13
10
29
 
11
30
  ### Added
@@ -236,7 +255,8 @@ First release: the next generation of `@oriolrius/node-red-contrib-s7`.
236
255
  - CI: tests on Node-RED 4 and 5, gitleaks, GitGuardian, RustSec and npm audit, CodeQL,
237
256
  OpenSSF Scorecard, Dependabot. License LGPL-3.0-only.
238
257
 
239
- [Unreleased]: https://github.com/oriolrius/node-red-contrib-s7-rust/compare/v1.3.0...HEAD
258
+ [Unreleased]: https://github.com/oriolrius/node-red-contrib-s7-rust/compare/v1.4.0...HEAD
259
+ [1.4.0]: https://github.com/oriolrius/node-red-contrib-s7-rust/compare/v1.3.0...v1.4.0
240
260
  [1.3.0]: https://github.com/oriolrius/node-red-contrib-s7-rust/compare/v1.2.2...v1.3.0
241
261
  [1.2.2]: https://github.com/oriolrius/node-red-contrib-s7-rust/compare/v1.2.1...v1.2.2
242
262
  [1.2.1]: https://github.com/oriolrius/node-red-contrib-s7-rust/compare/v1.2.0...v1.2.1
package/README.md CHANGED
@@ -87,6 +87,8 @@ Then restart Node-RED. The nodes are in the **network** category of the palette.
87
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
88
  | `s7 bsend` | Sends `msg.payload` as a block to a PLC `BRCV` (S7 connection, protocol "S7 partner"). Writes to the PLC. |
89
89
  | `s7 brcv` | A message for each block of a PLC `BSEND` (S7 connection, protocol "S7 partner"). |
90
+ | `s7 usend` | Sends `msg.payload` (one to four areas) to a PLC `URCV` (S7 connection, protocol "S7 partner"); not acknowledged. Writes to the PLC. |
91
+ | `s7 urcv` | A message for each PLC `USEND` (S7 connection, protocol "S7 partner"). |
90
92
 
91
93
  Every node has full help in the editor sidebar. Bad tags never stop the other tags: they give
92
94
  `null` and an entry in `msg.s7.errors`, or `msg.quality = "bad"` in a watch.
@@ -129,12 +131,12 @@ This map shows each protocol function and where it is available. It is strict: a
129
131
  | PLC hot / cold start | job 0x28, PI service `P_PROGRAM` | 🔒 | — |
130
132
  | Block download, delete | jobs 0x1A, 0x1B, 0x1C, PI service `_DELE` | ❌ | — |
131
133
  | Compress, copy RAM to ROM | PI services `_GARB`, `_MODU` | ❌ | — |
132
- | Cyclic data | userdata group 2 | ❌ | — (`s7 watch` uses polling) |
133
- | Alarms and messages | userdata group 4 alarm subfunctions, NOTIFY, ALARM_S/ALARM_8 | ❌ | — |
134
- | Protection level password | userdata group 5 (security) | ❌ | — |
134
+ | Cyclic data | userdata group 2 (an S7-1200/1500 answers 0x8104, not supported: S7-300/400 only) | ❌ | — (`s7 watch` uses polling; S7CommPlus: mode "PLC subscription") |
135
+ | Alarms and messages | userdata group 4 alarm subfunctions, NOTIFY, ALARM_S/ALARM_8 (an S7-1500 answers 0x8104: S7-300/400 only) | ❌ | — (S7-1500: `s7 alarms` over S7CommPlus) |
136
+ | Protection level password | userdata group 5 (security) (an S7-1500 answers 0x8104: S7-300/400 only) | ❌ | — (S7-1500: S7CommPlus legitimation) |
135
137
  | Programmer commands, force | userdata group 1 | ❌ | — |
136
138
  | 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 | ❌ | — |
139
+ | USEND/URCV | userdata with the R_ID in the parameters (syntax id 0x13), one to four areas in one PDU, not acknowledged, on the same S7 connection | ✅ | `s7 usend`, `s7 urcv` (endpoint protocol "S7 partner") |
138
140
  | S7 routing to other subnets | COTP with routing parameters | ❌ | — |
139
141
 
140
142
  ### S7CommPlus (crate `s7plus`)
@@ -197,14 +199,17 @@ check fails, the endpoint stays disconnected and the error shows the fingerprint
197
199
  from the PLC* then shows the refused certificate with a warning (`refused: true`), so a new PLC
198
200
  certificate can be checked and taken over.
199
201
 
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
+ **S7 partner (BSEND/BRCV, USEND/URCV)**: the PLC program sends and receives data blocks with
203
+ `BSEND` / `BRCV`, and up to four areas without acknowledgement with `USEND` / `URCV`, over an S7
204
+ connection; Node-RED is the partner. In TIA Portal, add an S7 connection to an
202
205
  unspecified partner (Devices & networks → Connections), with the active connection establishment on
203
206
  the partner side, clear "SIMATIC-ACC" to get numeric TSAPs, and set the partner address to the
204
207
  address the PLC sees for Node-RED. Load the hardware configuration (the connection is part of it).
205
208
  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.
209
+ TSAP (for example `03.00`), remote = the PLC TSAP (for example `10.01`). The instructions use the
210
+ connection ID of TIA Portal and an R_ID that both sides agree on. A `URCV` of an S7-1500 takes the
211
+ data of `s7 usend` only when each area has the exact length of its `RD_i` (for example 100 bytes
212
+ for an `Array[0..99] of Byte`); USEND has no acknowledgement, so check `NDR` in the PLC.
208
213
 
209
214
  ## Addresses
210
215
 
@@ -272,8 +277,8 @@ All examples use the address `192.168.0.1`. Change it in the endpoint.
272
277
  - `setClock` and `syncClock` change the PLC clock. The admin API refuses them.
273
278
  - `s7 alarms` acknowledges alarms when a message with `msg.ack` arrives (a write to the PLC), never
274
279
  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).
280
+ - `s7 bsend` and `s7 usend` send data to a `BRCV` / `URCV` of the PLC program (the program
281
+ decides what to do with it).
277
282
  - `s7 write` writes to the PLC at once. Test on a simulator (for example PLCSIM Advanced) before
278
283
  you write to a machine.
279
284
 
Binary file
Binary file
@@ -0,0 +1,119 @@
1
+ [
2
+ {
3
+ "id": "c7",
4
+ "type": "comment",
5
+ "name": "USEND / URCV with an S7 connection",
6
+ "info": "The same S7 connection as for BSEND/BRCV (see the example 06): endpoint protocol 'S7 partner'.\n\ns7 urcv sends a message for each PLC USEND: msg.payload is a Buffer for one area (SD_1),\nan array of Buffers for two to four areas; msg.areas has the transport size of each area.\ns7 usend sends msg.payload to a PLC URCV with R_ID 4: one area or an array of up to four.\nAn S7-1500 URCV takes it only when each area has the exact length of its RD_i\n(here 8 bytes for an Array[0..7] of Byte). USEND has no acknowledgement.\nThe usend node writes to the PLC.",
7
+ "x": 240,
8
+ "y": 40,
9
+ "wires": []
10
+ },
11
+ {
12
+ "id": "rx7",
13
+ "type": "s7rs-urcv",
14
+ "name": "",
15
+ "endpoint": "ep7",
16
+ "rid": "",
17
+ "x": 140,
18
+ "y": 100,
19
+ "wires": [
20
+ [
21
+ "d71"
22
+ ]
23
+ ]
24
+ },
25
+ {
26
+ "id": "d71",
27
+ "type": "debug",
28
+ "name": "USENDs 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": "i7",
43
+ "type": "inject",
44
+ "name": "send 8 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,5,6,7,8]",
56
+ "payloadType": "json",
57
+ "x": 150,
58
+ "y": 160,
59
+ "wires": [
60
+ [
61
+ "tx7"
62
+ ]
63
+ ]
64
+ },
65
+ {
66
+ "id": "tx7",
67
+ "type": "s7rs-usend",
68
+ "name": "",
69
+ "endpoint": "ep7",
70
+ "rid": "4",
71
+ "x": 340,
72
+ "y": 160,
73
+ "wires": [
74
+ [
75
+ "d72"
76
+ ]
77
+ ]
78
+ },
79
+ {
80
+ "id": "d72",
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": "ep7",
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
+ ]
@@ -69,7 +69,12 @@ class NapiBridge extends EventEmitter {
69
69
  if (!this.subTags.has(ev.sub)) return; // unsubscribed meanwhile
70
70
  const a = JSON.parse(ev.alarms);
71
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 });
72
+ for (const b of a.alarms) {
73
+ const e = { event: 'blocks', sub: ev.sub, conn: ev.conn, kind: b.kind || 'bsend', rid: b.rid, ts: ev.ts };
74
+ if (b.areas) e.areas = b.areas.map((x) => ({ type: x.type, data: Buffer.from(x.data, 'hex') }));
75
+ else e.data = Buffer.from(b.data, 'hex');
76
+ this.emit('blocks', e);
77
+ }
73
78
  return;
74
79
  }
75
80
  this.emit('alarms', { event: 'alarms', sub: ev.sub, conn: ev.conn, alarms: a.alarms, snapshot: a.snapshot, ts: ev.ts });
@@ -131,13 +136,14 @@ class NapiBridge extends EventEmitter {
131
136
  this.native.subscribeAlarms(p);
132
137
  }
133
138
 
134
- // subscribeBlocks({conn, sub}): 'blocks' events {sub, conn, rid, data (Buffer), ts}: the blocks
135
- // of the PLC BSEND on an S7 partner endpoint
139
+ // subscribeBlocks({conn, sub, kind}): 'blocks' events of an S7 partner endpoint: kind 'bsend'
140
+ // (default) {sub, conn, kind, rid, data (Buffer), ts} for each PLC BSEND block, kind 'usend'
141
+ // {sub, conn, kind, rid, areas: [{type, data (Buffer)}], ts} for each PLC USEND
136
142
  async subscribeBlocks(p) {
137
143
  this.start();
138
144
  this.subTags.set(p.sub, []);
139
145
  this.blockSubs.add(p.sub);
140
- this.native.subscribeBlocks(p.conn, p.sub);
146
+ this.native.subscribeBlocks(p.conn, p.sub, p.kind || 'bsend');
141
147
  }
142
148
 
143
149
  async unsubscribe(sub) {
@@ -35,11 +35,13 @@
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
38
+ <h4>S7 partner (BSEND/BRCV, USEND/URCV)</h4>
39
+ <p>Data transfer with the PLC instructions <code>BSEND</code> / <code>BRCV</code> (blocks,
40
+ acknowledged) and <code>USEND</code> / <code>URCV</code> (up to four areas, not acknowledged)
41
+ over an S7 connection, for the nodes <code>s7 bsend</code>, <code>s7 brcv</code>,
42
+ <code>s7 usend</code> and <code>s7 urcv</code>. In TIA Portal: add an S7
41
43
  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
44
+ side (not on the PLC), and use its ID in the instructions. Node-RED connects to the PLC with the
43
45
  TSAPs of that connection: local = the partner TSAP, remote = the PLC TSAP (S7-1500 numeric
44
46
  TSAPs: clear "SIMATIC-ACC" in the connection properties). The partner address of the connection
45
47
  must be the address the PLC sees for Node-RED. The connection is loaded with the hardware
@@ -28,7 +28,7 @@
28
28
  "protocol": {
29
29
  "s7": "S7comm (classic, PUT/GET)",
30
30
  "s7plus": "S7CommPlus (S7-1200/1500, symbols)",
31
- "s7partner": "S7 partner (BSEND/BRCV over an S7 connection)"
31
+ "s7partner": "S7 partner (BSEND/BRCV, USEND/URCV over an S7 connection)"
32
32
  },
33
33
  "certVerify": {
34
34
  "none": "not checked",
@@ -0,0 +1,25 @@
1
+ <script type="text/html" data-help-name="s7rs-urcv">
2
+ <p>Receives the data that the PLC sends with <code>USEND</code> (S7 communication over an S7
3
+ connection). One message per USEND. The endpoint must use the protocol <i>S7 partner</i>.</p>
4
+ <h3>Outputs</h3>
5
+ <dl class="message-properties">
6
+ <dt>payload <span class="property-type">Buffer | array</span></dt>
7
+ <dd>the bytes of the area when the USEND has one area (SD_1); an array of Buffers when it has
8
+ more (SD_1 to SD_4).</dd>
9
+ <dt>areas <span class="property-type">array</span></dt>
10
+ <dd><code>{type, data}</code> for each area: <code>type</code> is the S7 transport size (3 bit,
11
+ 4 byte/word/dword, 5 integer, 7 real, 9 octet string), <code>data</code> a Buffer.</dd>
12
+ <dt>rid <span class="property-type">number</span></dt>
13
+ <dd>the R_ID of the USEND call; also in <code>msg.topic</code> as text.</dd>
14
+ <dt>ts <span class="property-type">string</span></dt>
15
+ <dd>receive time (ISO, UTC).</dd>
16
+ </dl>
17
+ <h3>Details</h3>
18
+ <p><b>R_ID</b>: only USENDs with this R_ID; empty: every USEND. Several nodes on one endpoint each
19
+ get every USEND.</p>
20
+ <p>The PLC sends only while Node-RED is connected: a USEND without a connection ends with an error
21
+ in the PLC (STATUS of USEND). USENDs that come before the first <code>s7 urcv</code> node of the
22
+ endpoint starts go to that node (at most 100).</p>
23
+ <p>Decode the bytes with a function node (<code>msg.payload[1].readInt16BE(0)</code>, …): the PLC
24
+ sends its SD areas in S7 byte order (big endian).</p>
25
+ </script>
@@ -0,0 +1,8 @@
1
+ {
2
+ "s7rs-urcv": {
3
+ "label": { "name": "Name", "endpoint": "PLC (S7 partner)" },
4
+ "placeholder": { "rid": "empty: every R_ID" },
5
+ "status": { "count": "__n__ messages" },
6
+ "errors": { "subscribe": "URCV: __error__" }
7
+ }
8
+ }
@@ -0,0 +1,26 @@
1
+ <script type="text/html" data-help-name="s7rs-usend">
2
+ <p>Sends <code>msg.payload</code> to a PLC <code>URCV</code> (S7 communication over an S7
3
+ connection, <code>USEND</code> / <code>URCV</code>). <b>This writes to the PLC.</b> The endpoint
4
+ must use the protocol <i>S7 partner</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>one area (a Buffer, an array of bytes, or a string sent as UTF-8), or an array of 1 to 4
9
+ areas (Buffers or strings) for RD_1 to RD_4 of the URCV.</dd>
10
+ <dt class="optional">rid <span class="property-type">number</span></dt>
11
+ <dd>the R_ID of the URCV call in the PLC (when the node has no R_ID).</dd>
12
+ </dl>
13
+ <h3>Outputs</h3>
14
+ <dl class="message-properties">
15
+ <dt>s7 <span class="property-type">object</span></dt>
16
+ <dd><code>rid</code>, <code>bytes</code> (the length of each area), <code>ms</code>: the
17
+ message passes when the USEND is sent.</dd>
18
+ </dl>
19
+ <h3>Details</h3>
20
+ <p>USEND is not acknowledged: the PLC gives no answer, also when no URCV takes the data. The
21
+ URCV takes it only when it is ready (<code>EN_R = TRUE</code>), the R_ID is the same and each
22
+ area has the length of its RD_i: an S7-1500 needs the exact length of an
23
+ <code>Array of Byte</code> (send 100 bytes to <code>Array[0..99] of Byte</code>). Check
24
+ <code>NDR</code> or a counter in the PLC. All areas together must fit in one PDU (about the PDU
25
+ size minus 24 bytes, minus 4 per area); use <code>s7 bsend</code> for larger data.</p>
26
+ </script>
@@ -0,0 +1,11 @@
1
+ {
2
+ "s7rs-usend": {
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, or an array of 1 to 4 of them (not empty)"
9
+ }
10
+ }
11
+ }
@@ -14,7 +14,7 @@ module.exports = function (RED) {
14
14
  let count = 0;
15
15
 
16
16
  const onBlocks = (ev) => {
17
- if (ev.sub !== node.id) return;
17
+ if (ev.sub !== node.id || (ev.kind && ev.kind !== 'bsend')) return;
18
18
  if (want !== null && ev.rid !== want) return;
19
19
  count += 1;
20
20
  node.status({ fill: 'green', shape: 'dot', text: text(RED, 's7rs-brcv.status.count', { n: count }) });
@@ -0,0 +1,33 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('s7rs-urcv', {
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 urcv',
14
+ label: function () {
15
+ return this.name || ('s7 urcv' + (this.rid !== '' && this.rid !== undefined ? ' R_ID ' + this.rid : ''));
16
+ },
17
+ });
18
+ </script>
19
+
20
+ <script type="text/html" data-template-name="s7rs-urcv">
21
+ <div class="form-row">
22
+ <label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="s7rs-urcv.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-urcv.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-urcv.placeholder.rid" style="width: 150px" />
32
+ </div>
33
+ </script>
@@ -0,0 +1,39 @@
1
+ 'use strict';
2
+ // s7rs-urcv: receives the USENDs of the PLC over an S7 partner endpoint
3
+ // (S7 connection, USEND/URCV). One message per USEND.
4
+
5
+ const { text, getEndpoint } = require('../lib/common');
6
+
7
+ module.exports = function (RED) {
8
+ function S7rsUrcv(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 onUsend = (ev) => {
17
+ if (ev.sub !== node.id || ev.kind !== 'usend') return;
18
+ if (want !== null && ev.rid !== want) return;
19
+ count += 1;
20
+ node.status({ fill: 'green', shape: 'dot', text: text(RED, 's7rs-urcv.status.count', { n: count }) });
21
+ const payload = ev.areas.length === 1 ? ev.areas[0].data : ev.areas.map((a) => a.data);
22
+ node.send({ topic: String(ev.rid), payload, areas: ev.areas, rid: ev.rid, ts: ev.ts });
23
+ };
24
+ ep.bridge.on('blocks', onUsend);
25
+
26
+ ep.ready
27
+ .then(() => ep.bridge.subscribeBlocks({ conn: ep.id, sub: node.id, kind: 'usend' }))
28
+ .catch((err) => node.error(text(RED, 's7rs-urcv.errors.subscribe', { error: err.message })));
29
+
30
+ node.on('close', (removed, done) => {
31
+ ep.bridge.off('blocks', onUsend);
32
+ ep.bridge
33
+ .unsubscribe(node.id)
34
+ .catch(() => {})
35
+ .finally(() => done());
36
+ });
37
+ }
38
+ RED.nodes.registerType('s7rs-urcv', S7rsUrcv);
39
+ };
@@ -0,0 +1,33 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('s7rs-usend', {
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 usend',
14
+ label: function () {
15
+ return this.name || ('s7 usend' + (this.rid !== '' && this.rid !== undefined ? ' R_ID ' + this.rid : ''));
16
+ },
17
+ });
18
+ </script>
19
+
20
+ <script type="text/html" data-template-name="s7rs-usend">
21
+ <div class="form-row">
22
+ <label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="s7rs-usend.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-usend.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-usend.placeholder.rid" style="width: 150px" />
32
+ </div>
33
+ </script>
@@ -0,0 +1,51 @@
1
+ 'use strict';
2
+ // s7rs-usend: sends msg.payload (one to four areas) as a USEND to a PLC URCV over an
3
+ // S7 partner endpoint (S7 connection, USEND/URCV). A write to the PLC, not acknowledged.
4
+
5
+ const { text, elapsedMs, getEndpoint } = require('../lib/common');
6
+
7
+ // Buffer as is; a byte array; a string as UTF-8.
8
+ function toBytes(p) {
9
+ if (Buffer.isBuffer(p)) return p;
10
+ if (Array.isArray(p) && p.length > 0 && 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
+ // One area (Buffer, byte array, string) or an array of 1..4 areas (Buffers or strings).
16
+ function toAreas(p) {
17
+ const one = toBytes(p);
18
+ if (one) return [one];
19
+ if (!Array.isArray(p) || p.length < 1 || p.length > 4) return null;
20
+ const list = p.map((x) => (Array.isArray(x) ? toBytes(x) : Buffer.isBuffer(x) || typeof x === 'string' ? toBytes(x) : null));
21
+ return list.every((b) => b && b.length > 0) ? list : null;
22
+ }
23
+
24
+ module.exports = function (RED) {
25
+ function S7rsUsend(config) {
26
+ RED.nodes.createNode(this, config);
27
+ const node = this;
28
+ const ep = getEndpoint(RED, node, config);
29
+ const cfgRid = String(config.rid ?? '').trim();
30
+
31
+ node.on('input', async (msg, send, done) => {
32
+ if (!ep) return done(new Error(text(RED, 's7rs-usend.errors.noEndpoint')));
33
+ const ridIn = msg.rid !== undefined ? msg.rid : cfgRid;
34
+ const rid = Number(ridIn);
35
+ if (ridIn === '' || !Number.isInteger(rid) || rid < 0 || rid > 0xffffffff) return done(new Error(text(RED, 's7rs-usend.errors.rid')));
36
+ const areas = toAreas(msg.payload);
37
+ if (!areas || areas.some((a) => a.length === 0)) return done(new Error(text(RED, 's7rs-usend.errors.payload')));
38
+ try {
39
+ await ep.ready;
40
+ const t0 = process.hrtime.bigint();
41
+ await ep.bridge.call(ep.id, 'usend', { rid, areas: areas.map((a) => ({ data: a.toString('hex') })) });
42
+ msg.s7 = { rid, bytes: areas.map((a) => a.length), ms: elapsedMs(t0) };
43
+ send(msg);
44
+ done();
45
+ } catch (err) {
46
+ done(err);
47
+ }
48
+ });
49
+ }
50
+ RED.nodes.registerType('s7rs-usend', S7rsUsend);
51
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-s7-rust",
3
- "version": "1.3.0",
3
+ "version": "1.4.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",
@@ -60,7 +60,9 @@
60
60
  "s7rs-info": "nodes/s7rs-info.js",
61
61
  "s7rs-alarms": "nodes/s7rs-alarms.js",
62
62
  "s7rs-bsend": "nodes/s7rs-bsend.js",
63
- "s7rs-brcv": "nodes/s7rs-brcv.js"
63
+ "s7rs-brcv": "nodes/s7rs-brcv.js",
64
+ "s7rs-usend": "nodes/s7rs-usend.js",
65
+ "s7rs-urcv": "nodes/s7rs-urcv.js"
64
66
  }
65
67
  },
66
68
  "scripts": {