Makes a client on a port.
The line, opened at the speed and format the devices on it use.
The response timeout and the turnaround delay.
How long the client waits for a whole reply, in milliseconds.
How long the client leaves the line quiet after a broadcast, in milliseconds.
Reads coils, function 0x01.
The device, 1 to 247.
The first coil's address.
How many, 1 to 2000.
The coils' states, in address order.
ModbusClientError When the transaction fails.
Reads discrete inputs, function 0x02.
The device, 1 to 247.
The first input's address.
How many, 1 to 2000.
The inputs' states, in address order.
ModbusClientError When the transaction fails.
Reads holding registers, function 0x03.
The device, 1 to 247.
The first register's address.
How many, 1 to 125.
The registers' values, in address order.
ModbusClientError When the transaction fails.
Reads input registers, function 0x04.
The device, 1 to 247.
The first register's address.
How many, 1 to 125.
The registers' values, in address order.
ModbusClientError When the transaction fails.
Writes a run of coils, function 0x0F.
The device, 1 to 247, or BROADCAST for every device.
The first coil's address.
The states to write, 1 to 1968 of them, in address order.
ModbusClientError When the transaction fails.
Writes a run of holding registers, function 0x10.
The device, 1 to 247, or BROADCAST for every device.
The first register's address.
The values to write, 1 to 123 of them, in address order.
ModbusClientError When the transaction fails.
Writes one coil, function 0x05.
The device, 1 to 247, or BROADCAST for every device.
The coil's address.
The state to write.
ModbusClientError When the transaction fails.
Writes one holding register, function 0x06.
The device, 1 to 247, or BROADCAST for every device.
The register's address.
The value to write.
ModbusClientError When the transaction fails.
StaticframeThe silence that separates two frames: 3.5 characters at the line's speed and format, and a fixed 1750 microseconds above 19200 baud.
The line's speed and character format.
The silence, in nanoseconds, rounded up.
A Modbus RTU client on a serial line: the gateway, the master in the specification's words, that sends each request and waits for its reply.
Each transaction follows the Modbus over Serial Line specification. The client leaves the line silent for 3.5 characters, or 1.75 ms above 19200 baud; drops anything stale waiting in the port; writes the request; and reads the reply to the length the request implies, against the response timeout. The reply's CRC, unit, and function are checked before a value is read out of it, and any failure rejects with a ModbusClientError. A write to BROADCAST reaches every device and draws no reply, so the client waits out the turnaround delay instead. Each call runs on a worker thread.
Example