Expand description
A library for controlling the R413D08 8-channel relay module via Modbus.
This crate provides two main ways to interact with the R413D08 relay module:
-
High-Level, Safe Clients: Stateful, thread-safe clients that are easy to share and use in concurrent applications. This is the recommended approach for most users. See
tokio_sync_safe_client::SafeClient(blocking) andtokio_async_safe_client::SafeClient(async). -
Low-Level, Stateless Functions: A set of stateless functions that directly map to the device’s Modbus commands. This API offers maximum flexibility but requires manual management of the Modbus context. See the
tokio_syncandtokio_asyncmodules.
§Features
- Protocol Implementation: Complete implementation of the R413D08 Modbus protocol.
- Stateful, Thread-Safe Clients: For easy and safe concurrent use.
- Stateless, Low-Level Functions: For maximum flexibility and control.
- Synchronous and Asynchronous APIs: Both blocking and
async/awaitAPIs are available. - Strongly-Typed API: Utilizes Rust’s type system for protocol correctness
(e.g.,
Port,Address,PortState).
§Quick Start
This example shows how to use the recommended high-level, synchronous SafeClient.
use r413d08_lib::{
protocol::{Address, Port},
tokio_sync_safe_client::SafeClient,
};
use tokio_modbus::client::sync::tcp;
use tokio_modbus::Slave;
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()))?;
let client = SafeClient::new(ctx);
// Use the client to interact with the device
client.set_port_open(Port::try_from(0)?)?;
let status = client.read_ports()?;
println!("Successfully turned on relay 0. Current status: {}", status);
Ok(())
}For more details, see the documentation for the specific client you wish to use.
Modules§
- protocol
- Defines data structures, constants, and protocol logic for interacting with an 8-Channel Multifunction RS485 Module via Modbus RTU, based on the protocol specification document.
- tokio_
async tokio-rtuortokio-tcp - Provides an asynchronous Modbus client for the R413D08 relay module.
- tokio_
async_ safe_ client safe-client-asyncand (tokio-rtuortokio-tcp) - Provides a thread-safe, asynchronous Modbus client for the R413D08 relay module.
- tokio_
common - This module provides common data structures and error types for the
tokiobased clients. - tokio_
sync tokio-rtu-syncortokio-tcp-sync - Provides a synchronous Modbus client for the R413D08 relay module.
- tokio_
sync_ safe_ client safe-client-syncand (tokio-rtu-syncortokio-tcp-sync) - Provides a thread-safe, synchronous Modbus client for the R413D08 relay module.