how to read serial stream of data [newbie]

Roy Smith roy at
Tue Feb 7 06:07:36 CET 2012

In article 
<e84f3af4-da6d-4ae9-8974-54354ec16307 at>,
 Jean Dupont <jeandupont115 at> wrote:

> I'd like to read in a stream of data which looks like this:
> the device sends out a byte-string of 11 bytes roughly every second:
>     B0B0B0B0B03131B0B50D8A
>     B0B0B0B0B03131B0B50D8A
>     B0B0B031B63131B0310D8A
>     B0B034B3323432B3310D8A
>     B0B03237B53432B3310D8A
> .
> .
> .
> As you see every string is ended by 0D8A
> How can this be accomplished in Python?

The basic idea would be to open your datastream in binary mode 
(, then use read(11) 
to read exactly 11 bytes into a string.

Depending on what the 11 bytes are, you might want to use the struct 
module ( to extract the data 
in a more useful form.

More information about the Python-list mailing list