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
-
#[](key) ⇒ Object
Read single or multiple values from a modbus slave depending on whether a Fixnum or a Range was given.
-
#initialize(slave, type) ⇒ ReadOnlyProxy
constructor
Initialize a proxy for a slave and a type of operation.
Constructor Details
#initialize(slave, type) ⇒ ReadOnlyProxy
Initialize a proxy for a slave and a type of operation
5 6 7 |
# File 'lib/rmodbus/proxy.rb', line 5 def initialize(slave, type) @slave, @type = slave, type end |
Instance Method Details
#[](key) ⇒ Object
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
11 12 13 14 15 16 17 18 19 |
# 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 |