Available on crate features
tokio-rtu or tokio-tcp only.Expand description
This module provides an asynchronous client for the SDM72 energy meter.
The SDM72 struct is the main entry point for interacting with the meter. It
wraps an asynchronous tokio-modbus context and provides high-level methods
for reading and writing meter data.
This client is suitable for applications that require non-blocking I/O and
is designed to be used within a tokio runtime. For applications that do
not use tokio, the synchronous client in the crate::tokio_sync
module may be more suitable.
§Example
use sdm72_lib::{
protocol::Address,
tokio_async::SDM72,
};
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 mut ctx = tcp::connect_slave(socket_addr, Slave(*Address::default())).await?;
let values = SDM72::read_all(&mut ctx, &Duration::from_millis(100)).await?;
println!("Successfully read values: {:#?}", values);
Ok(())
}Structs§
- SDM72
- An asynchronous client for the SDM72 energy meter.