Add timeout to raise exception when Modem#wait is stuck
parent
7281b8f82d
commit
aabb2027b0
|
@ -1,5 +1,6 @@
|
||||||
require 'serialport'
|
require 'serialport'
|
||||||
require 'forwardable'
|
require 'forwardable'
|
||||||
|
require 'timeout'
|
||||||
|
|
||||||
module Biju
|
module Biju
|
||||||
class Modem
|
class Modem
|
||||||
|
@ -23,8 +24,10 @@ module Biju
|
||||||
|
|
||||||
def wait(length: 0)
|
def wait(length: 0)
|
||||||
buffer = ''
|
buffer = ''
|
||||||
while IO.select([connection], [], [], 0.50) || buffer.length < length
|
Timeout.timeout(10) do
|
||||||
buffer << connection.getc.chr
|
while IO.select([connection], [], [], 0.50) || buffer.length < length
|
||||||
|
buffer << connection.getc.chr
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
buffer
|
buffer
|
||||||
|
|
Loading…
Reference in New Issue