Skip to main content

ModbusMaster

Struct ModbusMaster 

Source
pub struct ModbusMaster<A: ApplicationLayer, P: PhysicalLayer> {
    pub timeout_ms: u64,
    pub concurrent: bool,
    /* private fields */
}

Fields§

§timeout_ms: u64§concurrent: bool

Implementations§

Source§

impl<A: ApplicationLayer + 'static, P: PhysicalLayer + 'static> ModbusMaster<A, P>

Source

pub fn new( application: Arc<A>, physical: Arc<P>, options: ModbusMasterOptions, ) -> Self

Source

pub fn is_open(&self) -> bool

Source

pub fn is_destroyed(&self) -> bool

Source

pub async fn open(&self, options: P::OpenOptions) -> Result<(), ModbusError>

Source

pub async fn close(&self) -> Result<(), ModbusError>

Source

pub async fn destroy(&self)

Source

pub async fn read_coils( &self, unit: u8, address: u16, length: u16, timeout_ms: Option<u64>, ) -> Result<Option<MasterResponse<Vec<bool>>>, ModbusError>

Source

pub async fn write_fc1( &self, unit: u8, address: u16, length: u16, timeout_ms: Option<u64>, ) -> Result<Option<MasterResponse<Vec<bool>>>, ModbusError>

Alias for Self::read_coils.

Source

pub async fn read_discrete_inputs( &self, unit: u8, address: u16, length: u16, timeout_ms: Option<u64>, ) -> Result<Option<MasterResponse<Vec<bool>>>, ModbusError>

Source

pub async fn write_fc2( &self, unit: u8, address: u16, length: u16, timeout_ms: Option<u64>, ) -> Result<Option<MasterResponse<Vec<bool>>>, ModbusError>

Source

pub async fn read_holding_registers( &self, unit: u8, address: u16, length: u16, timeout_ms: Option<u64>, ) -> Result<Option<MasterResponse<Vec<u16>>>, ModbusError>

Source

pub async fn write_fc3( &self, unit: u8, address: u16, length: u16, timeout_ms: Option<u64>, ) -> Result<Option<MasterResponse<Vec<u16>>>, ModbusError>

Source

pub async fn read_input_registers( &self, unit: u8, address: u16, length: u16, timeout_ms: Option<u64>, ) -> Result<Option<MasterResponse<Vec<u16>>>, ModbusError>

Source

pub async fn write_fc4( &self, unit: u8, address: u16, length: u16, timeout_ms: Option<u64>, ) -> Result<Option<MasterResponse<Vec<u16>>>, ModbusError>

Source

pub async fn write_single_coil( &self, unit: u8, address: u16, value: bool, timeout_ms: Option<u64>, ) -> Result<Option<MasterResponse<bool>>, ModbusError>

Source

pub async fn write_fc5( &self, unit: u8, address: u16, value: bool, timeout_ms: Option<u64>, ) -> Result<Option<MasterResponse<bool>>, ModbusError>

Source

pub async fn write_single_register( &self, unit: u8, address: u16, value: u16, timeout_ms: Option<u64>, ) -> Result<Option<MasterResponse<u16>>, ModbusError>

Source

pub async fn write_fc6( &self, unit: u8, address: u16, value: u16, timeout_ms: Option<u64>, ) -> Result<Option<MasterResponse<u16>>, ModbusError>

Source

pub async fn write_multiple_coils( &self, unit: u8, address: u16, values: &[bool], timeout_ms: Option<u64>, ) -> Result<Option<MasterResponse<Vec<bool>>>, ModbusError>

Source

pub async fn write_fc15( &self, unit: u8, address: u16, values: &[bool], timeout_ms: Option<u64>, ) -> Result<Option<MasterResponse<Vec<bool>>>, ModbusError>

Source

pub async fn write_multiple_registers( &self, unit: u8, address: u16, values: &[u16], timeout_ms: Option<u64>, ) -> Result<Option<MasterResponse<Vec<u16>>>, ModbusError>

Source

pub async fn write_fc16( &self, unit: u8, address: u16, values: &[u16], timeout_ms: Option<u64>, ) -> Result<Option<MasterResponse<Vec<u16>>>, ModbusError>

Source

pub async fn report_server_id( &self, unit: u8, server_id_length: usize, timeout_ms: Option<u64>, ) -> Result<Option<MasterResponse<ServerId>>, ModbusError>

Source

pub async fn handle_fc17( &self, unit: u8, server_id_length: usize, timeout_ms: Option<u64>, ) -> Result<Option<MasterResponse<ServerId>>, ModbusError>

Source

pub async fn mask_write_register( &self, unit: u8, address: u16, and_mask: u16, or_mask: u16, timeout_ms: Option<u64>, ) -> Result<Option<MasterResponse<(u16, u16)>>, ModbusError>

Source

pub async fn handle_fc22( &self, unit: u8, address: u16, and_mask: u16, or_mask: u16, timeout_ms: Option<u64>, ) -> Result<Option<MasterResponse<(u16, u16)>>, ModbusError>

Source

pub async fn read_and_write_multiple_registers( &self, unit: u8, read_address: u16, read_length: u16, write_address: u16, write_values: &[u16], timeout_ms: Option<u64>, ) -> Result<Option<MasterResponse<Vec<u16>>>, ModbusError>

Source

pub async fn handle_fc23( &self, unit: u8, read_address: u16, read_length: u16, write_address: u16, write_values: &[u16], timeout_ms: Option<u64>, ) -> Result<Option<MasterResponse<Vec<u16>>>, ModbusError>

Source

pub async fn read_device_identification( &self, unit: u8, read_device_id_code: u8, object_id: u8, timeout_ms: Option<u64>, ) -> Result<Option<MasterResponse<DeviceIdentification>>, ModbusError>

Source

pub async fn handle_fc43_14( &self, unit: u8, read_device_id_code: u8, object_id: u8, timeout_ms: Option<u64>, ) -> Result<Option<MasterResponse<DeviceIdentification>>, ModbusError>

Source

pub fn add_custom_function_code(&self, cfc: CustomFunctionCode)

Source

pub fn remove_custom_function_code(&self, fc: u8)

Source

pub async fn send_custom_fc( &self, unit: u8, fc: u8, data: Vec<u8>, timeout_ms: Option<u64>, ) -> Result<Option<MasterResponse<Vec<u8>>>, ModbusError>

Send a non-standard / custom function code request. The master only validates that the response has matching unit and fc; any payload is returned as raw bytes. The caller must have registered a CustomFunctionCode with predict_response_length on the application layer (or on this master) so RTU framing can advance.

unit == 0 is broadcast: returns Ok(None) after the write.

Auto Trait Implementations§

§

impl<A, P> !Freeze for ModbusMaster<A, P>

§

impl<A, P> !RefUnwindSafe for ModbusMaster<A, P>

§

impl<A, P> Send for ModbusMaster<A, P>

§

impl<A, P> Sync for ModbusMaster<A, P>

§

impl<A, P> Unpin for ModbusMaster<A, P>

§

impl<A, P> UnsafeUnpin for ModbusMaster<A, P>

§

impl<A, P> UnwindSafe for ModbusMaster<A, P>

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.