Parsing data from pyserial, an (inefficient) solution
Grant Edwards
grante at visi.com
Mon Dec 4 10:49:51 EST 2006
On 2006-12-04, Giovanni Bajo <noway at ask.me> wrote:
[...]
>> This should result in complete packets (from the "M" to a "\r")
>
> Oh well. readline(eol="\r") will do that much better.
Yup. Using readline() has been suggested several times. It
sure seems like the obvious solution to me as well.
> while 1:
> data = ser.readline(eol="\r")
> args = data.split()
> if args[0] == "M":
> # command M; do something with args[1:]
> elif args[0] == "KK":
> # command KK; do something with args[1:]
> [.. process other commands ..]
> else:
> # Invalid command: might be an incomplete
> # packet. Just ignore it.
> pass
--
Grant Edwards grante Yow! Hmmm... A hash-singer
at and a cross-eyed guy were
visi.com SLEEPING on a deserted
island, when...
More information about the Python-list
mailing list