Skip to main content

ReadRequest

Struct ReadRequest 

Source
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

Source

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.

Source

pub const fn transaction(&self) -> TransactionId

The id this read carries, and the id its answer must echo.

Source

pub const fn unit(&self) -> UnitId

The device this read is addressed to.

Source

pub const fn function(&self) -> FunctionCode

Which of the two read tables this read asks about.

Source

pub const fn start(&self) -> RegisterAddress

Where in the map this read starts.

Source

pub const fn count(&self) -> RegisterCount

How many registers this read asks for, and so how many bytes its answer owes.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for ReadRequest

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ReadRequest

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for ReadRequest

Source§

impl PartialEq for ReadRequest

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ReadRequest

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.