Skip to content

Instantly share code, notes, and snippets.

@atimin
Created October 29, 2011 15:07
Show Gist options
  • Select an option

  • Save atimin/1324562 to your computer and use it in GitHub Desktop.

Select an option

Save atimin/1324562 to your computer and use it in GitHub Desktop.
require "rmodbus"
s = ModBus::TCPServer.new(9999, 1)
s.holding_registers = [1] * 10
s.start
ModBus::TCPClient.connect('127.0.0.1',9999) do |cl|
cl.with_slave(1) do |slave|
slave.raise_exception_on_mismatch = true
slave.debug =true
begin
puts slave.holding_registers[0..2]
slave.holding_registers[0..1] = [0,0]
rescue ModBus::Errors::ResponseMismatch => e
puts e.msg, e.request, e.response
end
end
end
s.stop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment