how to read serial stream of data [newbie]

Roy Smith roy at panix.com
Tue Feb 7 00:07:36 EST 2012


In article 
<e84f3af4-da6d-4ae9-8974-54354ec16307 at b18g2000vbz.googlegroups.com>,
 Jean Dupont <jeandupont115 at gmail.com> 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 
(http://docs.python.org/library/functions.html#open), 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 (http://docs.python.org/library/struct.html) to extract the data 
in a more useful form.



More information about the Python-list mailing list