ModbusTransport#

class ModbusTransport[source]#

Bases: TransportBase, ABC

Abstract Modbus line: owns the session, locking, and every wire op, addressed per call via unit_id. Annotate against it; construct a concrete subclass.

Initialize holder tracking, the lock, and the (not yet connected) client slot.

Attributes

is_open

Whether the client has been opened and not closed.

Methods

check_unit_id

Validate unit_id against this physical layer's range (0 to _max_unit_id) and return it.

close

Close and teardown; with a holder, remove it and tear down only when the last owner leaves.

lock

Return the reentrant resource lock for atomic multi-step sequences; the holder may write/query/read inside it.

open

Open the connection (idempotent); with a holder, admit it and return True only for the first owner.

read_coils

Read coils by address (FC01).

read_discrete_inputs

Read discrete inputs by address (FC02).

read_holding_registers

Read holding registers by address (FC03).

read_input_registers

Read input registers by address (FC04).

read_typed

Read address as data_type, dispatching by register_type and decoding across registers.

write_coil

Write a single coil by address (FC05).

write_coils

Write multiple coils by address (FC15).

write_holding_register

Write a single holding register by address (FC06).

write_holding_registers

Write multiple holding registers by address (FC16).

write_typed

Encode value as data_type and write it to address, dispatching by register_type.