Floppy-currentcost 0.0.2 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README CHANGED
@@ -19,12 +19,10 @@ Homepage: http://github.com/Floppy/currentcost-ruby
19
19
 
20
20
  == REQUIREMENTS
21
21
 
22
- ruby-serialport >= 0.7.0
23
- - You will need to get the source from http://github.com/aaronp/ruby-serialport,
24
- build the gem using "rake gem", and install it before using this gem.
22
+ Floppy-rb232 >= 0.1.0
25
23
 
26
- == STATUS
24
+ == USAGE
27
25
 
28
- This software is in very early development. There is currently no direct access
29
- to the meter via serial port, but you can use CurrentCost::Reading.from_xml to
30
- parse XML which you have got from the meter another way.
26
+ You can read data from the meter by creating an instance of the Meter class,
27
+ and regularly polling it for readings. See examples/simple.rb for an easy
28
+ example of how to do this.
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ dir = File.dirname(__FILE__) + '/../lib'
4
+ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
5
+
6
+ require 'rubygems'
7
+ require 'currentcost/meter'
8
+
9
+ require 'optparse'
10
+
11
+ # Command-line options
12
+ options = {:port => '/dev/ttyS0'}
13
+ OptionParser.new do |opts|
14
+ opts.on("-p", "--serial_port SERIAL_PORT", "serial port") do |p|
15
+ options[:port] = p
16
+ end
17
+ end.parse!
18
+
19
+ # Create meter
20
+ meter = CurrentCost::Meter.new(options[:port])
21
+
22
+ while true
23
+ reading = meter.latest_reading
24
+ if reading
25
+ puts "#{reading.channels[0][:watts]}W"
26
+ end
27
+ sleep(6)
28
+ end
@@ -1,15 +1,32 @@
1
+ require 'rb232'
2
+ require 'rb232/text_protocol'
3
+ require 'currentcost/reading'
4
+
1
5
  module CurrentCost
2
6
 
3
7
  class Meter
4
8
 
5
- def initialize
6
-
9
+ def initialize(port = '/dev/ttyS0')
10
+ @port = RB232::Port.new(port, :baud_rate => 9600)
11
+ @protocol = RB232::TextProtocol.new(@port, "\n")
12
+ @protocol.add_observer(self)
13
+ @protocol.start
7
14
  end
8
-
15
+
16
+ def update(message)
17
+ @latest_reading = Reading.from_xml(message) unless message.nil?
18
+ rescue CurrentCost::ParseError
19
+ nil
20
+ end
21
+
9
22
  def latest_reading
10
- Reading.new
23
+ @latest_reading
11
24
  end
12
-
25
+
26
+ def close
27
+ @protocol.stop
28
+ end
29
+
13
30
  end
14
31
 
15
32
  end
@@ -1,3 +1,6 @@
1
+ require 'currentcost/exceptions'
2
+ require 'rexml/document'
3
+
1
4
  module CurrentCost
2
5
 
3
6
  class Reading
@@ -61,4 +64,4 @@ module CurrentCost
61
64
 
62
65
  end
63
66
 
64
- end
67
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Floppy-currentcost
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Smith
@@ -9,10 +9,18 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-08-05 00:00:00 -07:00
12
+ date: 2008-08-19 00:00:00 -07:00
13
13
  default_executable:
14
- dependencies: []
15
-
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: Floppy-rb232
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.1.0
23
+ version:
16
24
  description:
17
25
  email: james@floppy.org.uk
18
26
  executables: []
@@ -29,6 +37,7 @@ files:
29
37
  - lib/currentcost/reading.rb
30
38
  - lib/currentcost/version.rb
31
39
  - lib/currentcost/exceptions.rb
40
+ - examples/simple.rb
32
41
  has_rdoc: false
33
42
  homepage: http://github.com/Floppy/currentcost-ruby
34
43
  post_install_message: