libmodbus-rs

libmodbus bindings for Rust Crates.io version Build Status Build status

Homepage |  Documentation |  original libmodbus Documentation |  Repo auf Github.com |

This crate is in early beta state. Please don't use in production and expect odd behavior.

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.

toml [dependencies] libmodbus = "0.4"

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:

```rust extern crate libmodbus_rs;

use libmodbus_rs::{Modbus, ModbusTCP, ModbusServer}; ```

The examples in the examples dir, show this.

Building libmodbus-rs

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

Debian based

```sh

apt-get install llvm-3.9-dev libclang-3.9-dev clang-3.9

```

Arch

```sh

pacman -S clang

```

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

Examples

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

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

sh cargo run --example random-test-server

In another shell start the client after the server sh cargo run --example random-test-client

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

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.