pub struct ReadRequest { /* private fields */ }Expand description
One read, complete enough to be a frame and to judge the frame that comes back.
Implementations§
Source§impl ReadRequest
impl ReadRequest
Sourcepub fn new(
transaction: TransactionId,
unit: UnitId,
function: FunctionCode,
start: RegisterAddress,
count: RegisterCount,
) -> Result<Self, ModbusError>
pub fn new( transaction: TransactionId, unit: UnitId, function: FunctionCode, start: RegisterAddress, count: RegisterCount, ) -> Result<Self, ModbusError>
A read a device could answer.
§Errors
Returns ModbusError::PastEndOfAddressSpace when the last register
asked for is past the end of the 16-bit address space — a request no
device can answer, caught where it is written rather than later in an
exception reply.
Sourcepub const fn transaction(&self) -> TransactionId
pub const fn transaction(&self) -> TransactionId
The id this read carries, and the id its answer must echo.
Sourcepub const fn function(&self) -> FunctionCode
pub const fn function(&self) -> FunctionCode
Which of the two read tables this read asks about.
Sourcepub const fn start(&self) -> RegisterAddress
pub const fn start(&self) -> RegisterAddress
Where in the map this read starts.
Sourcepub const fn count(&self) -> RegisterCount
pub const fn count(&self) -> RegisterCount
How many registers this read asks for, and so how many bytes its answer owes.
Sourcepub fn encode(&self) -> Vec<u8> ⓘ
pub fn encode(&self) -> Vec<u8> ⓘ
This read, as the bytes that go on the wire.
Big-endian throughout, which is the protocol’s order and not a choice.
Sourcepub fn decode(&self, frame: &[u8]) -> Result<Vec<u16>, ModbusError>
pub fn decode(&self, frame: &[u8]) -> Result<Vec<u16>, ModbusError>
What a device sent back, as the registers this read asked for.
The frame is the whole reply, header included, exactly as many bytes as its length field declares. Everything the device echoed is checked against this request before a single register is believed, which is what keeps a late answer to a previous read from being taken as this one’s.
§Errors
Returns ModbusError::Exception when the device refused the read,
and one of the framing or echo variants when the frame is not an
answer to this request. No reply produces a panic and none produces
registers the device did not send.