Flush serialport output before every AT command
parent
a3a9c43d8b
commit
9475bdfb5c
|
@ -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))
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue