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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
//! 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
//! extern crate futures;
//! extern crate tokio_core;
//! extern crate tokio_modbus;
//!
//! use tokio_core::reactor::Core;
//! use futures::future::Future;
//! use tokio_modbus::*;
//!
//! pub fn main() {
//!     let mut core = Core::new().unwrap();
//!     let handle = core.handle();
//!     let addr = "192.168.0.222:502".parse().unwrap();
//!
//!     let task = Client::connect_tcp(&addr, &handle).and_then(|client| {
//!         client
//!             .read_input_registers(0x1000, 7)
//!             .and_then(move |data| {
//!                 println!("Response is '{:?}'", data);
//!                 Ok(())
//!             })
//!     });
//!     core.run(task).unwrap();
//! }
//! ```
//!
//! ## Sync TCP client
//!
//! ```rust,no_run
//! extern crate tokio_modbus;
//! use tokio_modbus::*;
//!
//! pub fn main() {
//!     let addr = "192.168.0.222:502".parse().unwrap();
//!     let mut client = SyncClient::connect_tcp(&addr).unwrap();
//!     let data = client.read_input_registers(0x1000, 7).unwrap();
//!     println!("Response is '{:?}'", data);
//! }
//! ```
//!
//! ## RTU client
//!
//! ```rust,no_run
//! extern crate futures;
//! extern crate tokio_core;
//! extern crate tokio_modbus;
//! extern crate tokio_serial;
//!
//! use tokio_core::reactor::Core;
//! use futures::future::Future;
//! use tokio_serial::{BaudRate, Serial, SerialPortSettings};
//! use tokio_modbus::*;
//!
//! pub fn main() {
//!     let mut core = Core::new().unwrap();
//!     let handle = core.handle();
//!     let tty_path = "/dev/ttyUSB0";
//!     let server_addr = 0x01;
//!
//!     let mut settings = SerialPortSettings::default();
//!     settings.baud_rate = BaudRate::Baud19200;
//!     let mut port = Serial::from_path(tty_path, &settings, &handle).unwrap();
//!     port.set_exclusive(false).unwrap();
//!
//!     let task = Client::connect_rtu(port, server_addr, &handle).and_then(|client| {
//!         println!("Reading a sensor value");
//!         client
//!             .read_holding_registers(0x082B, 2)
//!             .and_then(move |res| {
//!                 println!("Sensor value is: {:?}", res);
//!                 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)

extern crate byteorder;
extern crate bytes;
extern crate futures;
extern crate tokio_core;
extern crate tokio_io;
extern crate tokio_proto;
#[cfg(feature = "rtu")]
extern crate tokio_serial;
extern crate tokio_service;

mod frame;
mod codec;
mod proto;
mod service;
mod client;
mod server;

pub use frame::*;
pub use client::*;
pub use server::*;