I can not make a simple script working fine in Python2.7 work in Python3. The script:
enter code here{
#!/usr/bin/env python
# simple test program to test serial I/O data from gps
#
# Dec 2019 HRK
import Adafruit_BBIO.UART as UART
import serial
UART.setup("UART2")
ser2 = serial.Serial('/dev/ttyO2', timeout=2)
def parseGPS(gps_data):
if gps_data[0:6] == "$GNRMC":
sdata=gps_data.split(",")
if sdata[2] == 'V':
print("Sat data not valid")
return
print("Parsing GNRMC data")
time=sdata[1][0:2]+":"+sdata[1][2:4]+":"+sdata[1][4:6]
lat=decode(sdata[3])
dirlat=sdata[4]
lon=decode(sdata[5])
dirlon=sdata[6]
print('GMT: {} lat: {}{} long: {}{}'.format(time, lat, dirlat, lon, dirlon))
def decode(coord):
# converts dddmm.mmmmm > DD deg MM.MMMMM min
x = coord.split(".")
head = x[0]
tail = x[1]
tail = tail[0:2]
deg = head[0:-2]
min = head[-2:]
return deg + ":" + min + "." + tail
print("receiving GPS data")
while True:
data = ser2.readline()
parseGPS(data)
}
Python2 gives the expected respons. Python3 just stops after printing("receiving GPS data").
I am aware of differences in serial in the two Python version but Googling did not bring a solution for me. The problem is likely the ser2.readline() statement.
Please advise.
Thanks in advance,
Harke