pub struct AsyncTcpClient<const N: usize = 9> { /* private fields */ }Expand description
Async Modbus TCP client facade.
All Modbus request methods (read_holding_registers, write_single_coil,
etc.) are available directly on this type via Deref to
AsyncClientCore.
The constant generic parameter N is the compile-time pipeline depth
(default 9).
Implementations§
Source§impl AsyncTcpClient
impl AsyncTcpClient
Sourcepub fn connect(host: &str, port: u16) -> Result<AsyncTcpClient, AsyncError>
👎Deprecated: use AsyncTcpClient::new(…) and then client.connect().await
pub fn connect(host: &str, port: u16) -> Result<AsyncTcpClient, AsyncError>
use AsyncTcpClient::new(…) and then client.connect().await
Deprecated constructor alias.
Use AsyncTcpClient::new and then call client.connect().await?.
Sourcepub fn connect_with_poll_interval(
host: &str,
port: u16,
_poll_interval: Duration,
) -> Result<AsyncTcpClient, AsyncError>
👎Deprecated: use AsyncTcpClient::new(…) and then client.connect().await
pub fn connect_with_poll_interval( host: &str, port: u16, _poll_interval: Duration, ) -> Result<AsyncTcpClient, AsyncError>
use AsyncTcpClient::new(…) and then client.connect().await
Deprecated constructor alias.
Use AsyncTcpClient::new and then call client.connect().await?.
Sourcepub fn new(host: &str, port: u16) -> Result<AsyncTcpClient, AsyncError>
pub fn new(host: &str, port: u16) -> Result<AsyncTcpClient, AsyncError>
Creates an async TCP client for host:port without connecting.
Uses the default pipeline depth of 9. Call AsyncClientCore::connect
on the returned client before sending requests.
Sourcepub fn new_with_poll_interval(
host: &str,
port: u16,
_poll_interval: Duration,
) -> Result<AsyncTcpClient, AsyncError>
pub fn new_with_poll_interval( host: &str, port: u16, _poll_interval: Duration, ) -> Result<AsyncTcpClient, AsyncError>
Creates an async TCP client for host:port with a custom
poll_interval.
The poll interval is ignored in the async implementation.
Uses the default pipeline depth of 9. Call AsyncClientCore::connect
on the returned client before sending requests.
Sourcepub fn new_with_config(
tcp_config: ModbusTcpConfig,
_poll_interval: Duration,
) -> Result<AsyncTcpClient, AsyncError>
pub fn new_with_config( tcp_config: ModbusTcpConfig, _poll_interval: Duration, ) -> Result<AsyncTcpClient, AsyncError>
Creates an async TCP client with a fully custom ModbusTcpConfig,
using the default pipeline depth of 9.
Call AsyncClientCore::connect on the returned client before sending
requests.
Source§impl<const N: usize> AsyncTcpClient<N>
impl<const N: usize> AsyncTcpClient<N>
Sourcepub fn connect_with_pipeline(
host: &str,
port: u16,
) -> Result<AsyncTcpClient<N>, AsyncError>
👎Deprecated: use AsyncTcpClient::new_with_pipeline(…) and then client.connect().await
pub fn connect_with_pipeline( host: &str, port: u16, ) -> Result<AsyncTcpClient<N>, AsyncError>
use AsyncTcpClient::new_with_pipeline(…) and then client.connect().await
Deprecated constructor alias.
Use AsyncTcpClient::new_with_pipeline and then call
client.connect().await?.
Sourcepub fn connect_with_pipeline_and_poll_interval(
host: &str,
port: u16,
_poll_interval: Duration,
) -> Result<AsyncTcpClient<N>, AsyncError>
👎Deprecated: use AsyncTcpClient::new_with_pipeline_and_poll_interval(…) and then client.connect().await
pub fn connect_with_pipeline_and_poll_interval( host: &str, port: u16, _poll_interval: Duration, ) -> Result<AsyncTcpClient<N>, AsyncError>
use AsyncTcpClient::new_with_pipeline_and_poll_interval(…) and then client.connect().await
Deprecated constructor alias.
Use AsyncTcpClient::new_with_pipeline_and_poll_interval and then
call client.connect().await?.
Sourcepub fn new_with_pipeline(
host: &str,
port: u16,
) -> Result<AsyncTcpClient<N>, AsyncError>
pub fn new_with_pipeline( host: &str, port: u16, ) -> Result<AsyncTcpClient<N>, AsyncError>
Creates an async TCP client with compile-time pipeline depth N.
Call AsyncClientCore::connect on the returned client before sending
requests.
Sourcepub fn new_with_pipeline_and_poll_interval(
host: &str,
port: u16,
_poll_interval: Duration,
) -> Result<AsyncTcpClient<N>, AsyncError>
pub fn new_with_pipeline_and_poll_interval( host: &str, port: u16, _poll_interval: Duration, ) -> Result<AsyncTcpClient<N>, AsyncError>
Creates an async TCP client with compile-time pipeline depth N and a
custom poll_interval.
The poll interval is ignored in the async implementation.
Call AsyncClientCore::connect on the returned client before sending
requests.
Sourcepub fn new_with_config_and_pipeline(
tcp_config: ModbusTcpConfig,
_poll_interval: Duration,
) -> Result<AsyncTcpClient<N>, AsyncError>
pub fn new_with_config_and_pipeline( tcp_config: ModbusTcpConfig, _poll_interval: Duration, ) -> Result<AsyncTcpClient<N>, AsyncError>
Creates an async TCP client with a fully custom config and pipeline
depth N.
Call AsyncClientCore::connect on the returned client before sending
requests.
Methods from Deref<Target = AsyncClientCore>§
Sourcepub async fn connect(&self) -> Result<(), AsyncError>
pub async fn connect(&self) -> Result<(), AsyncError>
Establishes the underlying transport connection.
Must be called once before issuing Modbus requests. Can be called again after a disconnect to reconnect.
Sourcepub async fn disconnect(&self) -> Result<(), AsyncError>
pub async fn disconnect(&self) -> Result<(), AsyncError>
Disconnects the underlying transport.
Drains all in-flight and queued requests with
MbusError::ConnectionClosed and closes the transport. After this
call, connect can be called to reconnect.
This is an explicit, graceful disconnect. The background task continues running so the client can be reconnected later. Dropping the client handle entirely also stops the background task.
Sourcepub fn has_pending_requests(&self) -> bool
pub fn has_pending_requests(&self) -> bool
Returns true when there are requests in-flight awaiting a response.
This is a synchronous check — no .await required.
Sourcepub fn set_request_timeout(&self, timeout: Duration)
pub fn set_request_timeout(&self, timeout: Duration)
Sets a per-request deadline applied to every subsequent request call.
If a response is not received within timeout, the method returns
AsyncError::Timeout. The in-flight entry remains in the background
task until the transport delivers or errors; calling
connect resets transport state.
The timeout can be updated at any time and takes effect on the next
request. Call clear_request_timeout to
remove it.
Sourcepub fn clear_request_timeout(&self)
pub fn clear_request_timeout(&self)
Removes the per-request timeout set by
set_request_timeout, allowing requests to
wait indefinitely for a server response.
Sourcepub async fn read_multiple_coils(
&self,
unit_id: u8,
address: u16,
quantity: u16,
) -> Result<Coils, AsyncError>
pub async fn read_multiple_coils( &self, unit_id: u8, address: u16, quantity: u16, ) -> Result<Coils, AsyncError>
Reads multiple coils (FC 01) from address with the given quantity.
Returns the coil values packed into a Coils object.
Sourcepub async fn write_single_coil(
&self,
unit_id: u8,
address: u16,
value: bool,
) -> Result<(u16, bool), AsyncError>
pub async fn write_single_coil( &self, unit_id: u8, address: u16, value: bool, ) -> Result<(u16, bool), AsyncError>
Writes a single coil (FC 05) at address with the given boolean value.
Returns (address, value) echoed back by the server.
Sourcepub async fn write_multiple_coils(
&self,
unit_id: u8,
address: u16,
coils: &Coils,
) -> Result<(u16, u16), AsyncError>
pub async fn write_multiple_coils( &self, unit_id: u8, address: u16, coils: &Coils, ) -> Result<(u16, u16), AsyncError>
Writes multiple coils (FC 15) starting at address.
Returns (starting_address, quantity) echoed back by the server.
Sourcepub async fn read_holding_registers(
&self,
unit_id: u8,
address: u16,
quantity: u16,
) -> Result<Registers<mbus_core::::models::register::model::HoldingRegisters::{constant#0}>, AsyncError>
pub async fn read_holding_registers( &self, unit_id: u8, address: u16, quantity: u16, ) -> Result<Registers<mbus_core::::models::register::model::HoldingRegisters::{constant#0}>, AsyncError>
Reads holding registers (FC 03) from address with the given quantity.
Returns the register values as a HoldingRegisters object.
Sourcepub async fn read_input_registers(
&self,
unit_id: u8,
address: u16,
quantity: u16,
) -> Result<Registers<mbus_core::::models::register::model::InputRegisters::{constant#0}, Input>, AsyncError>
pub async fn read_input_registers( &self, unit_id: u8, address: u16, quantity: u16, ) -> Result<Registers<mbus_core::::models::register::model::InputRegisters::{constant#0}, Input>, AsyncError>
Reads input registers (FC 04) from address with the given quantity.
Returns the register values as an InputRegisters object.
Sourcepub async fn write_single_register(
&self,
unit_id: u8,
address: u16,
value: u16,
) -> Result<(u16, u16), AsyncError>
pub async fn write_single_register( &self, unit_id: u8, address: u16, value: u16, ) -> Result<(u16, u16), AsyncError>
Writes a single holding register (FC 06) at address with value.
Returns (address, value) echoed back by the server.
Sourcepub async fn write_multiple_registers(
&self,
unit_id: u8,
address: u16,
values: &[u16],
) -> Result<(u16, u16), AsyncError>
pub async fn write_multiple_registers( &self, unit_id: u8, address: u16, values: &[u16], ) -> Result<(u16, u16), AsyncError>
Writes multiple holding registers (FC 16) starting at address.
Returns (starting_address, quantity) echoed back by the server.
Sourcepub async fn read_write_multiple_registers(
&self,
unit_id: u8,
read_address: u16,
read_quantity: u16,
write_address: u16,
write_values: &[u16],
) -> Result<Registers<mbus_core::::models::register::model::HoldingRegisters::{constant#0}>, AsyncError>
pub async fn read_write_multiple_registers( &self, unit_id: u8, read_address: u16, read_quantity: u16, write_address: u16, write_values: &[u16], ) -> Result<Registers<mbus_core::::models::register::model::HoldingRegisters::{constant#0}>, AsyncError>
Performs a combined read/write on holding registers (FC 23).
Reads read_quantity registers starting at read_address and
simultaneously writes write_values starting at write_address.
Returns the read registers.
Sourcepub async fn mask_write_register(
&self,
unit_id: u8,
address: u16,
and_mask: u16,
or_mask: u16,
) -> Result<(), AsyncError>
pub async fn mask_write_register( &self, unit_id: u8, address: u16, and_mask: u16, or_mask: u16, ) -> Result<(), AsyncError>
Applies an AND/OR bitmask to a holding register (FC 22).
The resulting register value is (current & and_mask) | (or_mask & !and_mask).
Sourcepub async fn read_discrete_inputs(
&self,
unit_id: u8,
address: u16,
quantity: u16,
) -> Result<DiscreteInputs, AsyncError>
pub async fn read_discrete_inputs( &self, unit_id: u8, address: u16, quantity: u16, ) -> Result<DiscreteInputs, AsyncError>
Reads discrete inputs (FC 02) from address with the given quantity.
Returns the input states as a DiscreteInputs object.
Sourcepub async fn read_fifo_queue(
&self,
unit_id: u8,
address: u16,
) -> Result<FifoQueue, AsyncError>
pub async fn read_fifo_queue( &self, unit_id: u8, address: u16, ) -> Result<FifoQueue, AsyncError>
Reads the FIFO queue (FC 24) at address.
Returns up to 31 words from the FIFO queue as a FifoQueue object.
Sourcepub async fn read_file_record(
&self,
unit_id: u8,
sub_request: &SubRequest,
) -> Result<Vec<SubRequestParams>, AsyncError>
pub async fn read_file_record( &self, unit_id: u8, sub_request: &SubRequest, ) -> Result<Vec<SubRequestParams>, AsyncError>
Reads a file record (FC 20) described by sub_request.
Returns the sub-request response parameters for each requested record.
Sourcepub async fn write_file_record(
&self,
unit_id: u8,
sub_request: &SubRequest,
) -> Result<(), AsyncError>
pub async fn write_file_record( &self, unit_id: u8, sub_request: &SubRequest, ) -> Result<(), AsyncError>
Writes a file record (FC 21) described by sub_request.
Sourcepub async fn read_device_identification(
&self,
unit_id: u8,
read_device_id_code: ReadDeviceIdCode,
object_id: ObjectId,
) -> Result<DeviceIdentificationResponse, AsyncError>
pub async fn read_device_identification( &self, unit_id: u8, read_device_id_code: ReadDeviceIdCode, object_id: ObjectId, ) -> Result<DeviceIdentificationResponse, AsyncError>
Reads device identification objects (FC 43 / MEI 14).
Sourcepub async fn encapsulated_interface_transport(
&self,
unit_id: u8,
mei_type: EncapsulatedInterfaceType,
data: &[u8],
) -> Result<(EncapsulatedInterfaceType, Vec<u8>), AsyncError>
pub async fn encapsulated_interface_transport( &self, unit_id: u8, mei_type: EncapsulatedInterfaceType, data: &[u8], ) -> Result<(EncapsulatedInterfaceType, Vec<u8>), AsyncError>
Sends an encapsulated interface transport request (FC 43).
Returns the (mei_type, data) pair from the server response.
Sourcepub async fn read_exception_status(&self, unit_id: u8) -> Result<u8, AsyncError>
pub async fn read_exception_status(&self, unit_id: u8) -> Result<u8, AsyncError>
Reads the device exception status (FC 07).
Sourcepub async fn diagnostics(
&self,
unit_id: u8,
sub_function: DiagnosticSubFunction,
data: &[u16],
) -> Result<DiagnosticsDataResponse, AsyncError>
pub async fn diagnostics( &self, unit_id: u8, sub_function: DiagnosticSubFunction, data: &[u16], ) -> Result<DiagnosticsDataResponse, AsyncError>
Sends a diagnostics request (FC 08).
Returns DiagnosticsDataResponse with echoed sub_function and data.
Sourcepub async fn get_comm_event_counter(
&self,
unit_id: u8,
) -> Result<(u16, u16), AsyncError>
pub async fn get_comm_event_counter( &self, unit_id: u8, ) -> Result<(u16, u16), AsyncError>
Reads the communication event counter (FC 11).
Returns (status_word, event_count).
Sourcepub async fn get_comm_event_log(
&self,
unit_id: u8,
) -> Result<(u16, u16, u16, Vec<u8>), AsyncError>
pub async fn get_comm_event_log( &self, unit_id: u8, ) -> Result<(u16, u16, u16, Vec<u8>), AsyncError>
Reads the communication event log (FC 12).
Returns (status, event_count, message_count, events).
Sourcepub async fn report_server_id(&self, unit_id: u8) -> Result<Vec<u8>, AsyncError>
pub async fn report_server_id(&self, unit_id: u8) -> Result<Vec<u8>, AsyncError>
Requests the server identifier data (FC 17).
Returns the raw server ID byte array.