Python Forum
reading and logging binary data on serial port
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
reading and logging binary data on serial port
#1
Hi,
I have a project to log raw binary GPS data (from a ublox GPS reciever) to a file for later post processing. The receiver puts out raw GPS data message packets (not the NMEA sentences - these have been disabled). The problem i am having is that when i read and log the data to a file the resulting binary file is not the same as the data that i read from. For example if read and log using a terminal program like "cutecom" it works fine so there is obviously something wrong with my code.

The following code simply reads a byte into an array and then logs it to a file as a test:
import serial
import time
import pickle

def setupSerial(GPSPort):
    ser = serial.Serial(port=GPSPort,baudrate=115200,bytesize=8,parity='N',stopbits=1,xonxoff=0,rtscts=0)
    print(ser)               #testing

    return ser

GPSPort="/dev/ttyUSB0"
ser = setupSerial(GPSPort)
newFileBytes=[]

for x in range(1000):
    y = ser.inWaiting()
    print(y)
    if y > 0:
        z=ser.read()
        print(z)
        newFileBytes.append(z)

with open("~/GPSBinTest.ubx","wb") as mypicklefile:
    pickle.dump(newFileBytes, mypicklefile)
Can anybody see what i am doing wrong here.

Any help is much appreciated.

Cheers.
Reply
#2
how are you reading the data back in?
it should be like:
with open("~/GPSBinTest.ubx", 'rb') as fp:
    newdata = pickle.load(fp)
Reply
#3
Anybody......?

Hi,
Sorry Larz60+ i didnt see your reply so thanks.
Anyway i dont know quite what you mean, binary data isnt being loaded from the file it is coming from a GPS receiver connected to the serial port, the data is read into a byte array until 1000 bytes have been read (should it be 512 bytes?). Then it is dumped to a binary file. But the dumped file will not convert in RTKLib so something is wrong with the way i am logging the binary data to the file.

Any help you can give is much appreciated.

Cheers.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Waiting for input from serial port, then move on KenHorse 3 1,101 Apr-17-2024, 07:21 AM
Last Post: DeaD_EyE
  MCU reboots after opening Serial port when ran from Raspberry PI zazas321 3 453 Mar-19-2024, 09:02 AM
Last Post: zazas321
  pyserial/serial "has no attribute 'Serial' " gowb0w 9 4,162 Aug-24-2023, 07:56 AM
Last Post: gowb0w
  Serial Port As Global Prasanjith 2 1,517 Mar-23-2023, 08:54 PM
Last Post: deanhystad
Star Pyserial not reading serial.readline fast enough while using AccelStepper on Arduino MartyTinker 4 4,114 Mar-13-2023, 04:02 PM
Last Post: deanhystad
  Reading All The RAW Data Inside a PDF NBAComputerMan 4 1,359 Nov-30-2022, 10:54 PM
Last Post: Larz60+
  Reading Data from JSON tpolim008 2 1,099 Sep-27-2022, 06:34 PM
Last Post: Larz60+
  python serial port barryjo 2 1,662 Dec-27-2021, 11:09 PM
Last Post: barryjo
  Help reading data from serial RS485 korenron 8 14,045 Nov-14-2021, 06:49 AM
Last Post: korenron
  Help with WebSocket reading data from anoter function korenron 0 1,344 Sep-19-2021, 11:08 AM
Last Post: korenron

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020