relayrace 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/LICENCE +1 -0
  2. data/README +9 -0
  3. data/lib/relayrace.rb +54 -0
  4. metadata +57 -0
data/LICENCE ADDED
@@ -0,0 +1 @@
1
+ BSD
data/README ADDED
@@ -0,0 +1,9 @@
1
+ RelayrAce is a simple library to talk to Canakit (and Sparkfun) USB controlled relays.
2
+
3
+ More info on the relay boards can be found at:
4
+
5
+ http://www.canakit.com/catalog/product/view/id/627/s/4-port-usb-relay-controller/
6
+
7
+ and
8
+
9
+ http://www.sparkfun.com/commerce/product_info.php?products_id=9669
data/lib/relayrace.rb ADDED
@@ -0,0 +1,54 @@
1
+ require 'monitor'
2
+ require 'serialport'
3
+
4
+ class RelayrAce
5
+
6
+ Version = '0.0.2'
7
+
8
+ attr_reader :port
9
+
10
+ def initialize(port)
11
+ @port = port
12
+ @serial = SerialPort.new(port, 115200, 8, 1, SerialPort::NONE)
13
+ @serial.extend(MonitorMixin)
14
+ end
15
+
16
+ def close
17
+ @serial.close
18
+ @serial = @port = nil
19
+ end
20
+
21
+ def get_relay(relay)
22
+ abort "Reads aren't working yet"
23
+ end
24
+
25
+ def set_relay(relay, value)
26
+ send_cmd("REL#{relay}.#{(value)? 'ON' : 'OFF'}")
27
+ end
28
+
29
+ def toggle_relay(relay)
30
+ send_cmd("REL#{relay}.TOGGLE")
31
+ end
32
+
33
+ def set_all_relays(value)
34
+ send_cmd("RELS.#{(value)? 'ON' : 'OFF'}")
35
+ end
36
+
37
+ def get_channel(channel)
38
+ abort "Reads aren't working yet"
39
+ end
40
+
41
+ def set_channel(channel, value)
42
+ send_cmd("CH#{channel}.#{(value)? 'ON' : 'OFF'}")
43
+ end
44
+
45
+ def toggle_channel(channel)
46
+ send_cmd("CH#{channel}.TOGGLE")
47
+ end
48
+
49
+ def send_cmd(cmd)
50
+ @serial.synchronize do
51
+ @serial.write("\r\n#{cmd}\r\n")
52
+ end
53
+ end
54
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: relayrace
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Mat Trudel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-06-02 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: RelayrAce talks to Canakit USB relay boards.
17
+ email: mat@geeky.net
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - README
26
+ - LICENCE
27
+ - lib/relayrace.rb
28
+ has_rdoc: true
29
+ homepage:
30
+ licenses: []
31
+
32
+ post_install_message:
33
+ rdoc_options: []
34
+
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: "0"
42
+ version:
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ requirements: []
50
+
51
+ rubyforge_project:
52
+ rubygems_version: 1.3.5
53
+ signing_key:
54
+ specification_version: 3
55
+ summary: RelayrAce talks to Canakit USB relay boards.
56
+ test_files: []
57
+