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)
===========================================
Yes.
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.
Because of the random influx test that generates garbage for every read, right? That test is proving that if you literally just do the above, then you would hang in a real-world case as well. Imagine if someone chose the wrong serial port and instead chose an NMEA GPS with a constant stream of data. You'd hang.
So, put a limit on it and discard data, failing if you read 100 or 1024 bytes before you hit the "end" or something like that. Just saying, read(100) can't be sure to clear the buffer.
--Dan