diff --git a/lib/biju/hayes.rb b/lib/biju/hayes.rb index 9f7f836..70dc9fd 100644 --- a/lib/biju/hayes.rb +++ b/lib/biju/hayes.rb @@ -36,6 +36,7 @@ module Biju full_command = [command, (command_args.empty? ? nil : command_args)] .compact.join('=') + "\r\n" + modem.flush modem.write(full_command) answer = hayes_to_obj(modem.wait(length: full_command.length)) diff --git a/lib/biju/modem.rb b/lib/biju/modem.rb index a209cae..8312688 100644 --- a/lib/biju/modem.rb +++ b/lib/biju/modem.rb @@ -22,10 +22,14 @@ module Biju def_delegators :connection, :close, :write - def wait(length: 0) + def flush + wait(length: 0, timeout: 0) + end + + def wait(length: 0, timeout: 10) buffer = '' - Timeout.timeout(10) do - while IO.select([connection], [], [], 0.50) || buffer.length < length + Timeout.timeout(timeout) do + while IO.select([connection], [], [], 0.25) || buffer.length < length buffer << connection.getc.chr end end