Class: Pzem016::ModbusRegisters
- Inherits:
-
Object
- Object
- Pzem016::ModbusRegisters
- Defined in:
- lib/pzem016/pzem016.rb
Overview
Some abstract behavior for the register parser classes
Direct Known Subclasses
Instance Attribute Summary collapse
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
-
#slave ⇒ Object
readonly
Returns the value of attribute slave.
Instance Method Summary collapse
-
#initialize(name, slave) ⇒ ModbusRegisters
constructor
This takes two params: name and slave.
-
#read ⇒ Object
Stub for read logic.
-
#report ⇒ Object
Outputs a pretty dump of the readings to STDOUT.
-
#to_hash ⇒ Object
Simple basic behavior for turning the data read into a hash.
-
#to_json(*_args) ⇒ Object
Returns the sample data as a json string.
Constructor Details
#initialize(name, slave) ⇒ ModbusRegisters
This takes two params: name and slave. Name is a descriptive string for the slave. Slave is an instance of a ModBus::RTUClient slave that you’ve previously set up.
22 23 24 25 26 |
# File 'lib/pzem016/pzem016.rb', line 22 def initialize(name, slave) @slave = slave @name = name @raw = nil end |
Instance Attribute Details
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
15 16 17 |
# File 'lib/pzem016/pzem016.rb', line 15 def raw @raw end |
#slave ⇒ Object (readonly)
Returns the value of attribute slave.
15 16 17 |
# File 'lib/pzem016/pzem016.rb', line 15 def slave @slave end |
Instance Method Details
#read ⇒ Object
Stub for read logic
31 32 33 |
# File 'lib/pzem016/pzem016.rb', line 31 def read @raw = [] end |
#report ⇒ Object
Outputs a pretty dump of the readings to STDOUT
52 53 54 |
# File 'lib/pzem016/pzem016.rb', line 52 def report ap to_hash end |
#to_hash ⇒ Object
Simple basic behavior for turning the data read into a hash
38 39 40 |
# File 'lib/pzem016/pzem016.rb', line 38 def to_hash { raw: @raw } end |
#to_json(*_args) ⇒ Object
Returns the sample data as a json string
45 46 47 |
# File 'lib/pzem016/pzem016.rb', line 45 def to_json(*_args) to_hash.to_json end |