ModbusInstrument

Struct ModbusInstrument 

Source
pub struct ModbusInstrument {
    pub slave_addr: u8,
    pub port_path: String,
    pub baudrate: u64,
    pub timeout: Duration,
    pub ctx: Context,
}
Expand description

A generic async Modbus instrument.

Note: according to the Modbus spec, “coils” hold boolean values, while registers hold u16 values. This is reflected in the methods in this struct.

Fields§

§slave_addr: u8§port_path: String§baudrate: u64§timeout: Duration§ctx: Context

Implementations§

Source§

impl ModbusInstrument

Source

pub async fn new( slave_addr: u8, port_path: &str, baudrate: u64, timeout: Duration, ) -> Result<ModbusInstrument>

Creates a new ModbusInstrument. Opens a serial port on the given port path.

This will not fail if the device is unresponsive, only if the port file (/dev/ttyUSB0 or similar) doesn’t exist.

Source

pub async fn read_registers( &mut self, register: u16, count: u16, ) -> Result<Vec<u16>>

Asyncronously reads a number of registers.

Source

pub async fn write_register(&mut self, register: u16, value: u16) -> Result<()>

Writes to a register with the given u16. Returns Ok(()) on success.

Source

pub async fn read_coils(&mut self, coil: u16, count: u16) -> Result<Vec<bool>>

The same as read_registers(), but for coils

Source

pub async fn write_coil(&mut self, coil: u16, value: bool) -> Result<()>

The same as write_register(), but for coils

Trait Implementations§

Source§

impl Debug for ModbusInstrument

Source§

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

Formats the value using the given formatter. Read more

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> 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.