relayrace 0.0.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/relayrace.rb +22 -11
- metadata +33 -6
data/lib/relayrace.rb
CHANGED
@@ -1,16 +1,12 @@
|
|
1
1
|
require 'monitor'
|
2
2
|
require 'serialport'
|
3
|
+
require 'system_timer'
|
3
4
|
|
4
5
|
class RelayrAce
|
5
|
-
|
6
|
-
Version = '0.0.3'
|
7
|
-
|
8
|
-
attr_reader :port
|
9
|
-
|
10
|
-
def initialize(port)
|
6
|
+
def initialize(port, logger = nil)
|
11
7
|
@port = port
|
12
|
-
@
|
13
|
-
|
8
|
+
@logger = logger
|
9
|
+
open_serial_port
|
14
10
|
end
|
15
11
|
|
16
12
|
def close
|
@@ -48,9 +44,24 @@ class RelayrAce
|
|
48
44
|
|
49
45
|
def send_cmd(cmd)
|
50
46
|
@serial.synchronize do
|
51
|
-
|
52
|
-
|
53
|
-
|
47
|
+
begin
|
48
|
+
SystemTimer.timeout_after(10) do
|
49
|
+
@serial.write("\r\n")
|
50
|
+
until @serial.getc == ':' end
|
51
|
+
@serial.getc # Swallow the next ':'
|
52
|
+
@serial.write("#{cmd}\r\n")
|
53
|
+
end
|
54
|
+
rescue Timeout::Error
|
55
|
+
@logger.warn "Reopening serial port due to timeout" if @logger
|
56
|
+
open_serial_port
|
57
|
+
end
|
54
58
|
end
|
55
59
|
end
|
60
|
+
|
61
|
+
private
|
62
|
+
def open_serial_port
|
63
|
+
@serial.close if @serial
|
64
|
+
@serial = SerialPort.new(@port, 115200, 8, 1, SerialPort::NONE)
|
65
|
+
@serial.extend(MonitorMixin)
|
66
|
+
end
|
56
67
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: relayrace
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
|
+
- 1
|
7
8
|
- 0
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 0.0.3
|
10
|
+
version: 1.0.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Mat Trudel
|
@@ -15,10 +15,37 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-07-
|
18
|
+
date: 2010-07-22 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
|
-
dependencies:
|
21
|
-
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: ruby-serialport
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: SystemTimer
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id002
|
22
49
|
description: RelayrAce talks to Canakit USB relay boards.
|
23
50
|
email: mat@geeky.net
|
24
51
|
executables: []
|