py-serial + CSV [英] py-serial + CSV

查看:68
本文介绍了py-serial + CSV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我只是想从串口分析(解析)数据(我已经将
连接的GPS接收器连接到ttyS0,所以我可以读取ASCII字符在

串口1上的CSV表格。

我这样做只是为了理解Python是如何工作的(是的,你可以调用
$ b $我是Python / Linux新手:)

我的环境是Fedora Core 4,Python 2.4.1

单独使用CSV(从文件中读取CSV数据)和py-serial一个人(从串口读取数据
)正在完美运行。


即使我试图谷歌通过这个小组并通过

互联网,我无法直接从

串口读取(和解析)CSV数据。


来自我的串口(使用py-serial)我是这样得的:

import serial
s = serial.Serial(port = 0,baudrate = 4800,timeout = 20)
sr eadline()



''$ GPRMC,101236.331,A,5026.1018,N,01521.6653,E,0.0,328.1,230805 ,, * 09 \\ b \''


我的下一个目的是做这样的事情:


import csv

r = csv.reader(s.readline())

for currentline in r:

if currentline [0] ==''$ GPRMC'':

打印当前行[2]

打印当前行[4]


但它不起作用


感谢您的评论


Petr Jakes

解决方案

GPRMC,101236.331,A ,5026.1018,N,01521.6653,E,0.0,328.1,230805 ,, * 09 \\\\ n'


我的下一个目的是做这样的事情:


导入csv

r = csv.reader(s.readline())

for currentline in r:

if currentline [0] ==''


GPRMC'':

打印当前行[2]

prin t currentline [4]


但它不起作用


感谢您的评论


Petr Jakes


McBooCzech写道:

r = csv.reader(s.readline())




csv.reader期望一个可迭代的,而不是一个str。

-

Michael Hoffman


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

解决方案

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


McBooCzech wrote:

r = csv.reader(s.readline())



csv.reader expects an iterable, not a str.
--
Michael Hoffman


这篇关于py-serial + CSV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆