Class: Pzem016::InputRegisters
- Inherits:
-
ModbusRegisters
- Object
- ModbusRegisters
- Pzem016::InputRegisters
- Defined in:
- lib/pzem016/pzem016.rb
Overview
Parsing logic for the “input registers”, also known as readonly. This is where the sample data shows up
Instance Attribute Summary
Attributes inherited from ModbusRegisters
Instance Method Summary collapse
-
#alarm? ⇒ Boolean
Returns true of power consumption has reached the alarm number of watts.
-
#amps ⇒ Object
Extracts measured amps from the sample data.
-
#hz ⇒ Object
Extracts measured frequency from the sample data.
-
#powerFactor ⇒ Object
Extracts measured power factor from the sample data.
-
#read ⇒ Object
Specific input register read logic for PZEM-016.
-
#to_hash ⇒ Object
Specific logic for generating a hash of the input registers in a PZEM-016.
-
#volts ⇒ Object
Extracts measured volts from the sample data.
-
#wattHours ⇒ Object
Extracts cumulative watt-hours from the sample data.
-
#watts ⇒ Object
Extracts measured watts from the sample data.
Methods inherited from ModbusRegisters
#initialize, #report, #to_json
Constructor Details
This class inherits a constructor from Pzem016::ModbusRegisters
Instance Method Details
#alarm? ⇒ Boolean
Returns true of power consumption has reached the alarm number of watts
163 164 165 |
# File 'lib/pzem016/pzem016.rb', line 163 def alarm? @raw[9] == 0xFFFF end |
#amps ⇒ Object
Extracts measured amps from the sample data
128 129 130 |
# File 'lib/pzem016/pzem016.rb', line 128 def amps (((@raw[2] << 16) | @raw[1]) * 0.001).round(3) end |
#hz ⇒ Object
Extracts measured frequency from the sample data
149 150 151 |
# File 'lib/pzem016/pzem016.rb', line 149 def hz (@raw[7] * 0.1).round(3) end |
#powerFactor ⇒ Object
Extracts measured power factor from the sample data
156 157 158 |
# File 'lib/pzem016/pzem016.rb', line 156 def powerFactor (@raw[8] * 0.01).round(3) end |
#read ⇒ Object
Specific input register read logic for PZEM-016
114 115 116 |
# File 'lib/pzem016/pzem016.rb', line 114 def read @raw = @slave.input_registers[0..9] end |
#to_hash ⇒ Object
Specific logic for generating a hash of the input registers in a PZEM-016
170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/pzem016/pzem016.rb', line 170 def to_hash { "SlaveAddr": @slave.uid, "DeviceName": @name, "Volts": volts, "Amps": amps, "Watts": watts, "WH": wattHours, "HZ": hz, "PF": powerFactor, "Alarm": alarm? } end |
#volts ⇒ Object
Extracts measured volts from the sample data
121 122 123 |
# File 'lib/pzem016/pzem016.rb', line 121 def volts (@raw[0] * 0.1).round(3) end |
#wattHours ⇒ Object
Extracts cumulative watt-hours from the sample data
142 143 144 |
# File 'lib/pzem016/pzem016.rb', line 142 def wattHours (((@raw[6] << 16) | @raw[5]) * 0.1).round(3) end |
#watts ⇒ Object
Extracts measured watts from the sample data
135 136 137 |
# File 'lib/pzem016/pzem016.rb', line 135 def watts (((@raw[4] << 16) | @raw[3]) * 0.1).round(3) end |