Class: ModBus::ReadOnlyProxy
- Inherits:
-
Object
- Object
- ModBus::ReadOnlyProxy
- Defined in:
- lib/rmodbus/proxy.rb
Overview
Given a slave and a type of operation, execute a single or multiple read using hash syntax
Direct Known Subclasses
Instance Method Summary (collapse)
-
- (Object) [](key)
Read single or multiple values from a modbus slave depending on whether a Fixnum or a Range was given.
-
- (ReadOnlyProxy) initialize(slave, type)
constructor
Initialize a proxy for a slave and a type of operation.
Constructor Details
- (ReadOnlyProxy) initialize(slave, type)
Initialize a proxy for a slave and a type of operation
18 19 20 |
# File 'lib/rmodbus/proxy.rb', line 18 def initialize(slave, type) @slave, @type = slave, type end |
Instance Method Details
- (Object) [](key)
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
24 25 26 27 28 29 30 31 32 |
# File 'lib/rmodbus/proxy.rb', line 24 def [](key) if key.instance_of?(Fixnum) @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 |