Data Types

The datatypes module provides S7 data type definitions and address encoding.

S7 data types and conversion utilities.

Handles S7-specific data types, endianness conversion, and address encoding.

class snap7.datatypes.S7Area(*values)[source]

S7 memory area identifiers.

class snap7.datatypes.S7DataTypes[source]

S7 data type conversion utilities.

static decode_s7_data(data: bytes, word_len: S7WordLen, count: int) List[bool | int | float][source]

Decode S7 data from bytes to Python values.

Handles Siemens big-endian byte order.

static encode_address(area: S7Area, db_number: int, start: int, word_len: S7WordLen, count: int) bytes[source]

Encode S7 address into parameter format.

Returns 12-byte parameter section for read/write operations.

static encode_s7_data(values: Sequence[bool | int | float], word_len: S7WordLen) bytes[source]

Encode Python values to S7 data bytes.

Handles Siemens big-endian byte order.

static get_size_bytes(word_len: S7WordLen, count: int = 1) int[source]

Get total size in bytes for given word length and count.

static parse_address(address_str: str) Tuple[S7Area, int, int][source]

Parse S7 address string to area, DB number, and offset.

Examples: - “DB1.DBX0.0” -> (DB, 1, 0) - “M10.5” -> (MK, 0, 85) # bit 5 of byte 10 = bit 85 - “IW20” -> (PE, 0, 20)

class snap7.datatypes.S7WordLen(*values)[source]

S7 data word length identifiers.