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: ContextImplementations§
Source§impl ModbusInstrument
impl ModbusInstrument
Sourcepub async fn new(
slave_addr: u8,
port_path: &str,
baudrate: u64,
timeout: Duration,
) -> Result<ModbusInstrument>
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.
Sourcepub async fn read_registers(
&mut self,
register: u16,
count: u16,
) -> Result<Vec<u16>>
pub async fn read_registers( &mut self, register: u16, count: u16, ) -> Result<Vec<u16>>
Asyncronously reads a number of registers.
Sourcepub async fn write_register(&mut self, register: u16, value: u16) -> Result<()>
pub async fn write_register(&mut self, register: u16, value: u16) -> Result<()>
Writes to a register with the given u16. Returns Ok(()) on success.
Sourcepub async fn read_coils(&mut self, coil: u16, count: u16) -> Result<Vec<bool>>
pub async fn read_coils(&mut self, coil: u16, count: u16) -> Result<Vec<bool>>
The same as read_registers(), but for coils
Sourcepub async fn write_coil(&mut self, coil: u16, value: bool) -> Result<()>
pub async fn write_coil(&mut self, coil: u16, value: bool) -> Result<()>
The same as write_register(), but for coils
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ModbusInstrument
impl !RefUnwindSafe for ModbusInstrument
impl Send for ModbusInstrument
impl !Sync for ModbusInstrument
impl Unpin for ModbusInstrument
impl !UnwindSafe for ModbusInstrument
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more