pub struct ModbusClient<D: DataLink> { /* private fields */ }Expand description
Async Modbus client that wraps a DataLink transport.
The client is cheaply cloneable — all clones share the same underlying transport, throttle state, and metrics counters.
Implementations§
Source§impl<D: DataLink> ModbusClient<D>
impl<D: DataLink> ModbusClient<D>
Sourcepub fn with_config(datalink: D, config: ClientConfig) -> Self
pub fn with_config(datalink: D, config: ClientConfig) -> Self
Create a new client with the given configuration.
Sourcepub fn config(&self) -> ClientConfig
pub fn config(&self) -> ClientConfig
Return the current client configuration.
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Check if the underlying transport is connected.
Sourcepub async fn read_coils(
&self,
unit_id: UnitId,
start: u16,
quantity: u16,
) -> Result<Vec<bool>, ClientError>
pub async fn read_coils( &self, unit_id: UnitId, start: u16, quantity: u16, ) -> Result<Vec<bool>, ClientError>
Read coils (FC01) starting at start, returning quantity boolean values.
Sourcepub async fn custom_request(
&self,
unit_id: UnitId,
function_code: u8,
payload: &[u8],
) -> Result<Vec<u8>, ClientError>
pub async fn custom_request( &self, unit_id: UnitId, function_code: u8, payload: &[u8], ) -> Result<Vec<u8>, ClientError>
Send a custom (user-defined) function code request and return the raw response payload.
Sourcepub async fn report_server_id(
&self,
unit_id: UnitId,
) -> Result<ReportServerIdResponse, ClientError>
pub async fn report_server_id( &self, unit_id: UnitId, ) -> Result<ReportServerIdResponse, ClientError>
Report Server ID (FC17) — returns the device identifier and run status.
Sourcepub async fn read_device_identification(
&self,
unit_id: UnitId,
read_device_id_code: u8,
object_id: u8,
) -> Result<ReadDeviceIdentificationResponse, ClientError>
pub async fn read_device_identification( &self, unit_id: UnitId, read_device_id_code: u8, object_id: u8, ) -> Result<ReadDeviceIdentificationResponse, ClientError>
Read Device Identification (FC43/0x0E) — returns device info objects.
Sourcepub async fn read_discrete_inputs(
&self,
unit_id: UnitId,
start: u16,
quantity: u16,
) -> Result<Vec<bool>, ClientError>
pub async fn read_discrete_inputs( &self, unit_id: UnitId, start: u16, quantity: u16, ) -> Result<Vec<bool>, ClientError>
Read discrete inputs (FC02) starting at start, returning quantity boolean values.
Sourcepub async fn read_holding_registers(
&self,
unit_id: UnitId,
start: u16,
quantity: u16,
) -> Result<Vec<u16>, ClientError>
pub async fn read_holding_registers( &self, unit_id: UnitId, start: u16, quantity: u16, ) -> Result<Vec<u16>, ClientError>
Read holding registers (FC03) starting at start, returning quantity 16-bit values.
Sourcepub async fn read_input_registers(
&self,
unit_id: UnitId,
start: u16,
quantity: u16,
) -> Result<Vec<u16>, ClientError>
pub async fn read_input_registers( &self, unit_id: UnitId, start: u16, quantity: u16, ) -> Result<Vec<u16>, ClientError>
Read input registers (FC04) starting at start, returning quantity 16-bit values.
Sourcepub async fn write_single_coil(
&self,
unit_id: UnitId,
address: u16,
value: bool,
) -> Result<(), ClientError>
pub async fn write_single_coil( &self, unit_id: UnitId, address: u16, value: bool, ) -> Result<(), ClientError>
Write a single coil (FC05) at address to value.
Sourcepub async fn write_single_register(
&self,
unit_id: UnitId,
address: u16,
value: u16,
) -> Result<(), ClientError>
pub async fn write_single_register( &self, unit_id: UnitId, address: u16, value: u16, ) -> Result<(), ClientError>
Write a single holding register (FC06) at address to value.
Sourcepub async fn mask_write_register(
&self,
unit_id: UnitId,
address: u16,
and_mask: u16,
or_mask: u16,
) -> Result<(), ClientError>
pub async fn mask_write_register( &self, unit_id: UnitId, address: u16, and_mask: u16, or_mask: u16, ) -> Result<(), ClientError>
Mask write register (FC22): result = (current AND and_mask) OR (or_mask AND NOT and_mask).
Sourcepub async fn write_multiple_coils(
&self,
unit_id: UnitId,
start: u16,
values: &[bool],
) -> Result<(), ClientError>
pub async fn write_multiple_coils( &self, unit_id: UnitId, start: u16, values: &[bool], ) -> Result<(), ClientError>
Write multiple coils (FC15) starting at start.
Sourcepub async fn write_multiple_registers(
&self,
unit_id: UnitId,
start: u16,
values: &[u16],
) -> Result<(), ClientError>
pub async fn write_multiple_registers( &self, unit_id: UnitId, start: u16, values: &[u16], ) -> Result<(), ClientError>
Write multiple holding registers (FC16) starting at start.
Sourcepub async fn read_write_multiple_registers(
&self,
unit_id: UnitId,
read_start: u16,
read_quantity: u16,
write_start: u16,
write_values: &[u16],
) -> Result<Vec<u16>, ClientError>
pub async fn read_write_multiple_registers( &self, unit_id: UnitId, read_start: u16, read_quantity: u16, write_start: u16, write_values: &[u16], ) -> Result<Vec<u16>, ClientError>
Atomically read and write multiple registers (FC23).
Sourcepub async fn read_coils_raw(
&self,
unit_id: UnitId,
start: u16,
quantity: u16,
) -> Result<(Vec<u8>, u16), ClientError>
pub async fn read_coils_raw( &self, unit_id: UnitId, start: u16, quantity: u16, ) -> Result<(Vec<u8>, u16), ClientError>
Read coils returning raw packed bytes and the quantity, avoiding the
8x memory expansion of Vec<bool>.
Sourcepub async fn read_discrete_inputs_raw(
&self,
unit_id: UnitId,
start: u16,
quantity: u16,
) -> Result<(Vec<u8>, u16), ClientError>
pub async fn read_discrete_inputs_raw( &self, unit_id: UnitId, start: u16, quantity: u16, ) -> Result<(Vec<u8>, u16), ClientError>
Read discrete inputs returning raw packed bytes and the quantity.
Sourcepub async fn read_exception_status(
&self,
unit_id: UnitId,
) -> Result<u8, ClientError>
pub async fn read_exception_status( &self, unit_id: UnitId, ) -> Result<u8, ClientError>
FC07 - Read Exception Status
Sourcepub async fn diagnostics(
&self,
unit_id: UnitId,
sub_function: u16,
data: u16,
) -> Result<(u16, u16), ClientError>
pub async fn diagnostics( &self, unit_id: UnitId, sub_function: u16, data: u16, ) -> Result<(u16, u16), ClientError>
FC08 - Diagnostics
Sourcepub async fn read_fifo_queue(
&self,
unit_id: UnitId,
address: u16,
) -> Result<Vec<u16>, ClientError>
pub async fn read_fifo_queue( &self, unit_id: UnitId, address: u16, ) -> Result<Vec<u16>, ClientError>
FC24 - Read FIFO Queue