7 releases (1 stable)

1.0.0 Nov 5, 2020
0.8.0 Dec 21, 2017
0.7.0 Dec 14, 2017
0.5.0 Oct 20, 2017
0.4.2 May 15, 2017

#28 in #modbus

Download history 24/week @ 2023-12-04 21/week @ 2023-12-11 22/week @ 2023-12-18 6/week @ 2023-12-25 21/week @ 2024-01-01 24/week @ 2024-01-08 34/week @ 2024-01-15 40/week @ 2024-01-22 13/week @ 2024-01-29 10/week @ 2024-02-05 17/week @ 2024-02-12 32/week @ 2024-02-19 59/week @ 2024-02-26 23/week @ 2024-03-04 33/week @ 2024-03-11 20/week @ 2024-03-18

136 downloads per month
Used in 2 crates

LGPL-2.1

220KB
5.5K SLoC

C 4.5K SLoC // 0.1% comments Visual Studio Project 457 SLoC Automake 163 SLoC JavaScript 122 SLoC // 0.2% comments Rust 107 SLoC // 0.1% comments Bitbake 46 SLoC Shell 24 SLoC // 0.1% comments Visual Studio Solution 20 SLoC M4 20 SLoC // 0.3% comments

libmodbus

This crate was renamed to just libmodbus. Before version 1.0.0 the name of the crate was libmodbus-rs.

libmodbus bindings for Rust

Libmodbus is a free software library to send and receive data with a device that respects the Modbus protocol. That crate contains the Rust bindings for the libmodbus library (written in C). Like libmodbus self, this crate supports serial port and Ethernet connections for Modbus server and clients.

Crates.io version   Build Status   Build status   Coverage Status

Homepage |   Documentation |   Original libmodbus documentation |   Github repo |

This crate based on the latest libmodbus git:master branch. I plan to support the different libmodbus version via cargo's feature feature.

Usage

Include the dependencies into your Cargo.toml file.

for stable (crates.io)

[dependencies]
libmodbus-rs = "1"

or development (github master)

[dependencies]
libmodbus-rs = { git = "https://github.com/zzeroo/libmodbus-rs.git" }

Some header files of the original libmodbus C library are recreated as traits (e.g. ModbusTCP, ModbusRTU, ModbusServer, ModbusClient, ...). For example if you what to build an modbus server, in the modbus tcp context, include the following:

extern crate libmodbus_rs;

use libmodbus::{Modbus, ModbusServer, ModbusTCP};

The examples in the examples directory show this.

Documentation

Documentation (crates.io)

Documentation (master)

Building libmodbus-rs

The libmodbus ffi bindings (libmodbus-sys) are build using bindgen. Bindgen need Clang 3.9 or greater on your system.

Dependencies Archlinux

pacman -S autoconf clang39 git libtool make

Dependencies Debian based (e.g. Ubuntu)

apt install autoconf build-essential curl clang git-core libtool

Look also at the local ci/ docker files under ./ci/docker-archlinux and .ci/docker-debian9 for a known working, minimal setup.

For more information about the bindgen requirements please visit https://servo.github.io/rust-bindgen/requirements.html

Dependencies Windows

Follow the msys2 instructions https://www.msys2.org

pacman -Syu

Followed by the second update step

pacman -Su

Finally install clang

pacman -S  mingw64/mingw-w64-x86_64-clang

If all dependencies are solved, compile with cargo build and/ or run the tests with cargo test.

git clone https://github.com/zzeroo/libmodbus-rs
cd libmodbus-rs
cargo build

Examples

Most of the original libmodbus examples are reproduced in Rust. You can found them in the examples directory of this crate.

Please have look at the README.md in the examples directory for more information about the examples.

To start, for example, the random test server/ client use the following commands

cargo run --example random-test-server

In another shell start the client after the server

cargo run --example random-test-client

License

libmodbus-rs is distributed under the terms of the LGPL-2.1 license, which is the same license, libmodbus is using.

Links

This project hosts the original libmodbus documentation, used here, as well. Please have a look at http://zzeroo.github.io/libmodbus-rs/libmodbus/libmodbus.html.

Dependencies

~0–2MB
~38K SLoC