py-serial + CSV

McBooCzech petr at tpc.cz
Tue Aug 23 13:53:09 CEST 2005


Hi
I am just trying to analyze (parse) data from the serial port (I have
connected GPS receiver to the ttyS0, so I can read ASCII characters in
the CSV form on the serial port 1).
I am doing this just to understand how Python works (yes, you can call
me Python/Linux newbie :)
My environment is Fedora Core 4, Python 2.4.1

CSV alone (to read CSV data from the file)  and py-serial alone (to
read data from the serial port) are working flawlessly.

Even I was trying to google through this group and through the
Internet, I am not able to read (and parse) CSV data directly from the
serial port.

data from my serial port (using py-serial) I am getting this way:

>>> import serial
>>> s = serial.Serial(port=0,baudrate=4800, timeout=20)
>>> s.readline()
'$GPRMC,101236.331,A,5026.1018,N,01521.6653,E,0.0,328.1,230805,,*09\r\n'

my next intention was to do something like this:

import csv
r = csv.reader(s.readline())
for currentline in r:
    if currentline[0] == '$GPRMC':
        print currentline[2]
        print currentline[4]

but it does not work

Thanks for your comments

Petr Jakes




More information about the Python-list mailing list