Add timeout to raise exception when Modem#wait is stuck

develop
Guillaume DOTT 2013-09-11 16:38:59 +02:00
parent 7281b8f82d
commit aabb2027b0
1 changed files with 5 additions and 2 deletions

View File

@ -1,5 +1,6 @@
require 'serialport'
require 'forwardable'
require 'timeout'
module Biju
class Modem
@ -23,8 +24,10 @@ module Biju
def wait(length: 0)
buffer = ''
while IO.select([connection], [], [], 0.50) || buffer.length < length
buffer << connection.getc.chr
Timeout.timeout(10) do
while IO.select([connection], [], [], 0.50) || buffer.length < length
buffer << connection.getc.chr
end
end
buffer