Module tokio_sync_safe_client

Module tokio_sync_safe_client 

Source
Available on crate feature safe-client-sync and (crate features tokio-rtu-sync or tokio-tcp-sync) only.
Expand description

This module provides a thread-safe synchronous client for the SDM72 energy meter.

The SafeClient struct wraps the core synchronous API and manages the Modbus context within an Arc<Mutex>, allowing it to be shared across threads safely.

§Example

use sdm72_lib::{
    protocol::Address,
    tokio_sync_safe_client::SafeClient,
};
use tokio_modbus::client::sync::tcp;
use tokio_modbus::Slave;
use std::time::Duration;

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()))?;
    let mut client = SafeClient::new(ctx);

    let values = client.read_all(&Duration::from_millis(100))?;

    println!("Successfully read values: {:#?}", values);

    Ok(())
}

Structs§

SafeClient
A thread-safe synchronous client for the SDM72 energy meter.