Catch Atribute error
This commit is contained in:
parent
1fda91253b
commit
7ef68564ec
35
render.py
35
render.py
|
@ -3,36 +3,33 @@ import pynmea2
|
||||||
import serial
|
import serial
|
||||||
import io
|
import io
|
||||||
|
|
||||||
ser = serial.Serial('/dev/ttyACM0', 9600, timeout=5.0)
|
ser = serial.Serial('/dev/ttyUSB0', 9600, timeout=5.0)
|
||||||
sio = io.TextIOWrapper(io.BufferedRWPair(ser, ser))
|
sio = io.TextIOWrapper(io.BufferedRWPair(ser, ser))
|
||||||
last_time=00
|
last_time=00
|
||||||
|
|
||||||
|
|
||||||
def check_last_update(time,last_time):
|
|
||||||
if time==last_time:
|
|
||||||
return False
|
|
||||||
else:
|
|
||||||
return True
|
|
||||||
|
|
||||||
while 1:
|
while 1:
|
||||||
try:
|
try:
|
||||||
line = sio.readline()
|
line = sio.readline()
|
||||||
msg = pynmea2.parse(line)
|
msg = pynmea2.parse(line)
|
||||||
|
latitude=msg.latitude
|
||||||
|
longitude=msg.longitude
|
||||||
|
time=msg.timestamp
|
||||||
except serial.SerialException as e:
|
except serial.SerialException as e:
|
||||||
print('Device error: {}'.format(e))
|
print('Device error: {}'.format(e))
|
||||||
break
|
break
|
||||||
except pynmea2.ParseError as e:
|
except pynmea2.ParseError as e:
|
||||||
print('Parse error: {}'.format(e))
|
print('Parse error: {}'.format(e))
|
||||||
continue
|
continue
|
||||||
|
except Exception as e:
|
||||||
|
continue
|
||||||
else:
|
else:
|
||||||
if check_last_update(time=msg.timestamp,last_time=last_time)==True:
|
if last_time==00:
|
||||||
if last_time==00:
|
center = (latitude, longitude)
|
||||||
center = (msg.latitude, msg.longitude,)
|
m = Map(center=center, zoom=15)
|
||||||
m = Map(center=center, zoom=15)
|
marker = Marker(location=center, draggable=False)
|
||||||
marker = Marker(location=center, draggable=False)
|
m.add_layer(marker);
|
||||||
m.add_layer(marker);
|
display(m)
|
||||||
display(m)
|
last_time=time
|
||||||
last_time=msg.timestamp
|
else:
|
||||||
else:
|
marker.location=(latitude, longitude)
|
||||||
marker.location=(msg.latitude, msg.longitude)
|
last_time=time
|
||||||
last_time=msg.timestamp
|
|
||||||
|
|
Loading…
Reference in a new issue