Flush serialport output before every AT command

develop
Guillaume DOTT 2013-10-03 11:05:35 +02:00
parent a3a9c43d8b
commit 9475bdfb5c
2 changed files with 8 additions and 3 deletions

View File

@ -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))

View File

@ -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