domotics-arduino 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
@@ -185,7 +185,7 @@ module Domotics
|
|
185
185
|
|
186
186
|
# Default event handler simple prints event.
|
187
187
|
def event_handler(hash)
|
188
|
-
|
188
|
+
raise hash[:e] if hash[:e].is_a? ArduinoError
|
189
189
|
end
|
190
190
|
|
191
191
|
# Send command directly to board
|
@@ -250,7 +250,7 @@ module Domotics
|
|
250
250
|
end
|
251
251
|
# Connect to board
|
252
252
|
def connect
|
253
|
-
@board.close if @board
|
253
|
+
@board.close if @board and !@board.closed?
|
254
254
|
# Release command lock
|
255
255
|
@reply.push(FAILREPRLY) if @command_lock.locked?
|
256
256
|
@logger.info { "Open serial connection to board [#{@port_str}]..." }
|
@@ -283,6 +283,7 @@ module Domotics
|
|
283
283
|
@logger.info { "done." } if send_command(DEFAULTS)
|
284
284
|
rescue Exception => e
|
285
285
|
@logger.error { e.message }
|
286
|
+
#@logger.debug { e.backtrace.join }
|
286
287
|
tries = tries || 0
|
287
288
|
tries += 1
|
288
289
|
if tries <= 3
|
@@ -291,8 +292,7 @@ module Domotics
|
|
291
292
|
retry
|
292
293
|
end
|
293
294
|
@logger.error { "Board [#{@port_str}] malfunction. Automatic restart failed." }
|
294
|
-
event_handler :
|
295
|
-
raise ArduinoError, "Board [#{@port_str}] malfunction. Automatic restart failed."
|
295
|
+
event_handler event: :malfunction, e: ArduinoError.new("Board [#{@port_str}] malfunction. Automatic restart failed.")
|
296
296
|
end
|
297
297
|
# Checks
|
298
298
|
def check_pin(pin)
|
data/test/test_arduino.rb
CHANGED
@@ -10,12 +10,12 @@ class ArduinoTest < Test::Unit::TestCase
|
|
10
10
|
def asetup
|
11
11
|
@brd = ArduinoTestBoard.new(port: BoardEmulator.new.port)
|
12
12
|
end
|
13
|
-
def
|
13
|
+
def test_dead_board
|
14
14
|
assert_raise Domotics::Arduino::ArduinoError do
|
15
15
|
ArduinoTestBoard.new(port: BoardEmulator.new(type: :dead).port)
|
16
16
|
end
|
17
17
|
end
|
18
|
-
def
|
18
|
+
def test_crasy_board
|
19
19
|
assert_raise Domotics::Arduino::ArduinoError do
|
20
20
|
ArduinoTestBoard.new(port: BoardEmulator.new(type: :crasy).port)
|
21
21
|
end
|