ModbusTCPTransport#

class ModbusTCPTransport(host: str, port: int = 502, timeout: float = 3.0)[source]#

Bases: ModbusTransport

A Modbus TCP line. One socket, addressed per wire op via unit_id.

Validate and store host, port, and timeout.

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.