Crate tokio_modbus [−] [src]
A pure Rust Modbus library based on tokio.
Modbus is based on a master/slave model. To avoid confusions with the tokio terminology the master is called client and the slave is called server in this library.
Features
- pure Rust library
- async (non-blocking)
- Modbus TCP
- Modbus RTU
Installation
Add this to your Cargo.toml
:
[dependencies]
tokio-modbus = "*"
If you like to use Modbus TCP only:
[dependencies]
tokio-modbus = { version = "*", default-features = false, features = ["tcp"] }
If you like to use Modbus RTU only:
[dependencies]
tokio-modbus = { version = "*", default-features = false, features = ["rtu"] }
TCP client example
extern crate futures; extern crate tokio_core; extern crate tokio_modbus; use tokio_core::reactor::Core; use futures::future::Future; use tokio_modbus::{Client, TcpClient}; pub fn main() { let mut core = Core::new().unwrap(); let handle = core.handle(); let addr = "192.168.0.222:502".parse().unwrap(); let task = TcpClient::connect(&addr, &handle).and_then(|client| { println!("Fetching the coupler ID"); client .read_input_registers(0x1000, 7) .and_then(move |buff| { println!("Response is '{:?}'", buff); Ok(()) }) }); core.run(task).unwrap(); }
More examples can be found in the examples folder.
Protocol-Specification
Structs
RtuClient |
Modbus RTU client |
TcpClient |
Modbus TCP client |
Enums
Request |
A request represents a message from the client (master) to the server (slave). |
Response |
The data of a successfull request. |
Traits
Client |
A transport independent client trait. |