[chirp_devel] [PATCH] [New Model] Support for the BTECH Mobile Radios, update 1 for #3015
M.Sc. Pavel Milanes Costa
Sun Mar 27 17:27:48 PDT 2016
El 27/03/16 a las 17:42, Dan Smith via chirp_devel escribió:
>> +def _clean_buffer(radio):
>> >+ """Cleaning the read serial buffer"""
>> >+ radio.pipe.setTimeout(0.1)
>> >+
>> >+ try:
>> >+ dump = radio.pipe.read(100)
>> >+
>> >+ except Exception:
>> >+ raise errors.RadioError("Unknown error cleaning the serial buffer")
> This won't really flush the inbound reliably. You need to loop until you
> read at least once with nothing returned (i.e. hit the timeout). If
> there are 101 bytes in the pipe, this will not read them all out.
> Similarly, if there are ten bytes and the first read returns five of
> those, you won't clear the rest. Remember that read() does not have to
> return all the bytes you asked for.
>
You mean something like this:
===========================================
def _clean_buffer(radio):
# I omitted the non essential code
radio.pipe.setTimeout(0.1) # more or less 100 bytes on a call
out = "1"
while len(out) > 0:
out = radio.pipe.read(100)
===========================================
I have tested it and it will work as you mention, but the script testbed
will hang testing it, with the experience we had reading we found just a
few bytes on the serial queue never reaching 100, so this seems to be a
good number for our case.
Can you mod the testbed to allow for a code like that to pass it?
Thinking bigger: can be useful to have a call like this at the
radio.pipe level? I mean to code it at the radio class to simply call
from any driver like this
radio.pipe.flushInput() or .cleanBuffer() or anything alike.
73
More information about the chirp_devel
mailing list