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§
- Read
Request - One read, complete enough to be a frame and to judge the frame that comes back.
- Register
Address - Where in a device’s register map a read starts.
- Register
Count - How many 16-bit registers a read asks for.
- Scale
- The factor a register map applies to a decoded word.
- Transaction
Id - 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§
- Exception
Code - Why a device refused a read, in its own words.
- Exchange
Error - What an exchange refuses: the frame, or the transport under it.
- Function
Code - The Modbus function codes this crate can express. There are two.
- Modbus
Error - What a Modbus read refuses, on the way out and on the way back.
- Register
Kind - 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.