I have a GPS device running on COM7. and I can read NMEA data from serial port. It seems that QtPositioning support NMEA source . but I can't find any document about setting NMEA source to it.
I wrote some code to trying my best:
import PySide6.QtPositioning
import PySide6.QtCore
import PySide6.QtSerialPort
print('createSource')
obj = PySide6.QtCore.QObject()
source = PySide6.QtPositioning.QGeoPositionInfoSource.createDefaultSource(obj)
print(source.availableSources())
print('try Nmea Source')
qpNmea = PySide6.QtPositioning.QNmeaPositionInfoSource( PySide6.QtPositioning.QNmeaPositionInfoSource.RealTimeMode)
print(qpNmea.availableSources())
print('try Serial Port')
# new com9 QIODevice
com7 = PySide6.QtSerialPort.QSerialPort("com7" )
com7.setBaudRate(PySide6.QtSerialPort.QSerialPort.Baud9600)
com7.setDataBits(PySide6.QtSerialPort.QSerialPort.Data8)
com7.setParity(PySide6.QtSerialPort.QSerialPort.NoParity)
com7.setStopBits(PySide6.QtSerialPort.QSerialPort.OneStop)
com7.setFlowControl(PySide6.QtSerialPort.QSerialPort.NoFlowControl)
com7.open(PySide6.QtSerialPort.QSerialPort.ReadWrite)
com7.open(PySide6.QtSerialPort.QSerialPort.ReadOnly)
print(com7.readLine())
print('setDevice')
qpNmea.setDevice(com7)
qpNmea.startUpdates()
print(qpNmea.device())
print('others')
print(PySide6.QtPositioning.QGeoSatelliteInfoSource.availableSources())
print(PySide6.QtPositioning.QGeoPositionInfoSource.availableSources())
print(PySide6.QtPositioning.QNmeaPositionInfoSource.availableSources())
print ('end')
OUTPUT:
createSource
['winrt', 'nmea']
try Nmea Source
['winrt', 'nmea']
try Serial Port
b''
setDevice
<PySide6.QtSerialPort.QSerialPort(0x28928ad9680) at 0x000002892956F800>
others
[]
['winrt', 'nmea']
['winrt', 'nmea']
end