Rust + Modbus == Rodbus!

Adam Crain February 25, 2020
Rust + Modbus == Rodbus!

At the S4x20 conference this year in Miami, I gave a talk about the future of the Rust programming language in critical infrastructure. Along with the talk we released Rodbus, an implementation of the Modbus protocol in Rust.

One of coolest thing about Rust’s ecosystem is how easy it makes to download, build, and install command-line tools written in Rust using Cargo. While Rodbus is a full Modbus client/server library, we wanted to provide something for non-developer types as well. There’s a separate crate called rodbus-client that provides a command line Modbus client using the Rodbus library.

Installing rodbus-client

First, follow the instructions provided on the Rust website to install Rust on your OS

The open a console and run:

> cargo install rodbus-client

That’s all there is to it!

Cargo automatically does the following:

  1. Downloads the crate and all of its dependencies
  2. Compiles the application as a single executable with no dependencies
  3. Installs the executable into your $HOME/.cargo/bin directory

You can now use your installed Rust program as a Modbus client:

> rodbus-client.exe --help
Modbus Client Console 0.1.0
Simple program to show off client API

USAGE:
    rodbus-client.exe [OPTIONS] [SUBCOMMAND]

FLAGS:
        --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -h, --host <host>        A socket address [default: 127.0.0.1:502]
    -i, --id <id>            The unit id of Modbus server [default: 1]
    -p, --period <period>    Optional polling period in milliseconds

SUBCOMMANDS:
    help    Prints this message or the help of the given subcommand(s)
    rc      read coils
    rdi     read discrete inputs
    rhr     read holding registers
    rir     read input registers
    wmc     write multiple coils
    wmr     write multiple registers
    wsc     write single coil
    wsr     write single register