Class: CurrentCost::Meter
- Inherits:
-
Object
- Object
- CurrentCost::Meter
- Defined in:
- lib/currentcost/meter.rb
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(port = '/dev/ttyS0') ⇒ Meter
constructor
A new instance of Meter.
- #latest_reading ⇒ Object
- #update(message) ⇒ Object
Constructor Details
#initialize(port = '/dev/ttyS0') ⇒ Meter
Returns a new instance of Meter.
9 10 11 12 13 14 |
# File 'lib/currentcost/meter.rb', line 9 def initialize(port = '/dev/ttyS0') @port = RB232::Port.new(port, :baud_rate => 9600) @protocol = RB232::TextProtocol.new(@port, "\n") @protocol.add_observer(self) @protocol.start end |
Instance Method Details
#close ⇒ Object
26 27 28 |
# File 'lib/currentcost/meter.rb', line 26 def close @protocol.stop end |
#latest_reading ⇒ Object
22 23 24 |
# File 'lib/currentcost/meter.rb', line 22 def latest_reading @latest_reading end |
#update(message) ⇒ Object
16 17 18 19 20 |
# File 'lib/currentcost/meter.rb', line 16 def update() @latest_reading = Reading.from_xml() unless .nil? rescue CurrentCost::ParseError nil end |