PPI

Serial PPI transport and client support for S7-200 PLCs. Install the optional dependency with pip install "python-snap7[ppi]" and see S7-200 Serial PPI for setup, area semantics, and current limitations.

Siemens S7-200 PPI serial transport and client.

PPI carries ordinary S7 PDUs inside PROFIBUS-style SD1/SD2 frames. The implementation follows the request/acknowledgement exchange used by libnodave: an SD2 request, an E5 acknowledgement, an SD1 request-data poll, and an SD2 response.

class snap7.ppi.PPIArea(*values)[source]

Bases: IntEnum

S7-200 memory area identifiers.

class snap7.ppi.PPIClient(port: str, *, station: int = 2, local_station: int = 0, baudrate: int = 9600, timeout: float = 0.15, transport: PPIExchangeTransport | None = None)[source]

Bases: object

Minimal S7-200 client using PPI over a serial port.

connect() → PPIClient[source]

Open the serial port and negotiate the S7 PDU length.

disconnect() → None[source]

Close the PPI transport.

read_area(area: PPIArea, start: int, count: int) → bytearray[source]

Read items from an S7-200 memory area.

count is bytes for S/SM/I/Q/M/V and 16-bit items for AI/AQ/C/T.

v_read(start: int, size: int) → bytearray[source]

Read bytes from S7-200 V memory (wire-level DB1).

v_write(start: int, data: bytes | bytearray) → None[source]

Write bytes to S7-200 V memory (wire-level DB1).

write_area(area: PPIArea, start: int, data: bytes | bytearray) → None[source]

Write data to an S7-200 memory area.

class snap7.ppi.PPIExchangeTransport(*args, **kwargs)[source]

Bases: Protocol

Transport interface consumed by PPIClient.

class snap7.ppi.PPIFrame(frame_type: PPIFrameType, destination: int | None = None, source: int | None = None, control: int | None = None, payload: bytes = b'')[source]

Bases: object

Decoded PPI frame.

class snap7.ppi.PPIFrameType(*values)[source]

Bases: IntEnum

PPI/PROFIBUS frame delimiters.

class snap7.ppi.PPITransport(port: str, *, station: int = 2, local_station: int = 0, baudrate: int = 9600, timeout: float = 0.15, retries: int = 3, serial_port: SerialPort | None = None)[source]

Bases: object

Serial PPI master transport for a single S7-200 slave.

close() → None[source]

Close a serial port opened by this transport.

exchange(pdu: bytes) → bytes[source]

Exchange one S7 PDU with the configured S7-200 station.

open() → None[source]

Open the configured serial port using PPI’s 8E1 settings.

class snap7.ppi.SerialPort(*args, **kwargs)[source]

Bases: Protocol

Minimal serial-port interface used by PPITransport.

snap7.ppi.decode_frame(data: bytes) → PPIFrame[source]

Decode and validate one complete PPI frame.

snap7.ppi.encode_sd1(destination: int, source: int, control: int) → bytes[source]

Encode a fixed-length SD1 frame.

snap7.ppi.encode_sd2(destination: int, source: int, control: int, payload: bytes) → bytes[source]

Encode a variable-length SD2 frame.

snap7.ppi.encode_sd3(destination: int, source: int, control: int, payload: bytes) → bytes[source]

Encode an SD3 frame with its fixed eight-byte data field.