def update_devices(self):
     detector = QgsGpsDetector('scan')
     self.deviceComboBox.clear()
     devices_list = []
     for port in detector.availablePorts():
         devices_list.append(port[0])
     self.deviceComboBox.addItems(devices_list)
Example #2
0
    def connectGPS(self, portname):
        if not self.isConnected:
            self._currentport = portname
            if portname == 'scan' or portname == '':
                portname = ''
                self.detector = QgsGpsDetector(portname)
                self.detector.detected.connect(self._gpsfound)
                self.detector.detectionFailed.connect(self.gpsfailed)
                self.isConnectFailed = False
                self.detector.advance()
            elif portname.startswith("COM"):
                self.device = QSerialPort(portname)
                baudrates = [
                    QSerialPort.Baud4800, QSerialPort.Baud9600,
                    QSerialPort.Baud38400, QSerialPort.Baud57600,
                    QSerialPort.Baud115200
                ]
                flow = config.get("gps", {}).get("flow_control", None)
                rate = config.get("gps", {}).get("rate", None)
                if rate:
                    baudrates = [rate]

                for rate in baudrates:
                    self.device.setBaudRate(rate)
                    if flow == "hardware":
                        log("using hardware flow control for GPS")
                        self.device.setFlowControl(QSerialPort.HardwareControl)
                    elif flow == "software":
                        log("using software flow control for GPS")
                        self.device.setFlowControl(QSerialPort.SoftwareControl)
                    else:
                        self.device.setFlowControl(QSerialPort.NoFlowControl)
                    self.device.setParity(QSerialPort.NoParity)
                    self.device.setDataBits(QSerialPort.Data8)
                    self.device.setStopBits(QSerialPort.OneStop)
                    if self.device.open(QIODevice.ReadWrite):
                        log("Connection opened with {0}".format(
                            self.device.baudRate()))
                        self.gpsConn = QgsNmeaConnection(self.device)
                        self._gpsfound(self.gpsConn)
                        break
                    else:
                        del self.device
                        continue
                else:
                    # If we can't connect to any GPS just error out
                    self.gpsfailed.emit()
Example #3
0
    def startGPS(self):

        try:
            TOMsMessageLog.logMessage("In GPS_Thread.startGPS - running ... ",
                                      level=Qgis.Info)
            self.gpsCon = None
            #self.port = "COM3"  # TODO: Add menu to select port
            self.gpsDetector = QgsGpsDetector(self.gpsPort)
            self.gpsDetector.detected[QgsGpsConnection].connect(
                self.connection_succeed)
            self.gpsDetector.detectionFailed.connect(self.connection_failed)

            self.gpsDetector.advance()

        except Exception as e:
            TOMsMessageLog.logMessage(
                ("In GPS_Thread.startGPS - exception: " + str(e)),
                level=Qgis.Warning)
            self.gpsError.emit(e)
Example #4
0
def getGpsConnection():
    gpsConnection = None
    port = str(QgsSettings().value("/kadas/gps_port", ""))
    gpsDetector = QgsGpsDetector(port)
    loop = QEventLoop()

    def gpsDetected(connection):
        gpsConnection = connection  # NOQA
        loop.exit()

    def gpsDetectionFailed():
        loop.exit()

    gpsDetector.detected.connect(gpsDetected)
    gpsDetector.detectionFailed.connect(gpsDetectionFailed)
    gpsDetector.advance()
    loop.exec_()

    return gpsConnection
Example #5
0
 def activate(self):
     try:
         self.deactivate()
         if self.actionGPStoggle.isChecked():
             if self.port is None:
                 self.info.msg("Kein GPS Port gesetzt!")
                 return
             self.actionGPSport.setEnabled(False)
             if self.actionGPSlog.isChecked():
                 self.gpsLog.log('gps activate')
             self.gpsDetector = QgsGpsDetector(self.port)
             self.gpsDetector.detected[QgsGpsConnection].connect(
                 self.connection_succeed)
             # self.gpsDetector.detected[QgsNmeaConnection].connect(self.connection_succeed)
             self.gpsDetector.detectionFailed.connect(
                 self.connection_failed)
             self.gpsDetector.advance()
             self.init_marker()
     except Exception as e:
         self.info.err(e)
Example #6
0
    def connectGPS(self, portname):
        if not self.connected:
            self._currentport = portname
            if config.get("gps", {}).get("exp1", False):
                log("Using QgsSettings override for flow control")
                if portname == 'scan' or portname == '':
                    portname = ''

                flow = config.get("gps", {}).get("flow_control", None)
                log(f"GPS flow control is: {flow}")
                settings = QgsSettings()

                if flow:
                    if flow == "hardware":
                        settings.setValue("gps/flow_control", QSerialPort.HardwareControl, QgsSettings.Core)
                    elif flow == "software":
                        settings.setValue("gps/flow_control", QSerialPort.SoftwareControl, QgsSettings.Core)

                self.detector = QgsGpsDetector(portname)
                self.detector.detected.connect(self.gpsfound_handler)
                self.detector.detectionFailed.connect(self.gpsfailed)
                self.detector.advance()
            else:
                log("Using default code for GPS connection")
                if portname == 'scan' or portname == '':
                    portname = ''
                    self.detector = QgsGpsDetector(portname)
                    self.detector.detected.connect(self.gpsfound_handler)
                    self.detector.detectionFailed.connect(self.gpsfailed)
                    self.detector.advance()
                elif portname.startswith("COM"):
                    flow = config.get("gps", {}).get("flow_control", None)
                    rate = config.get("gps", {}).get("rate", None)
                    if rate:
                        baudrates = [rate]
                    else:
                        baudrates = [QSerialPort.Baud4800,
                                     QSerialPort.Baud9600,
                                     QSerialPort.Baud38400,
                                     QSerialPort.Baud57600,
                                     QSerialPort.Baud115200]

                    for rate in baudrates:
                        device = QSerialPort(portname)
                        device.setBaudRate(rate)
                        if flow == "hardware":
                            log("Using hardware flow control")
                            device.setFlowControl(QSerialPort.HardwareControl)
                        elif flow == "software":
                            log("Using software flow control")
                            device.setFlowControl(QSerialPort.SoftwareControl)
                        else:
                            device.setFlowControl(QSerialPort.NoFlowControl)
                        device.setParity(QSerialPort.NoParity)
                        device.setDataBits(QSerialPort.Data8)
                        device.setStopBits(QSerialPort.OneStop)
                        if device.open(QIODevice.ReadWrite):
                            gpsConn = QgsNmeaConnection(device)
                            self.gpsfound_handler(gpsConn)
                            break
                        else:
                            continue
                    else:
                        # If we can't connect to any GPS just error out
                        self.gpsfailed.emit()