Catch Atribute error

This commit is contained in:
DenialOfIntelligence 2023-06-17 10:55:28 +02:00
parent 1fda91253b
commit 7ef68564ec

View file

@ -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 = (msg.latitude, msg.longitude,) center = (latitude, 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=msg.timestamp last_time=time
else: else:
marker.location=(msg.latitude, msg.longitude) marker.location=(latitude, longitude)
last_time=msg.timestamp last_time=time