node-red-contrib-s7-rust 1.2.2 → 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,74 @@ 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
+
28
+ ## [1.3.0] - 2026-11-13
29
+
30
+ ### Added
31
+
32
+ - `s7 alarms`: acknowledges alarms. An input message with `msg.ack` (an alarm id `"0x…"`, a list of
33
+ ids, or `"all"` / `true`: every alarm that waits for acknowledgement) acknowledges the coming
34
+ state, as the TIA Portal alarm display does. The node sends `state: "acknowledged"` or
35
+ `"ackFailed"` (`payload.ackResult`: the PLC refuses an alarm whose class needs no
36
+ acknowledgement) per alarm. Alarm messages have `payload.acknowledged`. An alarm that went
37
+ before its acknowledgement stays in the node list until it is acknowledged (the PLC keeps it
38
+ too); the status shows the active alarms and how many wait for acknowledgement.
39
+ - `s7 info`: action `acknowledge {ids, all}` (writes; the admin API refuses it).
40
+ - Rust crate `s7plus`: `Client::acknowledge_alarms` (CreateObject of an AckJob, class 3636, under
41
+ the alarm subsystem; at most 100 alarms per job, like TIA Portal), `decode_ack_job`,
42
+ `AckResult`; arrays of structs (dynamic array, flags 0x20) are encoded and decoded with the
43
+ struct id once after the datatype, then the count and the members of each element. The fake
44
+ PLC has alarms with acknowledgement (`raise_alarm_ack`) and answers AckJobs.
45
+ - `test/plcsim`: `set-alarm-class.ps1` and `alarm-classes.xlsx` give `alReq` the alarm class
46
+ "Acknowledgement"; `live_alarms.js` acknowledges it. Tested on PLCSIM Advanced V8 (S7-1500,
47
+ FW S4.1): acknowledged in about 15 ms; an alarm of a class without acknowledgement gives
48
+ `ackFailed` (0x8005).
49
+ - BSEND / BRCV (S7 communication over an S7 connection): the endpoint protocol "S7 partner" and
50
+ two nodes. `s7 brcv` sends a message for each block of a PLC `BSEND` (`msg.payload` Buffer,
51
+ `msg.rid`; filter by R_ID); `s7 bsend` sends `msg.payload` (Buffer, byte array or string) to a
52
+ PLC `BRCV` with the R_ID of the node or `msg.rid`. Blocks up to 65534 bytes, in fragments of
53
+ the PDU size. Node-RED connects actively with the TSAPs of the S7 connection and connects again
54
+ after a loss. Blocks that come before the first `s7 brcv` node starts go to that node.
55
+ - Rust crate `s7`: `partner::Partner` (connect, `recv`, `send`) and a fake PLC
56
+ (`partner_fake`). The acknowledgement of a fragmented block carries the IDSeq of the fragments
57
+ as its sequence and the PDU reference of the request, as an S7-1500 does (snap7 uses a new
58
+ sequence; PLCSIM then stops after the first fragment).
59
+ - `test/plcsim`: FB `PartnerComm`, DBs `PartnerData` / `PartnerComm_DB`, `add-s7-connection.ps1`
60
+ (TIA Portal Openness: S7 connection to an unspecified partner), `download-hw-sw.ps1` (download
61
+ with the hardware configuration; the TIA Portal MCP loads the software only) and
62
+ `live_partner.js`. Tested on PLCSIM Advanced V8 (S7-1500, FW S4.1): 16 and 1800 bytes both
63
+ ways.
64
+ - Example flow "06 - BSEND and BRCV".
65
+ - `s7 info` (S7CommPlus), read only, also in the admin API:
66
+ - `resolve {name}`: the object id (RID) of a DB, FB, FC, OB or technology object by its name,
67
+ asked to the PLC (GetVariablesAddress 0x0590 with the object path
68
+ `ASRoot.PLCProgram.<name>`, as TIA Portal does for technology objects); `{path}` takes any
69
+ object path (`"ASRoot"`, `"ASRoot.PLCProgram"`). `rid` is null when the PLC has no such
70
+ object.
71
+ - `links {rid, aid}`: the objects that a relation of an object points to (GetLink 0x0524), for
72
+ example rid 8, aid 2667: the active alarm instances.
73
+ - Rust crate `s7plus`: `Client::resolve_object`, `Client::get_links`, `program_object_path`. The
74
+ request and response layouts were found on PLCSIM Advanced V8 (S7-1500, FW S4.1); the fake PLC
75
+ answers both with the PLCSIM bytes.
76
+
9
77
  ## [1.2.2] - 2026-11-12
10
78
 
11
79
  ### Fixed
@@ -187,7 +255,9 @@ First release: the next generation of `@oriolrius/node-red-contrib-s7`.
187
255
  - CI: tests on Node-RED 4 and 5, gitleaks, GitGuardian, RustSec and npm audit, CodeQL,
188
256
  OpenSSF Scorecard, Dependabot. License LGPL-3.0-only.
189
257
 
190
- [Unreleased]: https://github.com/oriolrius/node-red-contrib-s7-rust/compare/v1.2.2...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
260
+ [1.3.0]: https://github.com/oriolrius/node-red-contrib-s7-rust/compare/v1.2.2...v1.3.0
191
261
  [1.2.2]: https://github.com/oriolrius/node-red-contrib-s7-rust/compare/v1.2.1...v1.2.2
192
262
  [1.2.1]: https://github.com/oriolrius/node-red-contrib-s7-rust/compare/v1.2.0...v1.2.1
193
263
  [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,12 @@ 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"). |
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"). |
88
92
 
89
93
  Every node has full help in the editor sidebar. Bad tags never stop the other tags: they give
90
94
  `null` and an entry in `msg.s7.errors`, or `msg.quality = "bad"` in a watch.
@@ -127,11 +131,12 @@ This map shows each protocol function and where it is available. It is strict: a
127
131
  | PLC hot / cold start | job 0x28, PI service `P_PROGRAM` | 🔒 | — |
128
132
  | Block download, delete | jobs 0x1A, 0x1B, 0x1C, PI service `_DELE` | ❌ | — |
129
133
  | Compress, copy RAM to ROM | PI services `_GARB`, `_MODU` | ❌ | — |
130
- | Cyclic data | userdata group 2 | ❌ | — (`s7 watch` uses polling) |
131
- | Alarms and messages | userdata group 4 alarm subfunctions, NOTIFY, ALARM_S/ALARM_8 | ❌ | — |
132
- | 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) |
133
137
  | Programmer commands, force | userdata group 1 | ❌ | — |
134
- | BSEND/BRCV, USEND/URCV | userdata group 6 | ❌ | — |
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") |
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") |
135
140
  | S7 routing to other subnets | COTP with routing parameters | ❌ | — |
136
141
 
137
142
  ### S7CommPlus (crate `s7plus`)
@@ -152,11 +157,13 @@ This map shows each protocol function and where it is available. It is strict: a
152
157
  | Communication limits | read of the PLC limit attributes | ✅ | `s7 info`: `limits`, `info` |
153
158
  | Active alarms | alarm objects and text libraries | ✅ | `s7 info`: `alarms` |
154
159
  | Alarm subscription | CreateObject alarm subscription (TIA Portal or S7CommPlusDriver layout), DAI notifications | ✅ | `s7 alarms` |
160
+ | 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
161
  | Variable subscription | CreateObject subscription with a cycle time, notifications, credit limit | ✅ | `s7 watch` (mode "PLC subscription") |
156
162
  | Set CPU operating state (RUN/STOP) | SetVariable 0x04F2 | 🔒 | — |
157
163
  | Block upload / download, program changes | BeginSequence 0x0556, EndSequence 0x0560, Invoke 0x056B | ❌ | — |
158
- | Links | AddLink 0x0506, RemoveLink 0x051A, GetLink 0x0524 | ❌ | — |
159
- | GetVariablesAddress | 0x0590 | ❌ | — |
164
+ | Object relations (read) | GetLink 0x0524: object id, relation id → linked object ids | ✅ | `s7 info`: `links` |
165
+ | Object path resolution | GetVariablesAddress 0x0590: OMS object path (`ASRoot.PLCProgram.<name>`) → object id | ✅ | `s7 info`: `resolve` |
166
+ | Add / remove relations | AddLink 0x0506, RemoveLink 0x051A | ❌ | — (change the object model; no TIA Portal tool uses them) |
160
167
 
161
168
  ## Prepare the PLC
162
169
 
@@ -192,6 +199,18 @@ check fails, the endpoint stays disconnected and the error shows the fingerprint
192
199
  from the PLC* then shows the refused certificate with a warning (`refused: true`), so a new PLC
193
200
  certificate can be checked and taken over.
194
201
 
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
205
+ unspecified partner (Devices & networks → Connections), with the active connection establishment on
206
+ the partner side, clear "SIMATIC-ACC" to get numeric TSAPs, and set the partner address to the
207
+ address the PLC sees for Node-RED. Load the hardware configuration (the connection is part of it).
208
+ In the endpoint select "S7 partner" and enter the TSAPs of the connection: local = the partner
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.
213
+
195
214
  ## Addresses
196
215
 
197
216
  One address per line in the node, or in `msg.tags` / `msg.topic`.
@@ -256,6 +275,10 @@ All examples use the address `192.168.0.1`. Change it in the endpoint.
256
275
  - The nodes **cannot** stop or start the CPU and **cannot** upload blocks. The Rust crates have
257
276
  these functions, but the addon does not expose them.
258
277
  - `setClock` and `syncClock` change the PLC clock. The admin API refuses them.
278
+ - `s7 alarms` acknowledges alarms when a message with `msg.ack` arrives (a write to the PLC), never
279
+ by itself. `s7 info` action `acknowledge` does the same; the admin API refuses 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).
259
282
  - `s7 write` writes to the PLC at once. Test on a simulator (for example PLCSIM Advanced) before
260
283
  you write to a machine.
261
284
 
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
+ ]
@@ -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
+ ]
@@ -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,15 @@ 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) {
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
+ }
78
+ return;
79
+ }
70
80
  this.emit('alarms', { event: 'alarms', sub: ev.sub, conn: ev.conn, alarms: a.alarms, snapshot: a.snapshot, ts: ev.ts });
71
81
  return;
72
82
  }
@@ -126,8 +136,19 @@ class NapiBridge extends EventEmitter {
126
136
  this.native.subscribeAlarms(p);
127
137
  }
128
138
 
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
142
+ async subscribeBlocks(p) {
143
+ this.start();
144
+ this.subTags.set(p.sub, []);
145
+ this.blockSubs.add(p.sub);
146
+ this.native.subscribeBlocks(p.conn, p.sub, p.kind || 'bsend');
147
+ }
148
+
129
149
  async unsubscribe(sub) {
130
150
  this.subTags.delete(sub);
151
+ this.blockSubs.delete(sub);
131
152
  if (this.native) this.native.unsubscribe(sub);
132
153
  }
133
154
 
@@ -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,17 @@
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, 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
43
+ connection to an unspecified partner, with the active connection establishment on the partner
44
+ side (not on the PLC), and use its ID in the instructions. Node-RED connects to the PLC with the
45
+ TSAPs of that connection: local = the partner TSAP, remote = the PLC TSAP (S7-1500 numeric
46
+ TSAPs: clear "SIMATIC-ACC" in the connection properties). The partner address of the connection
47
+ must be the address the PLC sees for Node-RED. The connection is loaded with the hardware
48
+ configuration.</p>
38
49
  <h4>Log</h4>
39
50
  <p>Messages go to the Node-RED log. <code>trace</code> logs every frame in hex.</p>
40
51
  <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, USEND/URCV 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>
@@ -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
+ }
@@ -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 || (ev.kind && ev.kind !== 'bsend')) 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>
@@ -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.2.2",
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",
@@ -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,11 @@
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",
64
+ "s7rs-usend": "nodes/s7rs-usend.js",
65
+ "s7rs-urcv": "nodes/s7rs-urcv.js"
60
66
  }
61
67
  },
62
68
  "scripts": {