Zum Hauptinhalt springen

Siemens S7-Treiber

Übersicht

ISO-on-TCP-Kommunikation für die Siemens SIMATIC S7-Serie (S7-300 / S7-400 / S7-1200 / S7-1500).

PositionWert
opc_typeS7
Implementierungsklasseplantpulse.driver.protocol.s7.S7_34_Driver
Bibliothekiot-communication (plantpulse.plc.protocol.s7)
read✅ (Batch-Modus)
write✅ (Boolean/Integer/Long/Float/Double/String)
Sicherheitkeine (direkte TCP-Verbindung, S7-Safety-Kommunikation wird nicht unterstützt)

OPC-Registrierungsformular

FeldBedeutungBeispiel
opc_agent_ipPLC-IP192.168.0.70
opc_agent_portISO-on-TCP-Port102
timecycleAbfrageintervall (ms)1000
options.controller-typeSerieS7_400 (default) / S7_300 / S7_200 / S7_200_SMART / S7_1200 / S7_1500 / SINUMERIK_828D
options.local-rackRack-Nummer (alter Tippfehler-Schlüssel local-lack wird ebenfalls unterstützt)0 (default)
options.local-slotSlot-Nummer3 (Standard S7-400) / 0 (S7-1200/1500) / 2 (S7-300)
options.multi-readSammel-read je Chunk in einem Umlauf (opt-in)false (default)
options.multi-read-max-itemsObergrenze der Items pro Chunk18 (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).

NotationBedeutung
%DB1.DBX0.0Bit X0.0 in DB1 (Bool)
%DB1.DBB0Byte 0 in DB1 (8-bit)
%DB1.DBW0Word 0 in DB1 (16-bit)
%DB1.DBD0Doppelwort 0 in DB1 (32-bit / Real)
%I0.0Input-Bit 0.0
%Q0.0Output-Bit 0.0
%M0.0Merker-Bit 0.0
%MW100Merkerwort 100
%MD100Merker-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_typeformatZuordnung / Hinweis
Boolean / Bool(empty)DBX / Ix.y / Mx.y
ByteB / BYTEDBB / MB
Short / Int / Int16(empty)DBW (signed 16-bit)
Int32 / DWordDW / DWORDDBD (signed 32-bit)
UInt32UDWDBD (unsigned)
Float / REALREALDBD 32-bit IEEE-Float
Double / LREALLREAL8-Byte-Bereich im DB
StringSTR[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 / SymptomUrsacheBehebung
Connection refusedISO-on-TCP (Port 102) blockiert„Permit access with PUT/GET“ im TIA Portal aktivieren
Connection rejected by remoterack/slot stimmen nicht übereinanhand der obigen Tabelle korrigieren
Address out of rangeDB nicht im absoluten Adressmodus (Optimized)im TIA Portal DB-Eigenschaften → „Optimized block access“ AUS
alle Werte 0falsche DB-Nummer / falscher Offsetdieselbe Adresse mit der Watch table des TIA Portal per read prüfen
nur Bool wird nicht gelesen.bit in %DB1.DBX0.0 fehltDBX{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_typeformatplc_address BeispielBedeutung
Boolean(empty)%DB1.DBX0.0Bit 0 von Byte 0 in DB1
Boolean(empty)%DB1.DBX10.7Bit 7 von Byte 10 in DB1
Boolean(empty)%I0.0Input-Bit 0.0
Boolean(empty)%Q0.0Output-Bit 0.0
Boolean(empty)%M0.0Merker-Bit 0.0

8- / 16-Bit-Ganzzahlen

data_typeformatplc_address BeispielBedeutung
IntegerB%DB1.DBB0Byte (8-bit)
IntegerBYTE%MB10Merkerbyte 10
Integer(empty)%DB1.DBW0DB-Word (signed 16)
Integer(empty)%MW100Merkerwort 100

32-Bit-Ganzzahlen

data_typeformatplc_address BeispielBedeutung
IntegerDW%DB1.DBD0DB-Doppelwort (signed 32)
IntegerDWORD%MD100Merker-Doppelwort 100
IntegerUDW%DB1.DBD8unsigned 32

Gleitkomma (Float / Double)

data_typeformatplc_address BeispielBedeutung
FloatREAL%DB1.DBD0IEEE 754 32-bit (DBD = 4 Byte)
FloatREAL%MD200Merker-Float 200
DoubleLREAL%DB1.DBD8IEEE 754 64-bit (8 Byte)

Zeichenketten

data_typeformatplc_address BeispielBedeutung
StringSTR[16]%DB1.DBB100S7 STRING (max. 16 Zeichen), inkl. 2 Byte Header
StringSTR[32]%DB2.DBB0S7 STRING, max. 32

Einsatz von Formula

Zweckdata_typefomulaHinweis
Ganzzahl-Rohwert → Skalierung auf GleitkommaFloat${VALUE}*0.1DBW-Rohwert → Messwert
TemperaturkorrekturFloat${VALUE}+${TAG_OFFSET}Kalibrierung
Druckeinheiten-Umrechnung (Pa → kPa)Float${VALUE}/1000Einheitenumrechnung

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"}
]
}'