Skip to content

Advanced API

Tier: Advanced / Evolving

Lower-level bank metadata and Modbus mapping helpers.

pyclickplc.BANKS module-attribute

BANKS: dict[str, BankConfig] = {
    "X": BankConfig(
        "X", 1, 816, BIT, valid_ranges=_SPARSE_RANGES
    ),
    "Y": BankConfig(
        "Y", 1, 816, BIT, valid_ranges=_SPARSE_RANGES
    ),
    "C": BankConfig("C", 1, 2000, BIT),
    "T": BankConfig(
        "T", 1, 500, BIT, interleaved_with="TD"
    ),
    "CT": BankConfig(
        "CT", 1, 250, BIT, interleaved_with="CTD"
    ),
    "SC": BankConfig("SC", 1, 1000, BIT),
    "DS": BankConfig("DS", 1, 4500, INT),
    "DD": BankConfig("DD", 1, 1000, INT2),
    "DH": BankConfig("DH", 1, 500, HEX),
    "DF": BankConfig("DF", 1, 500, FLOAT),
    "XD": BankConfig("XD", 0, 16, HEX),
    "YD": BankConfig("YD", 0, 16, HEX),
    "TD": BankConfig(
        "TD", 1, 500, INT, interleaved_with="T"
    ),
    "CTD": BankConfig(
        "CTD", 1, 250, INT2, interleaved_with="CT"
    ),
    "SD": BankConfig("SD", 1, 1000, INT),
    "TXT": BankConfig("TXT", 1, 1000, TXT),
}

pyclickplc.BankConfig dataclass

Configuration for a single PLC memory bank.

pyclickplc.DataType

Bases: IntEnum

DataType mapping from MDB database.

pyclickplc.ModbusMapping dataclass

Modbus address mapping configuration for a PLC memory bank.

is_writable property

is_writable: bool

True if any write FC (5, 6, 15, 16) is in function_codes.

pyclickplc.plc_to_modbus

plc_to_modbus(bank: str, index: int) -> tuple[int, int]

Map PLC address to (modbus_address, register_count).

Parameters:

Name Type Description Default
bank str

Bank name (e.g. "X", "DS", "XD")

required
index int

MDB index (e.g. 1 for X001, 0 for XD0, 2 for XD1)

required

Returns:

Type Description
tuple[int, int]

Tuple of (modbus_address, register_count)

Raises:

Type Description
ValueError

If bank or index is invalid

pyclickplc.modbus_to_plc

modbus_to_plc(
    address: int, is_coil: bool
) -> tuple[str, int] | None

Reverse map Modbus address to (bank, display_index) or None.

Parameters:

Name Type Description Default
address int

Raw Modbus coil or register address

required
is_coil bool

True for coil address space, False for register space

required

Returns:

Type Description
tuple[str, int] | None

Tuple of (bank_name, display_index) or None if unmapped

pyclickplc.pack_value

pack_value(
    value: bool | int | float | str, data_type: DataType
) -> list[int]

Pack a Python value into Modbus register(s).

Parameters:

Name Type Description Default
value bool | int | float | str

The value to pack

required
data_type DataType

The DataType determining the encoding

required

Returns:

Type Description
list[int]

List of 16-bit register values

Raises:

Type Description
ValueError

If data_type is BIT (coils don't use register packing)

pyclickplc.unpack_value

unpack_value(
    registers: list[int], data_type: DataType
) -> int | float | str

Unpack Modbus register(s) into a Python value.

Parameters:

Name Type Description Default
registers list[int]

List of 16-bit register values

required
data_type DataType

The DataType determining the decoding

required

Returns:

Type Description
int | float | str

The unpacked Python value