relayrace 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/relayrace.rb +9 -25
- metadata +3 -3
data/lib/relayrace.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'monitor'
|
2
1
|
require 'serialport'
|
3
2
|
require 'system_timer'
|
4
3
|
|
@@ -6,12 +5,6 @@ class RelayrAce
|
|
6
5
|
def initialize(port, logger = nil)
|
7
6
|
@port = port
|
8
7
|
@logger = logger
|
9
|
-
open_serial_port
|
10
|
-
end
|
11
|
-
|
12
|
-
def close
|
13
|
-
@serial.close
|
14
|
-
@serial = @port = nil
|
15
8
|
end
|
16
9
|
|
17
10
|
def get_relay(relay)
|
@@ -43,25 +36,16 @@ class RelayrAce
|
|
43
36
|
end
|
44
37
|
|
45
38
|
def send_cmd(cmd)
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
2.times {
|
51
|
-
|
39
|
+
begin
|
40
|
+
SystemTimer.timeout_after(10) do
|
41
|
+
SerialPort.open(@port, 115200, 8, 1, SerialPort::NONE) do |tty|
|
42
|
+
tty.write("\r\n")
|
43
|
+
2.times { tty.getc == ':' }
|
44
|
+
tty.write("#{cmd}\r\n")
|
52
45
|
end
|
53
|
-
rescue Timeout::Error
|
54
|
-
@logger.warn "Reopening serial port due to timeout" if @logger
|
55
|
-
open_serial_port
|
56
46
|
end
|
47
|
+
rescue Timeout::Error
|
48
|
+
@logger.warn "Failed to execute operation #{cmd}" if @logger
|
57
49
|
end
|
58
50
|
end
|
59
|
-
|
60
|
-
private
|
61
|
-
def open_serial_port
|
62
|
-
@serial.close if @serial
|
63
|
-
sleep 1 # Give the OS a chance to catch up
|
64
|
-
@serial = SerialPort.new(@port, 115200, 8, 1, SerialPort::NONE)
|
65
|
-
@serial.extend(MonitorMixin)
|
66
|
-
end
|
67
|
-
end
|
51
|
+
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: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 2
|
10
|
+
version: 1.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Mat Trudel
|