Parsing data from pyserial (final resolution)

L

Lone Wolf

After going back and reading everybody's suggestions, I finally
got a simple, efficient solution. As was pointed out to me in
several posts, I needed to use readline rather than read. That's
obvious to me now ... but isn't everything obvious once you
understand it :)

Anyway, I am posting my code on the (slim) chance that someone
new to python and interested in robotics might find it useful:

#########################################################

# This program reads a serial port hookup up to a CMUcam1.
# It tracks the middle of a green object and provides a
confidence estimate

import serial

ser=serial.Serial('com1',baudrate=115200, bytesize=8,
parity='N', stopbits=1,xonxoff=0, timeout=1)

ser.write("TC 016 240 100 240 016 240\r\n") #This line orders
the CMUcam to track green

for i in range(0,100,1):
reading = ser.readline(eol="\r")
components = reading.split()
mx = int(components[1])
my = int(components[2])
confidence = int(components[8])
print mx, my, confidence
ser.close

########################################################

This code will read 5-6 frames per second, which should be
plenty for most vision processing applications.

Once again, I really want to thank those who took the time to
help me. The good news is that I learned something from all my
mistakes.

Happy Hunting

Wolf

________________________________________________
Get your own "800" number
Voicemail, fax, email, and a lot more
http://www.ureach.com/reg/tag
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top