node-red-contrib-s7-rust 0.0.0-stage → 1.0.1

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/LICENSE ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
package/NOTICE ADDED
@@ -0,0 +1,22 @@
1
+ node-red-contrib-s7-rust
2
+ Copyright 2026 Oriol Rius
3
+
4
+ This product is licensed under the GNU Lesser General Public License, version 3 only
5
+ (LGPL-3.0-only, see LICENSE), which supplements the GNU General Public License, version 3
6
+ (see COPYING). The source code of the prebuilt binaries is in the Git tag of each release:
7
+ https://github.com/oriolrius/node-red-contrib-s7-rust
8
+
9
+ The S7comm and S7CommPlus implementations are Rust code. Parts of the S7CommPlus client
10
+ follow the protocol handling of S7CommPlusDriver (Thomas Wiens, LGPL-3.0). Protocol
11
+ descriptions used as references:
12
+ - Wireshark s7comm and s7comm-plus dissectors
13
+ - snap7 (Davide Nardella)
14
+ - nodes7 (plcpeople) and node-red-contrib-s7 (address syntax)
15
+ - S7CommPlusDriver (Thomas Wiens)
16
+
17
+ The binary addon (bin/*/s7napi.node) statically links these Rust crates and their
18
+ dependencies: napi, napi-derive, serde_json, chrono, socket2, rustls, ring, aes,
19
+ flate2 (zlib-rs). Their licenses (MIT, Apache-2.0, ISC, BSD-style) apply to those parts.
20
+
21
+ Siemens, SIMATIC, S7-1200, S7-1500, LOGO! and TIA Portal are trademarks of Siemens AG.
22
+ This project is not affiliated with or endorsed by Siemens AG.
package/README.md CHANGED
@@ -1,3 +1,310 @@
1
- # Temporary Holding Version
1
+ # node-red-contrib-s7-rust
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![npm](https://img.shields.io/npm/v/node-red-contrib-s7-rust.svg)](https://www.npmjs.com/package/node-red-contrib-s7-rust)
4
+ [![CI](https://github.com/oriolrius/node-red-contrib-s7-rust/actions/workflows/ci.yml/badge.svg)](https://github.com/oriolrius/node-red-contrib-s7-rust/actions/workflows/ci.yml)
5
+ [![Security](https://github.com/oriolrius/node-red-contrib-s7-rust/actions/workflows/security.yml/badge.svg)](https://github.com/oriolrius/node-red-contrib-s7-rust/actions/workflows/security.yml)
6
+ [![CodeQL](https://github.com/oriolrius/node-red-contrib-s7-rust/actions/workflows/codeql.yml/badge.svg)](https://github.com/oriolrius/node-red-contrib-s7-rust/actions/workflows/codeql.yml)
7
+ [![OpenSSF Scorecard](https://api.scorecard.dev/projects/github.com/oriolrius/node-red-contrib-s7-rust/badge)](https://scorecard.dev/viewer/?uri=github.com/oriolrius/node-red-contrib-s7-rust)
8
+ [![License](https://img.shields.io/badge/license-LGPL--3.0-blue.svg)](LICENSE)
9
+
10
+ Siemens S7 nodes for [Node-RED](https://nodered.org). The two S7 protocols are written in Rust and
11
+ run **inside** the Node-RED process as a Node-API addon:
12
+
13
+ - **S7comm** (classic, ISO-on-TCP port 102): S7-200, S7-300, S7-400, S7-1200, S7-1500, LOGO! 8.
14
+ Absolute addresses, Siemens and nodes7 syntax.
15
+ - **S7CommPlus** (S7-1200/1500): **symbolic access** to optimized DBs and PLC tags
16
+ (`"DB_Data".speed`, `Motor_On`), absolute I/Q/M/DB addresses, optional TLS 1.3 and password.
17
+
18
+ There is no external process, no compiler at install time and no runtime npm dependency. The
19
+ package ships prebuilt binaries for **Linux x64** (glibc and musl/Alpine).
20
+
21
+ This is the next generation of
22
+ [@oriolrius/node-red-contrib-s7](https://www.npmjs.com/package/@oriolrius/node-red-contrib-s7).
23
+ See [Migration](#migration-from-oriolriusnode-red-contrib-s7).
24
+
25
+ ## Contents
26
+
27
+ - [Requirements](#requirements)
28
+ - [Install](#install)
29
+ - [Nodes](#nodes)
30
+ - [Protocol coverage](#protocol-coverage)
31
+ - [Prepare the PLC](#prepare-the-plc)
32
+ - [Addresses](#addresses)
33
+ - [Values](#values)
34
+ - [Examples](#examples)
35
+ - [Safety](#safety)
36
+ - [Performance](#performance)
37
+ - [Limits](#limits)
38
+ - [Migration from @oriolrius/node-red-contrib-s7](#migration-from-oriolriusnode-red-contrib-s7)
39
+ - [Build from source](#build-from-source)
40
+ - [License](#license)
41
+
42
+ ## Requirements
43
+
44
+ | | |
45
+ |---|---|
46
+ | OS / CPU | Linux x86-64 only: glibc ≥ 2.28 (Debian 10+, Ubuntu 20.04+, RHEL 8+) or musl (Alpine, the official `nodered/node-red` Docker image) |
47
+ | Node.js | ≥ 18 (Node-RED 5 needs ≥ 22.9) |
48
+ | Node-RED | ≥ 4.0 (tested on 4 and 5) |
49
+
50
+ Windows, macOS and ARM are not supported. npm refuses to install the package on them
51
+ (`os` and `cpu` fields).
52
+
53
+ ## Install
54
+
55
+ In the Node-RED editor: **Menu → Manage palette → Install**, search
56
+ `node-red-contrib-s7-rust`.
57
+
58
+ Or on the command line, in your Node-RED user directory (usually `~/.node-red`):
59
+
60
+ ```sh
61
+ npm install node-red-contrib-s7-rust
62
+ ```
63
+
64
+ Then restart Node-RED. The nodes are in the **network** category of the palette.
65
+
66
+ ## Nodes
67
+
68
+ | Node | Function |
69
+ |---|---|
70
+ | `s7 endpoint` (config) | One PLC connection: protocol, host, port. S7comm: CPU family, rack/slot or TSAPs, PDU, gap, byte order. S7CommPlus: remote TSAP, TLS, user, password (stored as a credential). |
71
+ | `s7 read` | Reads tags when a message arrives. Output: one value, `{tag: value}` or an array. |
72
+ | `s7 write` | Writes the tag of the node, the tag in `msg.topic`, or `msg.payload = {tag: value, …}` in one request. |
73
+ | `s7 watch` | A Rust thread reads the tags at an interval and sends only the changes. Optional conditional rate ("Fast while" a tag is true). |
74
+ | `s7 info` | Diagnostics. Both protocols: `status`, `cpuState`. S7comm: `identify`, `szl`, `szlList`, `clock`, `setClock`, `syncClock`, `blocks`, `listBlocks`, `blockInfo`. S7CommPlus: `info`, `dbs`, `browse`, `alarms`, `limits`. |
75
+
76
+ Every node has full help in the editor sidebar. Bad tags never stop the other tags: they give
77
+ `null` and an entry in `msg.s7.errors`, or `msg.quality = "bad"` in a watch.
78
+
79
+ The endpoint also adds two admin API routes for tools and the editor (Node-RED admin
80
+ authentication applies, permission `s7rs-endpoint.read`):
81
+
82
+ - `GET /s7rs/status/:endpointId`: connection state, request count, errors, latency percentiles.
83
+ - `GET /s7rs/call/:endpointId/:action`: a read-only `s7 info` action (for example `browse`).
84
+
85
+ ## Protocol coverage
86
+
87
+ This map shows each protocol function and where it is available. It is strict: a function has
88
+ ✅ only when a node uses it. The Rust tests run every ✅ and 🔒 function against the fake PLCs.
89
+
90
+ | Mark | Meaning |
91
+ |---|---|
92
+ | ✅ | Available in the nodes |
93
+ | 🔒 | In the Rust crate only. The nodes do not expose it (safety, or not needed) |
94
+ | ❌ | Not implemented |
95
+
96
+ ### S7comm (crate `s7`)
97
+
98
+ | Function | Protocol detail | Status | Node / action |
99
+ |---|---|---|---|
100
+ | ISO-on-TCP connection | TPKT (RFC 1006) + COTP CR/CC, TCP port 102 | ✅ | `s7 endpoint` |
101
+ | Rack/slot addressing | remote TSAP `[link type, rack<<5 \| slot]`, link type PG/OP/S7 basic | ✅ | `s7 endpoint` |
102
+ | Explicit TSAPs | local and remote TSAP (S7-200, LOGO! 8) | ✅ | `s7 endpoint` |
103
+ | Setup Communication | job 0xF0, PDU size negotiation | ✅ | `s7 endpoint` |
104
+ | Read Var | job 0x04, multi-item, split at the PDU size, near tags merged ("gap") | ✅ | `s7 read`, `s7 watch` |
105
+ | Write Var | job 0x05, multi-item, split at the PDU size | ✅ | `s7 write` |
106
+ | Memory areas | I (0x81), Q (0x82), M (0x83), DB (0x84), peripheral PI/PQ (0x80), T (0x1D), C (0x1C), V (= DB1) | ✅ | all |
107
+ | Read SZL | userdata group 4 (CPU functions), multi-part replies | ✅ | `s7 info`: `szl`, `szlList`, `identify`, `cpuState` |
108
+ | Read clock | userdata group 7 (time functions) | ✅ | `s7 info`: `clock` |
109
+ | Set clock | userdata group 7 (time functions) | ✅ | `s7 info`: `setClock`, `syncClock` (refused by the admin API) |
110
+ | List blocks | userdata group 3 (block functions): count per type, list of one type | ✅ | `s7 info`: `blocks`, `listBlocks` |
111
+ | Block info | userdata group 3 (block functions) | ✅ | `s7 info`: `blockInfo` |
112
+ | Block upload | jobs 0x1D, 0x1E, 0x1F | 🔒 | — |
113
+ | PLC STOP | job 0x29, PI service `P_PROGRAM` | 🔒 | — |
114
+ | PLC hot / cold start | job 0x28, PI service `P_PROGRAM` | 🔒 | — |
115
+ | Block download, delete | jobs 0x1A, 0x1B, 0x1C, PI service `_DELE` | ❌ | — |
116
+ | Compress, copy RAM to ROM | PI services `_GARB`, `_MODU` | ❌ | — |
117
+ | Cyclic data | userdata group 2 | ❌ | — (`s7 watch` uses polling) |
118
+ | Alarms and messages | userdata group 4 alarm subfunctions, NOTIFY, ALARM_S/ALARM_8 | ❌ | — |
119
+ | Protection level password | userdata group 5 (security) | ❌ | — |
120
+ | Programmer commands, force | userdata group 1 | ❌ | — |
121
+ | BSEND/BRCV, USEND/URCV | userdata group 6 | ❌ | — |
122
+ | S7 routing to other subnets | COTP with routing parameters | ❌ | — |
123
+
124
+ ### S7CommPlus (crate `s7plus`)
125
+
126
+ | Function | Protocol detail | Status | Node / action |
127
+ |---|---|---|---|
128
+ | Connection | TPKT + COTP, remote TSAP `SIMATIC-ROOT-HMI`, protocol version 1 for the session creation, version 2 after it | ✅ | `s7 endpoint` |
129
+ | Session | CreateObject 0x04CA (ClientSession), session setup with SetMultiVariables, DeleteObject 0x04D4 at close | ✅ | `s7 endpoint` |
130
+ | TLS 1.3 | InitSsl 0x05B3, TLS inside COTP | ✅ | `s7 endpoint` (option "TLS") |
131
+ | PLC certificate verification | — | ❌ | — (TLS protects against passive capture only) |
132
+ | Legitimation (access level password) | challenge from GetVarSubStreamed 0x0586, legacy and new response | ✅ | `s7 endpoint` (password) |
133
+ | Read | GetMultiVariables 0x054C, symbolic and absolute addresses | ✅ | `s7 read`, `s7 watch` |
134
+ | Write | SetMultiVariables 0x0542, symbolic and absolute addresses | ✅ | `s7 write` |
135
+ | Absolute areas | I, Q, M, DB, timers and counters | ✅ | all |
136
+ | Type information, DB list, browse | Explore 0x04BB, type info cache | ✅ | `s7 info`: `dbs`, `browse`; symbol resolution in all nodes |
137
+ | Symbol to absolute address | from the type information (non-optimized DBs) | ✅ | used inside the nodes |
138
+ | CPU operating state | read of the PLC program object | ✅ | `s7 info`: `cpuState` |
139
+ | Communication limits | read of the PLC limit attributes | ✅ | `s7 info`: `limits`, `info` |
140
+ | Active alarms | alarm objects and text libraries | ✅ | `s7 info`: `alarms` |
141
+ | Alarm subscription | CreateObject subscription, notifications | 🔒 | — |
142
+ | Variable subscription | CreateObject subscription, notifications | 🔒 | — (`s7 watch` uses polling) |
143
+ | Set CPU operating state (RUN/STOP) | SetVariable 0x04F2 | 🔒 | — |
144
+ | Block upload / download, program changes | BeginSequence 0x0556, EndSequence 0x0560, Invoke 0x056B | ❌ | — |
145
+ | Links | AddLink 0x0506, RemoveLink 0x051A, GetLink 0x0524 | ❌ | — |
146
+ | GetVariablesAddress | 0x0590 | ❌ | — |
147
+
148
+ ## Prepare the PLC
149
+
150
+ **S7comm on S7-1200/1500**
151
+
152
+ 1. In TIA Portal, CPU properties → Protection & Security: enable **Permit access with PUT/GET
153
+ communication from remote partner**.
154
+ 2. In each DB you read: Attributes → clear **Optimized block access**. S7comm uses absolute
155
+ addresses (`DB1.DBW2`).
156
+ 3. Rack 0, slot 1 (the defaults for these families).
157
+
158
+ **S7comm on S7-300/400**: rack 0, slot 2 (default). **LOGO! 8**: select *LOGO! 8* or
159
+ *LOGO! 8 (TSAP)* and set up a server connection in LOGO!Soft Comfort.
160
+
161
+ **S7CommPlus (S7-1200/1500)**: no PUT/GET, optimized DBs are fine. Use symbols. If the CPU has an
162
+ access level password, set it in the endpoint. TLS needs S7-1500 FW ≥ 2.9 or S7-1200 FW ≥ 4.5.
163
+
164
+ ## Addresses
165
+
166
+ One address per line in the node, or in `msg.tags` / `msg.topic`.
167
+
168
+ **Siemens syntax** (S7comm and S7CommPlus)
169
+
170
+ ```text
171
+ DB1.DBX0.3 DB1.DBB0 DB1.DBW2 DB1.DBD4 also DB1.X0.3, DB1.B0, DB1.W2, DB1.D4
172
+ M0.0 MB0 MW0 MD0 I0.0 IB0 IW0 ID0 (E = I) Q0.0 QB0 QW0 QD0 (A = Q)
173
+ PIB0 PIW0 PQW0 (peripheral) T0 C0 (Z = C)
174
+ V10.3 VB10 VW20 VD30 LOGO! 8 / S7-200 V memory (= DB1)
175
+ ```
176
+
177
+ Optional suffixes: `[n]` for an array of n elements, and `:type`:
178
+
179
+ | Group | Types |
180
+ |---|---|
181
+ | Bit and integer | `bool`, `byte`, `char`, `word`, `int`, `dword`, `dint`, `lword`, `lint`, `bcd`, `lbcd` |
182
+ | Real | `real`, `lreal` |
183
+ | Text | `string[N]`, `wstring[N]`, `wchar` |
184
+ | Date and time | `dt`, `dtz`, `dtl`, `dtlz`, `date`, `tod`, `time`, `ltime`, `ltod`, `ldt` |
185
+
186
+ Examples: `DB1.DBW2:int`, `MD12:real`, `MW120[4]`, `DB1.DBB10:string[20]`, `DB2.DBB0:dtl`.
187
+ Without a type, the size gives one: `X` bool, `B` byte, `W` word, `D` dword.
188
+
189
+ **nodes7 syntax** (S7comm and S7CommPlus): `DB1,REAL4`, `DB5,X0.1`, `DB2,S7.10`, `MI14`, `MR38`,
190
+ `DB1,INT0.5` (5 INTs). Types with an `R` prefix (`RWORD`, `RDI`) are little-endian.
191
+
192
+ **Symbols** (S7CommPlus only): `"DB_Data".speed`, `"DB_Data".values[2]`, `"DB_Data".mat[1,2]`,
193
+ `"DB_Data".st.x`, PLC tag names (`Motor_On`), or any name with the `sym:` prefix. Use
194
+ `s7 info` → `browse` to list all symbols. Symbols and absolute addresses mix in one request.
195
+
196
+ ## Values
197
+
198
+ | PLC type | JavaScript |
199
+ |---|---|
200
+ | BOOL | boolean |
201
+ | integers up to 32 bit, REAL, LREAL | number |
202
+ | LINT, LWORD | number, or string outside ±2^53 |
203
+ | STRING, WSTRING, CHAR | string |
204
+ | DT, DTL, DATE, LDT and the `z` (UTC) variants | ISO 8601 string |
205
+ | TIME, LTIME, TOD (S7comm) | number: TIME in ms, LTIME in ns, TOD in ms of the day |
206
+ | arrays (`[n]`) | array |
207
+
208
+ For writes, the node also accepts `Date`, `BigInt`, `Buffer` (for byte arrays) and numeric strings.
209
+
210
+ ## Examples
211
+
212
+ Import them in the editor: **Menu → Import → Examples → node-red-contrib-s7-rust**.
213
+
214
+ | Example | Shows |
215
+ |---|---|
216
+ | 01 - Read and write (S7comm) | cyclic read to an object, single and multi-tag writes |
217
+ | 02 - Watch with conditional rate | change-only watch, faster while a tag is true |
218
+ | 03 - S7CommPlus symbolic access | symbols and absolute addresses in one read, browse |
219
+ | 04 - PLC diagnostics | `status`, `cpuState`, `identify` |
220
+
221
+ All examples use the address `192.168.0.1`. Change it in the endpoint.
222
+
223
+ ## Safety
224
+
225
+ - The nodes **cannot** stop or start the CPU and **cannot** upload blocks. The Rust crates have
226
+ these functions, but the addon does not expose them.
227
+ - `setClock` and `syncClock` change the PLC clock. The admin API refuses them.
228
+ - `s7 write` writes to the PLC at once. Test on a simulator (for example PLCSIM Advanced) before
229
+ you write to a machine.
230
+
231
+ ## Performance
232
+
233
+ The protocol work (frame building, request optimization, value decoding, change detection)
234
+ is in Rust. Node-RED gets ready-made JavaScript values, and a watch sends nothing when nothing
235
+ changed. Reads of tags that are near each other go in one request ("gap" setting).
236
+
237
+ Measured in-process against the fake CPU of the test suite (p50, Linux x64):
238
+
239
+ | Operation | 1 tag | 1 000 tags | 10 000 tags | 100 000 tags |
240
+ |---|---|---|---|---|
241
+ | read | 0.12 ms | 0.70 ms | 5.8 ms | 64 ms |
242
+
243
+ On a real network the PLC response time is the limit (for example ~2 ms per S7comm read on an
244
+ S7-1200 on the same LAN).
245
+
246
+ ## Limits
247
+
248
+ - The addon runs in the Node-RED process. A fatal error in native code stops Node-RED. The code
249
+ is safe Rust; the Node-API layer is the only FFI.
250
+ - S7CommPlus watch uses polling, not PLC subscriptions.
251
+ - S7CommPlus: the PLC certificate is not verified (TLS protects against passive capture only).
252
+
253
+ ## Migration from @oriolrius/node-red-contrib-s7
254
+
255
+ The two packages can be installed together: the node types are different.
256
+
257
+ | @oriolrius/node-red-contrib-s7 | This package |
258
+ |---|---|
259
+ | `s7 endpoint` | `s7 endpoint` (type `s7rs-endpoint`) |
260
+ | `s7 in`, mode "Single variable" | `s7 watch` with one tag, or `s7 read` |
261
+ | `s7 in`, mode "All variables, one per message" | `s7 watch`, output "one message per tag" |
262
+ | `s7 in`, mode "All variables" | `s7 watch`, output "one message with all tags" |
263
+ | "Emit only when value changes (diff)" | `s7 watch`, "send only values that changed" (on by default) |
264
+ | `s7 out` | `s7 write` |
265
+ | `s7 control` | no direct equivalent: the watch interval is set in the node, the tags in the node or in `msg.tags` of `s7 read` |
266
+ | variable table (`name` → address) | addresses directly in the nodes; use `msg.topic` / object keys as names |
267
+
268
+ Addresses in nodes7 syntax (`DB1,REAL4`) work without change.
269
+
270
+ ## Build from source
271
+
272
+ You need Rust (stable), Node.js ≥ 18 and, for the release binaries, `cargo-zigbuild`
273
+ (`pip install cargo-zigbuild`, or `uv`; the script uses `uvx` when it is not on `PATH`).
274
+
275
+ ```sh
276
+ npm install # dev dependencies (Node-RED and the test helper)
277
+ npm run build # addon for this host -> bin/linux-x64-<gnu|musl>/s7napi.node
278
+ npm test # Rust unit tests + Node-RED tests against fake PLCs
279
+ npm run build:release # both published binaries (glibc 2.28 and musl)
280
+ npm run lint # rustfmt + clippy
281
+ npm run validate # node-red-dev scorecard checks
282
+ ```
283
+
284
+ Repository layout:
285
+
286
+ ```text
287
+ crates/s7 S7comm client (Rust)
288
+ crates/s7plus S7CommPlus client (Rust)
289
+ crates/s7napi Node-API addon
290
+ lib/ JavaScript bridge to the addon, shared helpers
291
+ nodes/ Node-RED nodes (.js runtime, .html editor), locales/ (labels, help), icons/
292
+ examples/ example flows for the Node-RED import menu
293
+ test/ Node-RED tests (node-red-node-test-helper)
294
+ scripts/ build and packaging checks
295
+ docs/ release process
296
+ ```
297
+
298
+ `S7RS_NAPI=/path/to/s7napi.node` makes the nodes load another addon build.
299
+
300
+ ## License
301
+
302
+ [GNU Lesser General Public License v3.0 only](LICENSE) (`LGPL-3.0-only`). The LGPL adds
303
+ permissions to the [GNU GPL v3.0](COPYING). See [NOTICE](NOTICE).
304
+
305
+ You can use the package in closed-source flows and applications. If you distribute a changed
306
+ version of the Rust crates or of the addon, you must publish the source code of the changes
307
+ under the same license.
308
+
309
+ Siemens, SIMATIC, S7-1200, S7-1500, LOGO! and TIA Portal are trademarks of Siemens AG. This
310
+ project is not affiliated with or endorsed by Siemens AG.
Binary file
Binary file
@@ -0,0 +1,180 @@
1
+ [
2
+ {
3
+ "id": "c1",
4
+ "type": "comment",
5
+ "name": "Read and write with S7comm (classic)",
6
+ "info": "Set the PLC address in the endpoint.\nS7-1200/1500: enable PUT/GET access and use DBs that are not optimized.\n\nThe read node reads three tags every second and sends {tag: value}.\nThe write node takes msg.topic = tag, or msg.payload = {tag: value, ...}.",
7
+ "x": 230,
8
+ "y": 40,
9
+ "wires": []
10
+ },
11
+ {
12
+ "id": "i1",
13
+ "type": "inject",
14
+ "name": "every 1 s",
15
+ "props": [
16
+ {
17
+ "p": "payload"
18
+ },
19
+ {
20
+ "p": "topic",
21
+ "vt": "str"
22
+ }
23
+ ],
24
+ "repeat": "1",
25
+ "crontab": "",
26
+ "once": true,
27
+ "onceDelay": 0.5,
28
+ "topic": "",
29
+ "payload": "",
30
+ "payloadType": "date",
31
+ "x": 140,
32
+ "y": 100,
33
+ "wires": [
34
+ [
35
+ "r1"
36
+ ]
37
+ ]
38
+ },
39
+ {
40
+ "id": "r1",
41
+ "type": "s7rs-read",
42
+ "name": "",
43
+ "endpoint": "ep1",
44
+ "tags": "MW10:int\nMD12:real\nM20.0\nDB1.DBW0[3]:int",
45
+ "output": "object",
46
+ "x": 340,
47
+ "y": 100,
48
+ "wires": [
49
+ [
50
+ "d1"
51
+ ]
52
+ ]
53
+ },
54
+ {
55
+ "id": "d1",
56
+ "type": "debug",
57
+ "name": "values",
58
+ "active": true,
59
+ "tosidebar": true,
60
+ "console": false,
61
+ "tostatus": false,
62
+ "complete": "payload",
63
+ "targetType": "msg",
64
+ "statusVal": "",
65
+ "statusType": "auto",
66
+ "x": 540,
67
+ "y": 100,
68
+ "wires": []
69
+ },
70
+ {
71
+ "id": "i2",
72
+ "type": "inject",
73
+ "name": "MW10 := 123",
74
+ "props": [
75
+ {
76
+ "p": "payload"
77
+ },
78
+ {
79
+ "p": "topic",
80
+ "vt": "str"
81
+ }
82
+ ],
83
+ "repeat": "",
84
+ "crontab": "",
85
+ "once": false,
86
+ "onceDelay": 0.5,
87
+ "topic": "MW10:int",
88
+ "payload": "123",
89
+ "payloadType": "num",
90
+ "x": 150,
91
+ "y": 160,
92
+ "wires": [
93
+ [
94
+ "w1"
95
+ ]
96
+ ]
97
+ },
98
+ {
99
+ "id": "i3",
100
+ "type": "inject",
101
+ "name": "several tags",
102
+ "props": [
103
+ {
104
+ "p": "payload"
105
+ },
106
+ {
107
+ "p": "topic",
108
+ "vt": "str"
109
+ }
110
+ ],
111
+ "repeat": "",
112
+ "crontab": "",
113
+ "once": false,
114
+ "onceDelay": 0.5,
115
+ "topic": "",
116
+ "payload": "{\"MD12:real\":3.5,\"M20.0\":true,\"DB1.DBW0[3]:int\":[1,2,3]}",
117
+ "payloadType": "json",
118
+ "x": 150,
119
+ "y": 200,
120
+ "wires": [
121
+ [
122
+ "w1"
123
+ ]
124
+ ]
125
+ },
126
+ {
127
+ "id": "w1",
128
+ "type": "s7rs-write",
129
+ "name": "",
130
+ "endpoint": "ep1",
131
+ "tag": "",
132
+ "x": 360,
133
+ "y": 180,
134
+ "wires": [
135
+ [
136
+ "d2"
137
+ ]
138
+ ]
139
+ },
140
+ {
141
+ "id": "d2",
142
+ "type": "debug",
143
+ "name": "write result",
144
+ "active": true,
145
+ "tosidebar": true,
146
+ "console": false,
147
+ "tostatus": false,
148
+ "complete": "s7",
149
+ "targetType": "msg",
150
+ "statusVal": "",
151
+ "statusType": "auto",
152
+ "x": 550,
153
+ "y": 180,
154
+ "wires": []
155
+ },
156
+ {
157
+ "id": "ep1",
158
+ "type": "s7rs-endpoint",
159
+ "name": "PLC (S7comm)",
160
+ "protocol": "s7",
161
+ "host": "192.168.0.1",
162
+ "port": 102,
163
+ "cpu": "1200",
164
+ "rack": "",
165
+ "slot": "",
166
+ "link": "",
167
+ "localTsap": "",
168
+ "remoteTsap": "",
169
+ "pdu": "",
170
+ "timeout": 5000,
171
+ "attempts": 3,
172
+ "reconnect": 5000,
173
+ "gap": 5,
174
+ "byteOrder": "big",
175
+ "logLevel": "warn",
176
+ "tsap": "SIMATIC-ROOT-HMI",
177
+ "tls": false,
178
+ "username": ""
179
+ }
180
+ ]