Siemens S7-Treiber
Übersicht
ISO-on-TCP-Kommunikation für die Siemens SIMATIC S7-Serie (S7-300 / S7-400 / S7-1200 / S7-1500).
| Position | Wert |
|---|---|
opc_type | S7 |
| Implementierungsklasse | plantpulse.driver.protocol.s7.S7_34_Driver |
| Bibliothek | iot-communication (plantpulse.plc.protocol.s7) |
| read | ✅ (Batch-Modus) |
| write | ✅ (Boolean/Integer/Long/Float/Double/String) |
| Sicherheit | keine (direkte TCP-Verbindung, S7-Safety-Kommunikation wird nicht unterstützt) |
OPC-Registrierungsformular
| Feld | Bedeutung | Beispiel |
|---|---|---|
opc_agent_ip | PLC-IP | 192.168.0.70 |
opc_agent_port | ISO-on-TCP-Port | 102 |
timecycle | Abfrageintervall (ms) | 1000 |
options.controller-type | Serie | S7_400 (default) / S7_300 / S7_200 / S7_200_SMART / S7_1200 / S7_1500 / SINUMERIK_828D |
options.local-rack | Rack-Nummer (alter Tippfehler-Schlüssel local-lack wird ebenfalls unterstützt) | 0 (default) |
options.local-slot | Slot-Nummer | 3 (Standard S7-400) / 0 (S7-1200/1500) / 2 (S7-300) |
options.multi-read | Sammel-read je Chunk in einem Umlauf (opt-in) | false (default) |
options.multi-read-max-items | Obergrenze der Items pro Chunk | 18 (default, PDU-Budget 240) |
rack/slot
- S7-300 : rack=0, slot=2
- S7-400 : rack=0, slot=3 (abhängig vom CPU-Slot)
- S7-1200 / 1500 : rack=0, slot=0 (oder 1)
Tag-plc_address-Format
Siemens-Standard-Speicheradressierung (DB / I / Q / M / T / C).
| Notation | Bedeutung |
|---|---|
%DB1.DBX0.0 | Bit X0.0 in DB1 (Bool) |
%DB1.DBB0 | Byte 0 in DB1 (8-bit) |
%DB1.DBW0 | Word 0 in DB1 (16-bit) |
%DB1.DBD0 | Doppelwort 0 in DB1 (32-bit / Real) |
%I0.0 | Input-Bit 0.0 |
%Q0.0 | Output-Bit 0.0 |
%M0.0 | Merker-Bit 0.0 |
%MW100 | Merkerwort 100 |
%MD100 | Merker-Doppelwort 100 |
Die Bibliothek iot-communication akzeptiert auch Formen ohne % wie DB1.DBW0, aus Konsistenzgründen wird jedoch das Präfix % empfohlen.
data_type- / format-Zuordnung
data_type | format | Zuordnung / Hinweis |
|---|---|---|
| Boolean / Bool | (empty) | DBX / Ix.y / Mx.y |
| Byte | B / BYTE | DBB / MB |
| Short / Int / Int16 | (empty) | DBW (signed 16-bit) |
| Int32 / DWord | DW / DWORD | DBD (signed 32-bit) |
| UInt32 | UDW | DBD (unsigned) |
| Float / REAL | REAL | DBD 32-bit IEEE-Float |
| Double / LREAL | LREAL | 8-Byte-Bereich im DB |
| String | STR[N] | S7 STRING (2 Byte Header + N Byte) |
Batch-Modus (IS_BATCH_MODE=true) + REQUEST_LIMIT=4 — ein read fasst bis zu 4 Adressen zusammen.
Häufige Fehler + Behebung
| Meldung / Symptom | Ursache | Behebung |
|---|---|---|
| Connection refused | ISO-on-TCP (Port 102) blockiert | „Permit access with PUT/GET“ im TIA Portal aktivieren |
Connection rejected by remote | rack/slot stimmen nicht überein | anhand der obigen Tabelle korrigieren |
Address out of range | DB nicht im absoluten Adressmodus (Optimized) | im TIA Portal DB-Eigenschaften → „Optimized block access“ AUS |
| alle Werte 0 | falsche DB-Nummer / falscher Offset | dieselbe Adresse mit der Watch table des TIA Portal per read prüfen |
| nur Bool wird nicht gelesen | .bit in %DB1.DBX0.0 fehlt | DBX{byte}.{bit}-Notation exakt angeben |
curl-Registrierungsbeispiel
Beispiel zum Lesen eines Real- und eines Bool-Werts aus DB1 einer S7-1500:
curl -X POST http://<edge-host>/api/v1/opc \
-H "Content-Type: application/json" \
-d '{
"opc_id": "OPC_S7_LINE2",
"opc_type": "S7",
"opc_name": "Line2 S7-1500",
"opc_agent_ip": "192.168.0.70",
"opc_agent_port": "102",
"site_id": "SITE_00001",
"auto_collect": true,
"timecycle": 1000,
"options": {
"controller-type": "S7_1500",
"local-rack": "0",
"local-slot": "0"
},
"tag_list": [
{
"tag_id": "OPC_S7_LINE2_TAG_00001",
"tag_name": "Pressure",
"plc_address": "%DB1.DBD0",
"data_type": "Float",
"format": "REAL"
},
{
"tag_id": "OPC_S7_LINE2_TAG_00002",
"tag_name": "RunFlag",
"plc_address": "%DB1.DBX10.0",
"data_type": "Boolean"
}
]
}'
Wert per read:
curl -s http://<edge-host>/api/v1/tag/OPC_S7_LINE2_TAG_00001/value | jq
Beispielsammlung (nach Datentyp)
Die Siemens-Standard-Speicherbereiche sind DB / I / Q / M / T / C. Die Bibliothek iot-communication akzeptiert das Präfix % wie in %DB1.DBW0 (funktioniert auch ohne, wird aus Konsistenzgründen aber empfohlen).
Bit / Bool (Boolean)
data_type | format | plc_address Beispiel | Bedeutung |
|---|---|---|---|
Boolean | (empty) | %DB1.DBX0.0 | Bit 0 von Byte 0 in DB1 |
Boolean | (empty) | %DB1.DBX10.7 | Bit 7 von Byte 10 in DB1 |
Boolean | (empty) | %I0.0 | Input-Bit 0.0 |
Boolean | (empty) | %Q0.0 | Output-Bit 0.0 |
Boolean | (empty) | %M0.0 | Merker-Bit 0.0 |
8- / 16-Bit-Ganzzahlen
data_type | format | plc_address Beispiel | Bedeutung |
|---|---|---|---|
Integer | B | %DB1.DBB0 | Byte (8-bit) |
Integer | BYTE | %MB10 | Merkerbyte 10 |
Integer | (empty) | %DB1.DBW0 | DB-Word (signed 16) |
Integer | (empty) | %MW100 | Merkerwort 100 |
32-Bit-Ganzzahlen
data_type | format | plc_address Beispiel | Bedeutung |
|---|---|---|---|
Integer | DW | %DB1.DBD0 | DB-Doppelwort (signed 32) |
Integer | DWORD | %MD100 | Merker-Doppelwort 100 |
Integer | UDW | %DB1.DBD8 | unsigned 32 |
Gleitkomma (Float / Double)
data_type | format | plc_address Beispiel | Bedeutung |
|---|---|---|---|
Float | REAL | %DB1.DBD0 | IEEE 754 32-bit (DBD = 4 Byte) |
Float | REAL | %MD200 | Merker-Float 200 |
Double | LREAL | %DB1.DBD8 | IEEE 754 64-bit (8 Byte) |
Zeichenketten
data_type | format | plc_address Beispiel | Bedeutung |
|---|---|---|---|
String | STR[16] | %DB1.DBB100 | S7 STRING (max. 16 Zeichen), inkl. 2 Byte Header |
String | STR[32] | %DB2.DBB0 | S7 STRING, max. 32 |
Einsatz von Formula
| Zweck | data_type | fomula | Hinweis |
|---|---|---|---|
| Ganzzahl-Rohwert → Skalierung auf Gleitkomma | Float | ${VALUE}*0.1 | DBW-Rohwert → Messwert |
| Temperaturkorrektur | Float | ${VALUE}+${TAG_OFFSET} | Kalibrierung |
| Druckeinheiten-Umrechnung (Pa → kPa) | Float | ${VALUE}/1000 | Einheitenumrechnung |
Umfassendes curl-Beispiel
curl -X POST http://<edge-host>/api/v1/opc \
-H "Content-Type: application/json" \
-d '{
"opc_id": "OPC_S7_FULL",
"opc_type": "S7",
"opc_name": "S7-1500 Full",
"opc_agent_ip": "192.168.0.70",
"opc_agent_port": "102",
"site_id": "SITE_00001",
"auto_collect": true,
"timecycle": 1000,
"options": { "controller-type": "S7_1500", "local-rack": "0", "local-slot": "0" },
"tag_list": [
{"tag_id":"OPC_S7_FULL_T01", "tag_name":"DBBit", "plc_address":"%DB1.DBX0.0", "data_type":"Boolean"},
{"tag_id":"OPC_S7_FULL_T02", "tag_name":"InputBit", "plc_address":"%I0.0", "data_type":"Boolean"},
{"tag_id":"OPC_S7_FULL_T03", "tag_name":"DBByte", "plc_address":"%DB1.DBB1", "data_type":"Integer", "format":"B"},
{"tag_id":"OPC_S7_FULL_T04", "tag_name":"DBWord", "plc_address":"%DB1.DBW2", "data_type":"Integer"},
{"tag_id":"OPC_S7_FULL_T05", "tag_name":"DBDouble", "plc_address":"%DB1.DBD4", "data_type":"Integer", "format":"DW"},
{"tag_id":"OPC_S7_FULL_T06", "tag_name":"Pressure", "plc_address":"%DB1.DBD8", "data_type":"Float", "format":"REAL"},
{"tag_id":"OPC_S7_FULL_T07", "tag_name":"Power", "plc_address":"%DB1.DBD12", "data_type":"Double", "format":"LREAL"},
{"tag_id":"OPC_S7_FULL_T08", "tag_name":"BatchName", "plc_address":"%DB1.DBB100", "data_type":"String", "format":"STR[16]"},
{"tag_id":"OPC_S7_FULL_T09", "tag_name":"PressKpa", "plc_address":"%DB1.DBD8", "data_type":"Float", "format":"REAL", "fomula":"${VALUE}/1000"}
]
}'