|
| 1 | +Tags |
| 2 | +==== |
| 3 | + |
| 4 | +Symbolic and typed access to PLC variables. |
| 5 | + |
| 6 | +A :class:`~snap7.tags.Tag` describes a typed value at a specific S7 address. |
| 7 | +Tags can be constructed from a PLC4X-style address string, or loaded in |
| 8 | +bulk from CSV, JSON, or TIA Portal XML exports. |
| 9 | + |
| 10 | +.. code-block:: python |
| 11 | +
|
| 12 | + from s7 import Client, Tag, load_tia_xml |
| 13 | +
|
| 14 | + client = Client() |
| 15 | + client.connect("192.168.1.10", 0, 1) |
| 16 | +
|
| 17 | + # Ad-hoc access with PLC4X-style strings |
| 18 | + speed = client.read_tag("DB1.DBD0:REAL") |
| 19 | + running = client.read_tag("DB1.DBX4.0:BOOL") |
| 20 | + client.write_tag("DB1.DBW6:INT", 1500) |
| 21 | +
|
| 22 | + # Batch read (uses optimizer when enabled) |
| 23 | + values = client.read_tags(["DB1.DBD0:REAL", "DB1.DBW6:INT"]) |
| 24 | +
|
| 25 | + # Load named tags from a TIA Portal XML export |
| 26 | + tags = load_tia_xml("db1.xml") |
| 27 | + temperature = client.read_tag(tags["Motor.Temperature"]) |
| 28 | +
|
| 29 | +Address syntax |
| 30 | +-------------- |
| 31 | + |
| 32 | +Tag addresses follow the PLC4X / Siemens STEP7 convention:: |
| 33 | + |
| 34 | + DB1.DBX0.0:BOOL # bit in data block |
| 35 | + DB1.DBB10:BYTE # byte |
| 36 | + DB1.DBW10:INT # word (2 bytes) |
| 37 | + DB1.DBD10:REAL # double word (4 bytes) |
| 38 | + DB1:10:INT # short form (DB 1, offset 10) |
| 39 | + DB1:10:STRING[20] # variable-length string |
| 40 | + DB1:10:REAL[5] # array of 5 REALs |
| 41 | + M10.5:BOOL # Merker bit |
| 42 | + MW20:WORD # Merker word |
| 43 | + I0.0:BOOL # input bit |
| 44 | + Q0.0:BOOL # output bit |
| 45 | + |
| 46 | +The leading ``%`` is optional (``%DB1.DBX0.0:BOOL`` also works). |
| 47 | + |
| 48 | +Supported types |
| 49 | +--------------- |
| 50 | + |
| 51 | +``BOOL``, ``BYTE``, ``CHAR``, ``WCHAR``, ``SINT``, ``USINT``, ``INT``, |
| 52 | +``UINT``, ``WORD``, ``DINT``, ``UDINT``, ``DWORD``, ``LINT``, ``ULINT``, |
| 53 | +``LWORD``, ``REAL``, ``LREAL``, ``TIME``, ``LTIME``, ``TOD``, ``LTOD``, |
| 54 | +``DATE``, ``DT``, ``LDT``, ``DTL``, ``STRING[n]``, ``WSTRING[n]``, |
| 55 | +``FSTRING[n]``. |
| 56 | + |
| 57 | +Arrays are supported for any fixed-size type via ``[count]`` suffix. |
| 58 | + |
| 59 | +API reference |
| 60 | +------------- |
| 61 | + |
| 62 | +.. automodule:: snap7.tags |
| 63 | + :members: |
0 commit comments