domotics-arduino 0.2.3 → 0.2.4

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.
@@ -176,8 +176,8 @@ module Domotics
176
176
  @logger.info { "Destroy board connection..." }
177
177
  @command_lock.synchronize do
178
178
  @board_listener.exit if @board_listener and @board_listener.alive?
179
- @board.close
180
179
  end
180
+ @board.close
181
181
  @logger.info { "done." }
182
182
  end
183
183
 
@@ -190,8 +190,8 @@ module Domotics
190
190
 
191
191
  # Send command directly to board
192
192
  def send_command(command, pin = 0, value = 0)
193
- @command_lock.synchronize do
194
- Timeout.timeout(1) do
193
+ Timeout.timeout(1) do
194
+ @command_lock.synchronize do
195
195
  @board.puts("#{command} #{pin} #{value}")
196
196
  # Get reply
197
197
  case reply = @reply.pop
@@ -212,9 +212,8 @@ module Domotics
212
212
  end
213
213
  end
214
214
  end
215
- rescue
216
- @logger.error { "Timeout while sending command to board [#{@port_str}]." }
217
- nil
215
+ rescue Timeout::Error
216
+ raise ArgumentError, "Board [#{@port_str}] timeout."
218
217
  end
219
218
  # Listen for board replies and alarms
220
219
  def listen
@@ -227,10 +226,10 @@ module Domotics
227
226
  if @command_lock.locked?
228
227
  @reply.push ArduinoError.new("Board [#{@port_str}] i/o error.")
229
228
  else
230
- connect
231
229
  @logger.error { "Board [#{@port_str}] i/o error." }
230
+ Thread.new { connect }
232
231
  end
233
- terminate
232
+ @board_lock.synchronize { @board_listener.exit }
234
233
  end
235
234
  message = message.chomp.force_encoding("ISO-8859-1").split
236
235
  case message.length
@@ -242,7 +241,6 @@ module Domotics
242
241
  @reply.push(message.collect{ |m| m.to_i })
243
242
  else
244
243
  @reply.push ArduinoError.new("Invalid reply from board [#{@port_str}].") if @command_lock.locked?
245
- terminate
246
244
  end
247
245
  end
248
246
  end
@@ -1,5 +1,5 @@
1
1
  module Domotics
2
2
  module Arduino
3
- VERSION = "0.2.3"
3
+ VERSION = "0.2.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: domotics-arduino
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: