33 releases (14 breaking)

new 0.16.1 Dec 13, 2024
0.15.0 Oct 10, 2024
0.14.0 Jul 21, 2024
0.12.0 Mar 21, 2024
0.0.0 Aug 21, 2017

#34 in Network programming

Download history 8952/week @ 2024-08-23 8731/week @ 2024-08-30 7658/week @ 2024-09-06 6995/week @ 2024-09-13 8290/week @ 2024-09-20 4402/week @ 2024-09-27 4203/week @ 2024-10-04 4478/week @ 2024-10-11 5729/week @ 2024-10-18 4506/week @ 2024-10-25 4146/week @ 2024-11-01 4810/week @ 2024-11-08 4623/week @ 2024-11-15 5184/week @ 2024-11-22 5799/week @ 2024-11-29 4607/week @ 2024-12-06

21,013 downloads per month
Used in 28 crates (25 directly)

MIT/Apache

190KB
4.5K SLoC

tokio-modbus

A pure Rust Modbus library based on tokio.

Crates.io Docs.rs Security audit Continuous integration MIT licensed Apache 2.0 licensed

Modbus is based on a master/slave communication pattern. To avoid confusion with the Tokio terminology the master is called client and the slave is called server in this library.

Features

  • Pure Rust library
  • Modbus TCP or RTU at your choice
  • Both async (non-blocking, default) and sync (blocking, optional)
  • Client API
  • Server implementations
    • for out-of-the-box usage or
    • as a starting point for a customized implementation
  • Open source (MIT/Apache-2.0)

Installation

Add this to your Cargo.toml:

[dependencies]
tokio-modbus = "*"

Cargo Features

  • "rtu": Asynchronous RTU client (default)
  • "tcp": Asynchronous TCP client (default)
  • "rtu-sync: Synchronous RTU client
  • "tcp-sync": Synchronous TCP client
  • "rtu-server": (Asynchronous) RTU server
  • "tcp-server": (Asynchronous) TCP server
  • "rtu-over-tcp-server": (Asynchronous) RTU over TCP server

Examples

If you only need an asynchronous TCP client add the following line to your Cargo.toml file:

[dependencies]
tokio-modbus = { version = "*", default-features = false, features = ["tcp"] }

For an asynchronous RTU client:

[dependencies]
tokio-modbus = { version = "*", default-features = false, features = ["rtu"] }

For an RTU server:

[dependencies]
tokio-modbus = { version = "*", default-features = false, features = ["rtu-server"] }

For a TCP server:

[dependencies]
tokio-modbus = { version = "*", default-features = false, features = ["tcp-server"] }

Examples

Various examples for Modbus RTU and TCP using either the asynchronous or synchronous API can be found in the examples folder.

Testing

The workspace contains documentation, tests, and examples for all available features.

cargo test --workspace
cargo test --workspace --all-features

Protocol-Specification

License

Copyright (c) 2017-2024 slowtec GmbH

MIT/Apache-2.0

Dependencies

~3–12MB
~123K SLoC