class ModBus::ReadOnlyProxy
Given a slave and a type of operation, execute a single or multiple read using hash syntax
Public Class Methods
new(slave, type)
click to toggle source
Initialize a proxy for a slave and a type of operation
# File lib/rmodbus/proxy.rb, line 5 def initialize(slave, type) @slave, @type = slave, type end
Public Instance Methods
[](key)
click to toggle source
Read single or multiple values from a modbus slave depending on whether a Fixnum or a Range was given. Note that in the case of multiples, a pluralized version of the method is sent to the slave
# File lib/rmodbus/proxy.rb, line 11 def [](key) if key.instance_of?(0.class) @slave.send("read_#{@type}", key, 1) elsif key.instance_of?(Range) @slave.send("read_#{@type}s", key.first, key.count) else raise ModBus::Errors::ProxyException, "Invalid argument, must be integer or range. Was #{key.class}" end end