pub struct ModbusRtuClient { /* private fields */ }Expand description
Modbus RTU client for serial communication
Implements async Modbus RTU protocol over RS-232/RS-485 serial ports.
§Example
use oxirs_modbus::protocol::rtu::ModbusRtuClient;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut client = ModbusRtuClient::open("/dev/ttyUSB0", 9600, 1)?;
let registers = client.read_holding_registers(0, 10).await?;
println!("Registers: {:?}", registers);
Ok(())
}Implementations§
Source§impl ModbusRtuClient
impl ModbusRtuClient
Sourcepub fn open_with_settings(
port: &str,
baud_rate: u32,
unit_id: u8,
data_bits: DataBits,
parity: Parity,
stop_bits: StopBits,
) -> ModbusResult<Self>
pub fn open_with_settings( port: &str, baud_rate: u32, unit_id: u8, data_bits: DataBits, parity: Parity, stop_bits: StopBits, ) -> ModbusResult<Self>
Open with custom serial settings
§Arguments
port- Serial port pathbaud_rate- Baud rateunit_id- Modbus unit IDdata_bits- Number of data bitsparity- Parity settingstop_bits- Stop bits
Sourcepub fn set_timeout(&mut self, timeout: Duration)
pub fn set_timeout(&mut self, timeout: Duration)
Set response timeout
Sourcepub async fn read_holding_registers(
&mut self,
start_address: u16,
count: u16,
) -> ModbusResult<Vec<u16>>
pub async fn read_holding_registers( &mut self, start_address: u16, count: u16, ) -> ModbusResult<Vec<u16>>
Sourcepub async fn read_input_registers(
&mut self,
start_address: u16,
count: u16,
) -> ModbusResult<Vec<u16>>
pub async fn read_input_registers( &mut self, start_address: u16, count: u16, ) -> ModbusResult<Vec<u16>>
Sourcepub async fn write_single_register(
&mut self,
address: u16,
value: u16,
) -> ModbusResult<()>
pub async fn write_single_register( &mut self, address: u16, value: u16, ) -> ModbusResult<()>
Write a single register (function code 0x06)
§Arguments
address- Register addressvalue- Value to write
Sourcepub async fn read_coils(
&mut self,
start_address: u16,
count: u16,
) -> ModbusResult<Vec<bool>>
pub async fn read_coils( &mut self, start_address: u16, count: u16, ) -> ModbusResult<Vec<bool>>
Sourcepub async fn read_discrete_inputs(
&mut self,
start_address: u16,
count: u16,
) -> ModbusResult<Vec<bool>>
pub async fn read_discrete_inputs( &mut self, start_address: u16, count: u16, ) -> ModbusResult<Vec<bool>>
Auto Trait Implementations§
impl Freeze for ModbusRtuClient
impl !RefUnwindSafe for ModbusRtuClient
impl Send for ModbusRtuClient
impl Sync for ModbusRtuClient
impl Unpin for ModbusRtuClient
impl !UnwindSafe for ModbusRtuClient
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more