Efficient handling of fast, real-time hex data
greg.ewing at canterbury.ac.nz
Wed Jun 1 00:37:01 EDT 2016
jladasky at itu.edu wrote:
> So, how can I take the byte sequence <0x01 0x02 0x03 0x04 0x05 0x06 \n> that
> Serial.readline() returns to me,
Using readline() to read binary data doesn't sound like
a good idea -- what happens if one of the data bytes
happens to be 0x0a?
If you're going binary, it would be better to ditch the
newlines and read a fixed number of bytes each time.
Regarding speed, if struct.unpack or numpy isn't fast
enough, you may need to deal with the data in bigger
Although if you're not doing a huge amount of processing
with them, I'd expect it to be plenty fast enough.
I just did a quick test, and I was able to unpack
about 700,000 random 6-byte strings per second on
a 2.8GHz Xeon.
More information about the Python-list