コード例 #1
0
 def setFrequency(self, frequency):
     f = RFTools.parseFrequency(frequency)
     if f > 0:
         self.frequency = f
         self.updated.emit()
     else:
         self.frequency = 0
         self.updated.emit()
         return
コード例 #2
0
ファイル: Frequency.py プロジェクト: Lusitanv/nanovna-saver
 def setMaximumFrequency(self):
     max_freq_str, selected = QtWidgets.QInputDialog.getText(
         self,
         "Stop frequency",
         "Set stop frequency",
         text=str(self.maxFrequency))
     if not selected:
         return
     max_freq = RFTools.parseFrequency(max_freq_str)
     if max_freq > 0 and not (self.fixedSpan
                              and max_freq <= self.minFrequency):
         self.maxFrequency = max_freq
     if self.fixedSpan:
         self.update()
コード例 #3
0
    def run(self):
        logger.info("Initializing SweepWorker")
        self.running = True
        self.percentage = 0
        if not self.app.serial.is_open:
            logger.debug("Attempted to run without being connected to the NanoVNA")
            self.running = False
            return

        if int(self.app.sweepCountInput.text()) > 0:
            self.noSweeps = int(self.app.sweepCountInput.text())

        logger.info("%d sweeps", self.noSweeps)
        if self.averaging:
            logger.info("%d averages", self.averages)

        if self.app.sweepStartInput.text() == "" or self.app.sweepEndInput.text() == "":
            logger.debug("First sweep - standard range")
            # We should handle the first startup by reading frequencies?
            sweep_from = 1000000
            sweep_to = 800000000
        else:
            sweep_from = RFTools.parseFrequency(self.app.sweepStartInput.text())
            sweep_to = RFTools.parseFrequency(self.app.sweepEndInput.text())
            logger.debug("Parsed sweep range as %d to %d", sweep_from, sweep_to)
            if sweep_from < 0 or sweep_to < 0 or sweep_from == sweep_to:
                logger.warning("Can't sweep from %s to %s",
                               self.app.sweepStartInput.text(),
                               self.app.sweepEndInput.text())
                self.error_message = \
                    "Unable to parse frequency inputs - check start and stop fields."
                self.stopped = True
                self.running = False
                self.signals.sweepError.emit()
                return

        span = sweep_to - sweep_from
        stepsize = int(span / (self.noSweeps * self.vna.datapoints - 1))

        #  Setup complete

        values = []
        values21 = []
        frequencies = []

        if self.averaging:
            for i in range(self.noSweeps):
                logger.debug("Sweep segment no %d averaged over %d readings", i, self.averages)
                if self.stopped:
                    logger.debug("Stopping sweeping as signalled")
                    break
                start = sweep_from + i * self.vna.datapoints * stepsize
                freq, val11, val21 = self.readAveragedSegment(
                    start, start + (self.vna.datapoints-1) * stepsize, self.averages)

                frequencies += freq
                values += val11
                values21 += val21

                self.percentage = (i + 1) * (self.vna.datapoints-1) / self.noSweeps
                logger.debug("Saving acquired data")
                self.saveData(frequencies, values, values21)

        else:
            for i in range(self.noSweeps):
                logger.debug("Sweep segment no %d", i)
                if self.stopped:
                    logger.debug("Stopping sweeping as signalled")
                    break
                start = sweep_from + i*self.vna.datapoints*stepsize
                try:
                    freq, val11, val21 = self.readSegment(
                        start, start+(self.vna.datapoints-1)*stepsize)

                    frequencies += freq
                    values += val11
                    values21 += val21

                    self.percentage = (i+1)*100/self.noSweeps
                    logger.debug("Saving acquired data")
                    self.saveData(frequencies, values, values21)
                except NanoVNAValueException as e:
                    self.error_message = str(e)
                    self.stopped = True
                    self.running = False
                    self.signals.sweepError.emit()
                except NanoVNASerialException as e:
                    self.error_message = str(e)
                    self.stopped = True
                    self.running = False
                    self.signals.sweepFatalError.emit()

        while self.continuousSweep and not self.stopped:
            logger.debug("Continuous sweeping")
            for i in range(self.noSweeps):
                logger.debug("Sweep segment no %d", i)
                if self.stopped:
                    logger.debug("Stopping sweeping as signalled")
                    break
                start = sweep_from + i * self.vna.datapoints * stepsize
                try:
                    _, values, values21 = self.readSegment(
                        start, start + (self.vna.datapoints-1) * stepsize)
                    logger.debug("Updating acquired data")
                    self.updateData(values, values21, i, self.vna.datapoints)
                except NanoVNAValueException as e:
                    self.error_message = str(e)
                    self.stopped = True
                    self.running = False
                    self.signals.sweepError.emit()
                except NanoVNASerialException as e:
                    self.error_message = str(e)
                    self.stopped = True
                    self.running = False
                    self.signals.sweepFatalError.emit()

        # Reset the device to show the full range if we were multisegment
        if self.noSweeps > 1:
            logger.debug("Resetting NanoVNA sweep to full range: %d to %d",
                         RFTools.parseFrequency(
                             self.app.sweepStartInput.text()),
                         RFTools.parseFrequency(self.app.sweepEndInput.text()))
            self.vna.resetSweep(RFTools.parseFrequency(self.app.sweepStartInput.text()),
                                RFTools.parseFrequency(self.app.sweepEndInput.text()))

        self.percentage = 100
        logger.debug("Sending \"finished\" signal")
        self.signals.finished.emit()
        self.running = False
        return
コード例 #4
0
ファイル: Marker.py プロジェクト: ve7it/nanovna-saver
 def setFrequency(self, frequency):
     f = RFTools.parseFrequency(frequency)
     self.frequency = max(f, 0)
     self.updated.emit(self)