1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
//! A pure [Rust](https://www.rust-lang.org) //! [Modbus](https://en.wikipedia.org/wiki/Modbus) library //! based on [tokio](https://tokio.rs). //! //! Modbus is based on a [master/slave](https://en.wikipedia.org/wiki/Master/slave_(technology)) //! 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) //! - sync (blocking) //! - Modbus TCP //! - Modbus RTU //! - Client & Server //! - Open Source (MIT/Apache-2.0) //! //! # Installation //! //! Add this to your `Cargo.toml`: //! //! ```toml //! [dependencies] //! tokio-modbus = "*" //! ``` //! If you like to use Modbus TCP only: //! //! ```toml //! [dependencies] //! tokio-modbus = { version = "*", default-features = false, features = ["tcp"] } //! ``` //! //! If you like to use Modbus RTU only: //! //! ```toml //! [dependencies] //! tokio-modbus = { version = "*", default-features = false, features = ["rtu"] } //! ``` //! //! # Examples //! //! ## TCP client //! //! ```rust,no_run //! use tokio_core::reactor::Core; //! use futures::Future; //! use tokio_modbus::prelude::*; //! //! pub fn main() { //! let mut core = Core::new().unwrap(); //! let handle = core.handle(); //! let socket_addr = "192.168.0.222:502".parse().unwrap(); //! //! let task = tcp::connect(&handle, socket_addr).and_then(|ctx| { //! ctx //! .read_input_registers(0x1000, 7) //! .and_then(move |data| { //! println!("Response is '{:?}'", data); //! Ok(()) //! }) //! }); //! core.run(task).unwrap(); //! } //! ``` //! //! ## Sync TCP client //! //! ```rust,no_run //! use tokio_modbus::prelude::*; //! //! pub fn main() { //! let socket_addr = "192.168.0.222:502".parse().unwrap(); //! let mut client = client::sync::tcp::connect(socket_addr).unwrap(); //! let data = client.read_input_registers(0x1000, 7).unwrap(); //! println!("Response is '{:?}'", data); //! } //! ``` //! //! ## RTU client //! //! ```rust,no_run //! use tokio_core::reactor::Core; //! use futures::Future; //! use tokio_serial::{Serial, SerialPortSettings}; //! //! use tokio_modbus::prelude::*; //! //! pub fn main() { //! let mut core = Core::new().unwrap(); //! let handle = core.handle(); //! let tty_path = "/dev/ttyUSB0"; //! let slave = Slave(0x17); //! //! let mut settings = SerialPortSettings::default(); //! settings.baud_rate = 19200; //! let port = Serial::from_path_with_handle(tty_path, &settings, &handle.new_tokio_handle()).unwrap(); //! //! let task = rtu::connect_slave(&handle, port, slave).and_then(|ctx| { //! println!("Reading a sensor value"); //! ctx //! .read_holding_registers(0x082B, 2) //! .and_then(move |rsp| { //! println!("Sensor value is: {:?}", rsp); //! Ok(()) //! }) //! }); //! //! core.run(task).unwrap(); //! } //! ``` //! //! More examples can be found in the [examples](https://github.com/slowtec/tokio-modbus/tree/master/examples) folder. //! //! # Protocol-Specification //! //! - [MODBUS Application Protocol Specification v1.1b3 (PDF)](http://modbus.org/docs/Modbus_Application_Protocol_V1_1b3.pdf) //! - [MODBUS over serial line specification and implementation guide v1.02 (PDF)](http://modbus.org/docs/Modbus_over_serial_line_V1_02.pdf) //! - [MODBUS Messaging on TCP/IP Implementation Guide v1.0b (PDF)](http://modbus.org/docs/Modbus_Messaging_Implementation_Guide_V1_0b.pdf) pub mod prelude; pub mod client; pub mod server; pub mod slave; mod codec; mod frame; mod proto; mod service;