RModBus

RModBus - free implementation of ModBus protocol in pure Ruby.

Features

Support functions

Installation

Download and install RModBus with the following:

gem install rmodbus

Or if you are using bundler, add to your Gemfile:

gem 'rmodbus'

If you want to use ModBus over serial, you will also need to install the 'serialport' gem. If you are using bundler, add to your Gemfile:

gem 'serialport'

If you want to use ModBus::TCPServer or ModBus::RTUViaTCPServer and are using Ruby >= 2.2, you will also need to install the 'gserver' gem. If you are using bundler, add to your Gemfile:

gem 'gserver'

Please note that GServer is deprecated, and I'm looking for a better solution. Contributions are welcome!

Example

“`ruby require 'rmodbus'

ModBus::TCPClient.new('127.0.0.1', 8502) do |cl|
  cl.with_slave(1) do |slave|
    # Read a single holding register at address 16
    slave.holding_registers[16]

    # Write a single holding register at address 16
    slave.holding_registers[16] = 123

    # Read holding registers 16 through 20
    slave.holding_registers[16..20]

    # Write holding registers 16 through 20 with some values
    slave.holding_registers[16..20] = [1, 2, 3, 4, 5]
  end
end

“`

Versioning

This project will follow semver.org/

Given a version number MAJOR.MINOR.PATCH, increment the:

MAJOR version when you make incompatible API changes,
MINOR version when you add functionality in a backwards-compatible manner, and
PATCH version when you make backwards-compatible bug fixes.

Contributing

See CONTRIBUTING.

Reference

RModBus on GitHub: github.com/rmodbus/rmodbus

Documentation: www.rubydoc.info/github/rmodbus/rmodbus

ModBus specifications: www.modbus.org/specs.php

License

BSD-3-Clause

Credits

Aleksey Timin - original author