Hello, I'm trying to make timer which spit out gps signal every 10 or 60 seconds.
here is my code.
*
**import threading
import time
import serial
import datetime, string
from pynmea import nmea
def init_serial():
COMNUM = 13
global ser
ser = serial.Serial()
ser.baudrate = 9600
ser.port = 12
ser.timeout = 1
ser.open() **
def to_degrees(lats, longs): #convert nmea signal to usual altitude, longitude
lat_deg = lats[0:2]
lat_mins = lats[2:4]
lat_secs = round(float(lats[5:])*60/10000, 2)
lat_str = lat_deg + u'°'+ lat_mins + string.printable[68] + str(lat_secs) + string.printable[63]
lon_deg = longs[0:3]
lon_mins = longs[3:5]
lon_secs = round(float(longs[6:])*60/10000, 2)
lon_str = lon_deg + u'°'+ lon_mins + string.printable[68] + str(lon_secs) + string.printable[63]
return [lat_str, lon_str]
def gpgga(): # get gps signal
data = ser.readline()
if data[0:6] == "$GPGGA":
gpgga = nmea.GPGGA()
gpgga.parse(data)
lats = gpgga.latitude
lat_dir = gpgga.lat_direction
longs = gpgga.longitude
long_dir = gpgga.lon_direction
alt = gpgga.antenna_altitude
time = gpgga.timestamp
lat_lon = to_degrees(lats, longs)
print time
print "Latitude: ", lat_lon[0]+lat_dir ,"&", "Longitude: ", lat_lon[1]+long_dir
print "Altitude: ", alt
class Timer(threading.Thread): # Repeat timer and here is questions.
def __init__(self):
threading.Thread.__init__(self)
self.event = threading.Event()
def run(self):
while not self.event.is_set():
init_serial()
print datetime.datetime.now()
gpgga()
self.event.wait(14.2857142857142857142857)
ser.close()
def stop(self):
self.event.set()
i=0
while i<100:
tmr=Timer()
tmr.start()
print i
i=i+1
tmr.stop()
time.sleep(10)
ser.close()*
at the timer part, self.event.wait(14.2857142857142857142857) is waiting function but it didn't work and only time.sleep(10) function works.
what's wrong? and how to fix it