Skip to main content

Crate modbus_read

Crate modbus_read 

Source
Expand description

Read-only Modbus TCP client.

Modbus TCP is a request/response protocol: an MBAP header sits in front of a short PDU. This crate encodes a read, decodes the reply, and turns the 16-bit register words into numbers.

A write cannot be spelled. FunctionCode has two variants, 3 and 4. A write function code is not a value this crate refuses at run time; it is a value that does not exist.

The request decodes its own answer. A device that answered a read the caller had given up on leaves a whole, well-formed frame behind it. With the request in hand, the echoed transaction id, unit id, function code and register count are all checked, and that frame is a typed refusal instead. Vary the TransactionId between reads; a constant id makes the echo check agree with every frame.

One action, and it owns no connection. read_registers writes a frame and reads the frame that comes back over anything that is std::io::Read and std::io::Write. It holds no socket.

Enable the test-server feature for a loopback device that serves synthetic registers and refuses every other function code.

Structs§

ReadRequest
One read, complete enough to be a frame and to judge the frame that comes back.
RegisterAddress
Where in a device’s register map a read starts.
RegisterCount
How many 16-bit registers a read asks for.
Scale
The factor a register map applies to a decoded word.
TransactionId
The number a device uses to tell one request from another.
UnitId
Which device on the far side of the connection is being asked.

Enums§

ExceptionCode
Why a device refused a read, in its own words.
ExchangeError
What an exchange refuses: the frame, or the transport under it.
FunctionCode
The Modbus function codes this crate can express. There are two.
ModbusError
What a Modbus read refuses, on the way out and on the way back.
RegisterKind
How a device’s register map spells one quantity.

Constants§

MAX_REGISTERS
The most registers function codes 3 and 4 can answer in one frame.

Functions§

read_registers
Ask a device for the registers a read names, and read its answer.