#36 Add serial.Serial.readUntil() to read until there is a packet termination character

open
nobody
None
5
2014-03-28
2014-02-12
Jason S
No

For fast serial streams (we've used >= 1MBaud), handling input on a character-by-character basis in the Python layer is too slow. The other alternative presently available is to read N characters with a timeout.

But some serial protocols do not operate with fixed packet lengths, and instead are governed by packet termination characters. (I tend to use COBS -- see http://www.embeddedrelated.com/showarticle/113.php and http://en.wikipedia.org/wiki/Consistent_Overhead_Byte_Stuffing -- which reserves a 0 byte for packet termination)

It would increase the performance of pySerial if I could use a call like this:

ser = serial.Serial(1, 38400, timeout=0,
                    parity=serial.PARITY_EVEN, rtscts=1)
s = ser.readUntil(0, max_chars=254)

which would read up to 254 characters or until there is a 0 byte, whichever comes first. (Or a timeout, if one is set.)

Discussion