Permalink
Browse files

Fail fast on USB disconnect

  • Loading branch information...
1 parent d47fb86 commit 36e1433eb36856fafb4994af34ecd3899f5272bd @tpope committed Mar 9, 2011
Showing with 4 additions and 5 deletions.
  1. +4 −5 lib/zerbo.rb
View
@@ -17,9 +17,6 @@ def initialize(device=nil)
else
require 'serialport'
@device = SerialPort.new(device, 38400)
- unless RUBY_PLATFORM =~ /darwin/
- @device.read_timeout = 0
- end
end
@callbacks = []
end
@@ -41,8 +38,10 @@ def next_packet
end
alias next next_packet
- def read(*args)
- device.read(*args)
+ def read(length)
+ data = device.read(length)
+ raise Error, "Read timeout" unless data.to_s.length == length
+ data
end
protected :read

0 comments on commit 36e1433

Please sign in to comment.