Connection
The connection module implements the ISO on TCP transport layer (TPKT/COTP) used for S7 communication.
ISO on TCP connection management (RFC 1006).
Implements TPKT (Transport Service on top of TCP) and COTP (Connection Oriented Transport Protocol) layers for S7 communication.
- class snap7.connection.ISOTCPConnection(host: str, port: int = 102, local_tsap: int = 256, remote_tsap: int = 258, tpdu_size: TPDUSize = TPDUSize.S_1024)[source]
ISO on TCP connection implementation.
Handles the transport layer for S7 communication including: - TCP socket management - TPKT framing (RFC 1006) - COTP connection setup and data transfer - PDU size negotiation
- __enter__() ISOTCPConnection[source]
Context manager entry.
- __exit__(exc_type: Type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None) None[source]
Context manager exit.
- __init__(host: str, port: int = 102, local_tsap: int = 256, remote_tsap: int = 258, tpdu_size: TPDUSize = TPDUSize.S_1024)[source]
Initialize ISO TCP connection.
- Parameters:
host – Target PLC IP address
port – TCP port (default 102 for S7)
local_tsap – Local Transport Service Access Point
remote_tsap – Remote Transport Service Access Point
tpdu_size – TPDU size to request during COTP negotiation
- check_connection() bool[source]
Check if the TCP connection is still alive.
Uses a non-blocking socket peek to detect broken connections.