Struct Request

Source
pub struct Request<'a> { /* private fields */ }

Implementations§

Source§

impl<'a> Request<'a>

Source

pub fn new(modbus_id: u8, form: &'a RequestForm<'_>) -> Request<'a>

Creates a new Modbus RTU request instance.


§Arguments
  • modbus_id: The Modbus slave ID
  • form: A reference to the request form

§Returns

A new instance of Request containing the specified Modbus ID and form


§Examples
use modbus_rtu::common::{Request, RequestForm};
 
let read_value_form = RequestForm::ReadInputRegisters {
    start_register: 0x0000,
    registers_count: 12,
};
 
let request = Request::new(0x01, &read_value_form);
Source

pub fn to_packet(&self, buffer: &'a mut [u8; 256]) -> &'a [u8]

Writes a Modbus RTU request packet into the provided buffer and returns the corresponding slice.


§Arguments
  • buffer: The buffer into which the packet will be written

§Returns

A slice representing the constructed Modbus RTU request packet


§Examples
use modbus_rtu::common::{Request, RequestForm};

let write_datas_form = RequestForm::WriteMultipleRegisters {
    start_register: 0x0001,
    datas_to_write: &[0x1234, 0x5678],
};

let request = Request::new(0x01, &write_datas_form);

let mut buffer: [u8; 256] = [0; 256];
let packet = request.to_packet(&mut buffer);

assert_eq!(packet, &[0x01, 0x10, 0x00, 0x01, 0x00, 0x02, 0x04, 0x12, 0x34, 0x56, 0x78, 0x49, 0x57]);

Trait Implementations§

Source§

impl<'a> Debug for Request<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Request<'a>

§

impl<'a> RefUnwindSafe for Request<'a>

§

impl<'a> Send for Request<'a>

§

impl<'a> Sync for Request<'a>

§

impl<'a> Unpin for Request<'a>

§

impl<'a> UnwindSafe for Request<'a>

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.