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


Messages In This Thread
reading and logging binary data on serial port - by katesfb - Jul-23-2018, 12:18 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Waiting for input from serial port, then move on KenHorse 3 1,193 Apr-17-2024, 07:21 AM
Last Post: DeaD_EyE
  MCU reboots after opening Serial port when ran from Raspberry PI zazas321 3 489 Mar-19-2024, 09:02 AM
Last Post: zazas321
  pyserial/serial "has no attribute 'Serial' " gowb0w 9 4,619 Aug-24-2023, 07:56 AM
Last Post: gowb0w
  Serial Port As Global Prasanjith 2 1,557 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,206 Mar-13-2023, 04:02 PM
Last Post: deanhystad
  Reading All The RAW Data Inside a PDF NBAComputerMan 4 1,415 Nov-30-2022, 10:54 PM
Last Post: Larz60+
  Reading Data from JSON tpolim008 2 1,135 Sep-27-2022, 06:34 PM
Last Post: Larz60+
  python serial port barryjo 2 1,696 Dec-27-2021, 11:09 PM
Last Post: barryjo
  Help reading data from serial RS485 korenron 8 14,195 Nov-14-2021, 06:49 AM
Last Post: korenron
  Help with WebSocket reading data from anoter function korenron 0 1,354 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