[PythonCE] gps serial read error
infopazo at hdsnet.hu
infopazo at hdsnet.hu
Sat Dec 2 12:41:18 CET 2006
I receive the folowing error while I read gps information from my MyPal
636N:
('SerialException', '<no args>', [' File "\\SD
card\\work\\python\\serial-teszt.py", line 32, in <module>\n
rv=s.read(50)\n', ' File "\\SD Card\\Program
Files\\Python25\\ceserial.py", line 205, in read\n return
self.__buffered_read(size)\n', ' File "\\SD Card\\Program
Files\\Python25\\ceserial.py", line 248, in __buffered_read\n raise
SerialException, windll.coredll.GetLastError()\n'])
Source code:
# -*- coding:iso8859-2 -*-
import sys
import ctypes
import winbase
import ceserial
import exch
latin2_decoder = lambda s: str(s) #unicode(s, "iso8859-2", "replace")
def gprmc_test(row_ary):
return (row_ary[0] == "$GPRMC") and (row_ary[1]!="") and
(row_ary[3]!="") and (row_ary[5]!="")
def get_pos(row_ary):
return
{'rtime':float(row_ary[1]),'lon':float(row_ary[3]),'lat':float(row_ary[5])}
def rec_pos(data):
cur.execute("insert into coords_rec (rectime,long,lat) values
(%f,%f,%f)"%(data['rtime'],data['lon'],data['lat']))
from sqlite3 import dbapi2 as sqlite
con=sqlite.connect("\\SD Card\\work\\cdata.db",isolation_level=None)
con.text_factory=latin2_decoder
cur=con.cursor()
s=ceserial.Serial(port="COM5:",baudrate=4800)
s.open()
of=open('\\SD Card\\work\\python\\tmp.txt',"w")
rv=s.read(50)
cnt=0
c2=0
while (len(rv)>0) and (cnt<10000) and (c2<5):
try:
of.write(rv)
gps_ary=rv.split(',')
if (gprmc_test(gps_ary)):
rec_pos(get_pos(gps_ary))
print "(%f,%f,%f)"%(rtime,lon,lat)
#break
cnt+=1
rv=s.read(50)
except Exception, e:
c2=c2+1
print "%d. exception: "%c2
print exch.formatExceptionInfo()
con.close()
of.close()
s.close()
More information about the PythonCE
mailing list