Module tokio_async_safe_client

Module tokio_async_safe_client 

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

Asynchronous tokio-modbus client for the R4DCB08 temperature module.

This module provides a high-level API (SafeClient struct) to interact with the R4DCB08 8-channel temperature module using Modbus RTU or TCP. It handles the conversion between Rust types defined in the crate::protocol module and the raw Modbus register values.

All client methods are async and must be .awaited.

§Example

use r4dcb08_lib::{
    protocol::Address,
    tokio_async_safe_client::SafeClient,
};
use tokio_modbus::client::tcp;
use tokio_modbus::Slave;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Connect to the device and create a stateful, safe client
    let socket_addr = "192.168.1.100:502".parse()?;
    let ctx = tcp::connect_slave(socket_addr, Slave(*Address::default())).await?;
    let client = SafeClient::new(ctx);

    // Use the client to interact with the device
    let temperatures = client.read_temperatures().await?;

    println!("Successfully read temperatures. Current values: {}", temperatures);

    Ok(())
}

Structs§

SafeClient
Asynchronous client for interacting with the R4DCB08 temperature module over Modbus.