Parsing data from pyserial

Si Ballenger shb*NO*SPAM* at comporium.net
Sun Dec 3 10:15:07 EST 2006


On Sat, 2 Dec 2006 23:02:06 -0500, Lone Wolf
<lone_wolf at ureach.com> wrote:

>I'm trying to get data through my serial port from a CMUcam.
>This gizmo tracks a color and returns a packet of data. The
>packet has nine data points (well, really eight since the first
>point is just a packet header) separated by spaces as follows: M
>xxx xxx xxx xxx xxx xxx xxx xxx
>
>Here is the code I am using (python v24):
>
>import serial
>
>ser=serial.Serial('com1',baudrate=115200, bytesize=8,
>parity='N', stopbits=1,xonxoff=0, timeout=1)
>
>ser.write("PM 1") #This sets the CMUcam to poll mode
>
>for i in range(0,100,1):
>	ser.write("TC 016 240 100 240 016 240\r\n")
>	reading = ser.read(40)
>	print reading
>	components = reading.split()
>	print components
>ser.close

In my dealing with serial gizmos I have to put a delay between
the request sent to the gizmo and the reading of the serial input
buffer for returned data. Serial ports and gizmos need some time
to do their thing.



More information about the Python-list mailing list