We have a project to read raw binary GPS (in a remote environment) from a ublox NEO M8N and write it to the sd card using a pyboard and then convert the resultant binary file using the RTK library into the Rinex. I did it first with a conventional python3 program on pc (linux) and this worked fine however when i do the same thing using the pybaord the resultant binary file does not convert correctly implying that there is something wrong with the binary file that has been created.
Below is the python3 script that works and the micropython script that doesnt. Can anybody see where i may have gone wrong in the micropython code. What values should i set for timeout and read_buf_len in the uart setup.
Any help is much appreciated.
Cheers.
Code: Select all
import serial, time, os
def setupSerial():
print("Setting up serial object")
ser = serial.Serial(
port=GPSPort,
baudrate=115200,
bytesize=8,
parity='N',
stopbits=1,
#timeout=0,
xonxoff=0,
rtscts=0
)
print(ser)
return ser
print('UbloxRawGPSLog')
time.sleep(2)
newFile = open("/home/richard/Temp/GPSBinTest-Py.ubx","ab")
GPSPort='/dev/ttyUSB0'
ser=setupSerial()
newFileBytes=[]
while True:
newFileBytes=[]
while ser.inWaiting()==0:
pass
z=ser.readline()
newFileBytes.append(z)
for x in range(len(newFileBytes)):
newFile.write(newFileBytes[x])
Code: Select all
import time
from pyb import UART, LED
def setupUart():
print('Setting up uart')
ser=UART(1,115200) #x10=uart_RX
ser.init(115200,timeout=50,read_buf_len=64) #check this
return ser
time.sleep(2)
newFile = open("GPSBinTest.ubx","ab")
ser=setupUart()
newFileBytes=[]
led=LED(1)
led2=LED(2)
led.off()
led2.off()
while True:
newFileBytes=[]
while ser.any()==0:
led2.toggle()
z=ser.readline()
newFileBytes.append(z)
led.toggle()
for x in range(len(newFileBytes)):
newFile.write(newFileBytes[x])