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)]
|
full_command = [command, (command_args.empty? ? nil : command_args)]
|
||||||
.compact.join('=') + "\r\n"
|
.compact.join('=') + "\r\n"
|
||||||
|
|
||||||
|
modem.flush
|
||||||
modem.write(full_command)
|
modem.write(full_command)
|
||||||
answer = hayes_to_obj(modem.wait(length: full_command.length))
|
answer = hayes_to_obj(modem.wait(length: full_command.length))
|
||||||
|
|
||||||
|
|
|
@ -22,10 +22,14 @@ module Biju
|
||||||
|
|
||||||
def_delegators :connection, :close, :write
|
def_delegators :connection, :close, :write
|
||||||
|
|
||||||
def wait(length: 0)
|
def flush
|
||||||
|
wait(length: 0, timeout: 0)
|
||||||
|
end
|
||||||
|
|
||||||
|
def wait(length: 0, timeout: 10)
|
||||||
buffer = ''
|
buffer = ''
|
||||||
Timeout.timeout(10) do
|
Timeout.timeout(timeout) do
|
||||||
while IO.select([connection], [], [], 0.50) || buffer.length < length
|
while IO.select([connection], [], [], 0.25) || buffer.length < length
|
||||||
buffer << connection.getc.chr
|
buffer << connection.getc.chr
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue