Reading UBX Messages with pyubx2¶
Pyubx2 is an open-source Python library for parsing and generating UBX protocol messages. It can be used to read the UBX messages listed in Table 3 directly from the Port C serial stream, alongside the RTCM 3 MSM7 correction data sharing that same port.
Installation¶
Pyubx2 requires Python 3.10 or later. Install it together with pyserial, which provides the serial port interface:
Reading Messages from Port C¶
Identify the COM port assigned to Port C by the USB-to-UART driver (see Section 3.1) and connect at 115200 baud. UBXReader parses each frame from the incoming stream as it arrives:
from serial import Serial
from pyubx2 import UBXReader, NMEA_PROTOCOL, UBX_PROTOCOL
port = "COM5"
baud = 115200
with Serial(port, baud, timeout=3) as stream:
ubr = UBXReader(stream, protfilter=UBX_PROTOCOL)
for raw_data, parsed_data in ubr:
if parsed_data is not None:
print(parsed_data)
RTCM3 frames are still consumed from the stream to keep parsing in sync, but return parsed_data = None and are skipped by the check above