Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #19948
| From | Roy Smith <roy@panix.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: how to read serial stream of data [newbie] |
| Date | 2012-02-07 00:07 -0500 |
| Organization | PANIX Public Access Internet and UNIX, NYC |
| Message-ID | <roy-5854D8.00073507022012@news.panix.com> (permalink) |
| References | <e84f3af4-da6d-4ae9-8974-54354ec16307@b18g2000vbz.googlegroups.com> |
In article <e84f3af4-da6d-4ae9-8974-54354ec16307@b18g2000vbz.googlegroups.com>, Jean Dupont <jeandupont115@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.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
how to read serial stream of data [newbie] Jean Dupont <jeandupont115@gmail.com> - 2012-02-06 13:40 -0800
Re: how to read serial stream of data [newbie] Roy Smith <roy@panix.com> - 2012-02-07 00:07 -0500
Re: how to read serial stream of data [newbie] Jean Dupont <jeandupont115@gmail.com> - 2012-02-07 04:13 -0800
Re: how to read serial stream of data [newbie] Antti J Ylikoski <antti.ylikoski@tkk.fi> - 2012-02-07 15:48 +0200
Re: how to read serial stream of data [newbie] Peter Otten <__peter__@web.de> - 2012-02-07 15:02 +0100
Re: how to read serial stream of data [newbie] Antti J Ylikoski <antti.ylikoski@tkk.fi> - 2012-02-07 19:44 +0200
Re: how to read serial stream of data [newbie] Heiko Wundram <modelnine@modelnine.org> - 2012-02-07 15:04 +0100
Re: how to read serial stream of data [newbie] Jean Dupont <jeandupont115@gmail.com> - 2012-02-07 06:46 -0800
Re: how to read serial stream of data [newbie] Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-02-07 12:44 -0500
csiph-web