Siemens S7
The Siemens S7 driver (io.scadex.driver.s7) connects the gateway to Siemens S7 CPUs over Ethernet. Each tag bound to it reads one address of one CPU, polled on the connection's interval, and a write to such a tag writes that address. This page is for engineers who set up S7 connections and tags.
It speaks the classic S7 protocol (S7comm over ISO-on-TCP, port 102) itself and has no third-party dependency, and it declares SDK contract 1.6. It is in the default set of modules.
What has been proven
The driver has run against an S7 CPU written for its tests: a socket in the test process that answers the protocol. No real CPU has been tried yet, so the rack and slot of an ET 200S IM 151-8 below are what Siemens' manuals say, not something seen here. The S7-1500 the gateway has read so far was read through OPC UA, not through this driver.
Which CPUs
| CPU | What the driver reads |
|---|---|
| S7-300 and the CPUs built like it: the ET 200S IM 151-8 PN/DP and its relatives | Everything below. The CPU has no setting to switch on; its protection level (a password) decides whether reading is allowed at all |
| S7-400 | The same protocol; not tried |
| S7-1200 and S7-1500 | Only data blocks with Optimized block access switched off, and only when PUT/GET access is permitted in the CPU's protection settings. Otherwise every item is refused with "access to the object is not allowed", which the tags show |
The newer S7CommPlus protocol of an S7-1200 or S7-1500, with optimized blocks and symbolic names, is not part of this driver. For those, read the CPU's own OPC UA server with the OPC UA driver.
Adding a connection
Open Connections, then Siemens S7 (/connections/io.scadex.driver.s7), and add a PLC. The form is rendered from the driver's descriptor:
| Field | Key | Meaning | Default |
|---|---|---|---|
| Host | host | Required. The CPU's address or name, without a scheme, a path or a port. | none |
| Port | port | 1 to 65535. | 102 |
| Rack | rack | 0 to 7. The rack the CPU sits in. | 0 |
| Slot | slot | 0 to 31. The CPU's slot in the hardware configuration: 2 for an S7-300 and the CPUs built like it, 1 for an S7-1200 and S7-1500. | 2 |
| Poll interval (ms) | pollIntervalMs | How often every tag on the connection is read. 20 ms to 1 hour. | 1000 |
| Reply timeout (ms) | timeoutMs | How long to wait for an answer before the link counts as lost. 100 ms to 60 s. | 3000 |
| PDU size | pduSize | The largest request, in bytes, the gateway asks the CPU to take, 240 to 960. The CPU says what it allows (240 for an S7-300 class CPU, 480 for an S7-1200 and S7-1500) and the connection uses that. | 480 |
| Read across gaps of | readGap | Unused bytes to read through to join two tags into one run, 0 to 256. 0 reads only tags that touch. | 0 |
Every connection also has a unique name and an Enabled switch. Test connects, settles the PDU size and reads the first input byte, and reports the time. A CPU that refuses that read still counts as reached, and the message says why. A CPU that refuses the rack and slot hangs up when asked; the test then tries rack 0 with slots 2, 1 and 0 and names the one that answers.
Tags
A tag bound to this driver has the binding document:
{ "area": "db", "db": 5, "offset": 12, "dataType": "real" }
| Field | Meaning |
|---|---|
area | db (data block), input, output, marker, counter or timer. Default db. |
db | The data block number, 1 to 65535, for the db area. Leave it out for any other area. |
offset | The byte the value starts at, counted from 0: the 12 of DB5.DBD12. For a counter or a timer, its number, 0 to 65535. |
dataType | One of the types below. Default int; counter for the counter area and s5time for the timer area. |
bit | Required for a bool: bit 0 (lowest) to 7 of the byte. |
length | For string and wstring: the most characters the text holds, as declared in the project. Default 254. |
An S7 CPU is big-endian throughout, so there is no byte order to choose.
| Type | Size | Value |
|---|---|---|
bool | 1 bit | on or off |
byte, sint | 1 byte | 0 to 255, or -128 to 127 |
word, int | 2 bytes | 0 to 65535, or -32768 to 32767 |
dword, dint | 4 bytes | 0 to 4294967295, or the same with a sign |
lword, lint | 8 bytes | unsigned or signed 64 bits |
real, lreal | 4 or 8 bytes | a float. A value that is not a number reads as bad quality |
char | 1 byte | one character |
string | 2 + length bytes | text. A header that doesn't fit its length reads as bad quality |
wstring | 4 + 2 × length bytes | text of 16-bit characters |
date | 2 bytes | text such as 2026-11-25 |
time | 4 bytes | milliseconds, with a sign |
tod | 4 bytes | milliseconds since midnight |
dt | 8 bytes | text such as 2026-11-25T14:30:15.123 (1990 to 2089, no time zone) |
s5time | 2 bytes | milliseconds. What a timer holds |
counter | 2 bytes | the counter's value, 0 to 999 |
Scaling, units and alarms are the tag's own, as for every tag.
Making tags
- New tag on the connection page makes one tag from these fields.
- Browse shows the CPU's memory, because a CPU can't be asked what its project declares: names live in the engineering project, not in the CPU. It lists the areas, then for data blocks the numbers of the blocks that exist (a block that doesn't exist answers "no such data block"), then a block's bytes in pages of a hundred with what the CPU holds there now, in decimal and hex. The length of a block or area is found by asking, so the first open of one takes a few requests. Tick addresses, choose a data type and create the tags.
- Discovery also reads addresses typed as text, the way STEP 7 writes them:
DB1.DBW10,DB1.DBX0.3,MW20,MD4,M4.2,I0.1,IB3,QW4,Q0.5(EandAfor German input and output),T5andC3. The size letter decides the type:Xa bool,Ba byte,Wa word,Da double word. The way S7 libraries write them works too:DB5,REAL8,DB1,X0.1,DB2,S10.20(a text of 20 characters at byte 10). A type after a colon always wins:DB1.DBD4:real,DB1.DBB20:string[16]. The data type chosen in the form replaces the one the size letter implies, but not a bit, a counter or a timer.
A tag made this way has kind external; the tag editor shows it as a Driver tag, with the same fields.
How the link runs
- The driver connects with the reply timeout and retries every 5 seconds after a failure. While the link is down every bound tag is marked bad and keeps its last value. A request that isn't answered in time, or a connection the CPU closes, counts as the link being lost.
- Every poll reads the tags in as few requests as it can. Tags of the same area and data block that touch, or are within the gap, are read as one run, up to what one request item carries (222 bytes at a PDU of 240). Runs of different blocks and areas share a request, as many items as the PDU holds (19 at 240, 20 beyond) and no answer longer than it. A text longer than an item is read in pieces and put back together.
- A value is published when it changes, when its quality changes, and every 30 seconds even if neither did.
- The CPU answers each item of a request for itself. An item it refuses (a block that doesn't exist, an address past the end of the block, a protected block) makes only its own tags bad, with the CPU's reason as the quality detail. A refused run of several tags is read tag by tag from then on, so only the wrong one stays bad, and a refused tag is asked again at most every 5 to 30 seconds. A CPU that refuses a request of several items as a whole is asked again one item at a time.
- A tag whose binding can't be read (an unknown area or type, a bool without a bit) is bad with the reason.
Writing
A write uses the S7 write request. A bool is written as the single bit it is, so the other bits of its byte are not read and written back. A value longer than one request carries is written in pieces, which is not atomic. Counters and timers are read-only. A value that doesn't fit the type is refused with a sentence: 300 for a byte, 3.7 for an int, text longer than the string holds. A CPU that refuses a write makes it fail with "The CPU refused the write" and its reason.
Connection status
The gateway publishes each connection under [system]connection.s7.<name>: whether it is connected, its tag count, its last error, and numbers with history: values and messages per second, requests per poll, the PDU size, and how many tags are good, uncertain, bad or waiting.
API
Besides the standard driver routes (/connections, /connections/{id}/test, /browse, /discover and the rest, under /api/v1/modules/io.scadex.driver.s7):
| Route | Role | Meaning |
|---|---|---|
GET /api/v1/modules/io.scadex.driver.s7/status | any signed-in user | The live state of each link, with the PDU size it agreed to |
GET /api/v1/modules/io.scadex.driver.s7/connections/{id}/read | any signed-in user | Raw bytes as the CPU holds them. Query: area, db, offset (default 0), count (default 1). For a counter or a timer the values are its 16-bit words |
Not done
Reading the CPU's identity (order number, firmware), listing blocks and their sizes with the CPU's own block functions, S7CommPlus, a connection to an S7-200 or LOGO! (they use their own connection identifiers), and writing a single array element by name.