Available on crate feature
safe-client-async and (crate features tokio-rtu or tokio-tcp) only.Expand description
This module provides a thread-safe asynchronous client for the SDM72 energy meter.
The SafeClient struct wraps the core asynchronous API and manages the Modbus
context within an Arc<Mutex>, allowing it to be shared across tasks safely.
§Example
use sdm72_lib::{
protocol::Address,
tokio_async_safe_client::SafeClient,
};
use tokio_modbus::client::tcp;
use tokio_modbus::Slave;
use std::time::Duration;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let socket_addr = "192.168.1.100:502".parse()?;
let ctx = tcp::connect_slave(socket_addr, Slave(*Address::default())).await?;
let mut client = SafeClient::new(ctx);
let values = client.read_all(&Duration::from_millis(100)).await?;
println!("Successfully read values: {:#?}", values);
Ok(())
}Structs§
- Safe
Client - A thread-safe asynchronous client for the SDM72 energy meter.