python写的实时获取gps数据,并保存成txt文档
2个回答
展开全部
import serial
logf = open('your_log_file.txt', 'a')
ser = serial.Serial('/dev/ttyUSB0', baudrate=9600)
try:
while 1:
line = ser.readline()
logf.write(line.strip())
logf.flush()
finally:
logf.close()
追问
我想继续提取gps数据里的经纬度,该怎么写?
追答
import pynmea2
#
# other codes here
#
while 1:
line = ser.readline()
if line.startswith('$GPRMC'):
# The sentence has lat/long
rmc = pynmea2.parse(line)
print rmc.lon, rmc.lat
引用xuniuer2014的回答:
import seriallogf = open('your_log_file.txt', 'a')ser = serial.Serial('/dev/ttyUSB0', baudrate=9600)try: while 1: line = ser.readline() logf.write(line.strip()) logf.flush()finally: logf.close()
import seriallogf = open('your_log_file.txt', 'a')ser = serial.Serial('/dev/ttyUSB0', baudrate=9600)try: while 1: line = ser.readline() logf.write(line.strip()) logf.flush()finally: logf.close()
展开全部
PHP能实现吗?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询