Class: Pzem016::ModbusRegisters

Inherits:
Object
  • Object
show all
Defined in:
lib/pzem016/pzem016.rb

Overview

Some abstract behavior for the register parser classes

Direct Known Subclasses

HoldingRegisters, InputRegisters

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#rawObject (readonly)

Returns the value of attribute raw.



15
16
17
# File 'lib/pzem016/pzem016.rb', line 15

def raw
  @raw
end

#slaveObject (readonly)

Returns the value of attribute slave.



15
16
17
# File 'lib/pzem016/pzem016.rb', line 15

def slave
  @slave
end

Instance Method Details

#readObject

Stub for read logic



31
32
33
# File 'lib/pzem016/pzem016.rb', line 31

def read
  @raw = []
end

#reportObject

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_hashObject

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