Skip to content

Instantly share code, notes, and snippets.

@atimin
Created October 16, 2011 04:41
Show Gist options
  • Save atimin/1290517 to your computer and use it in GitHub Desktop.
Save atimin/1290517 to your computer and use it in GitHub Desktop.
Example RModBus
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment