стек друзей!У меня есть модуль GPS, и я ожидаю, что модуль GPS найдет спутники - за исключением тех случаев, когда модуль GPS ожидает поиска спутников, Python не может запускать что-либо еще.Я не хочу помещать модуль GPS в другой поток.Должен ли я поместить его в другой поток?Есть ли функция GPS, которая позволяет мне запрашивать данные каждые 5 секунд или около того?Я следовал этому уроку: https://learn.adafruit.com/adafruit-ultimate-gps-on-the-raspberry-pi/introduction
Вот мой код:
import os
import serial
import time
import gps #GPSD Library
#See wiring diagram here:
#https://learn.adafruit.com/adafruit-ultimate-gps-on-the-raspberry-pi/using-uart-instead-of-usb
class pa6h():
def __init__(self):
# GPS is on Serial 0. For Raspberry Pi 3 make sure you also
# 1. Turn on serial Hardware in raspi-config
# 2. Put enable_uart=1 in the /boot/config.txt
# 3. Remove any console=... from /boot/cmdline.txt EXCEPT console=tty1
# 4. Run sudo chmod 777 /dev/serial0
# Test code by connecting Pi TX and RX to each other
# self.ser = serial.Serial("dev/serial0", timeout=0.1)
os.system('sudo gpsd /dev/serial0 -F /var/run/gpsd.sock')
self.session = gps.gps("localhost", "2947") #GPSD is on Port 2947
def read_gps(self):
# Test code by connecting Pi TX and RX to each other
# self.ser.write("TEST")
# time.sleep(0.1)
# data = ser.read(10)
self.session.stream(gps.WATCH_ENABLE | gps.WATCH_NEWSTYLE)
while True:
try:
report = self.session.next()
# Wait for a 'TPV' report and display the current time
# print report
# If has TPV, report latitude and longitude
if report['class'] == 'TPV':
if hasattr(report, 'lat') and hasattr(report, 'lon'):
return [report.lat, report.lon]
except KeyError:
pass
except KeyboardInterrupt:
quit()
except StopIteration:
session = None
print "GPSD has terminated"