예제 #1
0
    def __init__(self, parent=None):
        super().__init__(parent)

        self._instruments = InstrumentController()
        self._threadPool = QThreadPool()

        self._vcoCharMeasurement = VCOCharMeasurement()

        self._offset = 0.0
        self._offsetF1 = 0.0
        self._offsetF2 = 0.0
        self._offsetF3 = 0.0
        self._offsetF4 = 0.0
        self._offsetF5 = 0.0
        self._freqOffset = 0.0
        self._ampOffset = 0.0
        self._curOffset = 0.0
        self._markerOffsets = [[0.0] * 5] * 5
        self._markerOffset = self._markerOffsets[0]
        self._deltaFs = [0.0] * 6

        self._freqs = list()
        self._raw_amps = list()
        self._amps = list()
        self._smoothAmps = list()

        self._freq = 0.0
        self._amp = 0.0
        self._cur = 0.0

        self._loadParams()
예제 #2
0
    def __init__(self, parent=None):
        super().__init__(parent)

        self.setAttribute(Qt.WA_QuitOnClose)
        self.setAttribute(Qt.WA_DeleteOnClose)

        # create instance variables
        self._ui = uic.loadUi('mainwindow.ui', self)
        self._instrumentController = InstrumentController(parent=self)
        self._connectionWidget = ConnectionWidget(
            parent=self, controller=self._instrumentController)
        self._measureWidget = MeasureWidgetWithSecondaryParameters(
            parent=self, controller=self._instrumentController)
        self._measureModel = MeasureModel(
            parent=self, controller=self._instrumentController)
        self._plotWidget = PrimaryPlotWidget(
            parent=self, result=self._instrumentController.result)
        self._statWidget = StatWidget(parent=self,
                                      result=self._instrumentController.result)

        # init UI
        self._ui.layInstrs.insertWidget(0, self._connectionWidget)
        self._ui.layInstrs.insertWidget(1, self._measureWidget)
        self._ui.layInstrs.insertWidget(2, self._statWidget, 10)

        self._ui.tabWidget.insertTab(0, self._plotWidget,
                                     'Автоматическое измерение')

        self._init()
예제 #3
0
    def __init__(self, parent=None):
        super().__init__(parent)

        self.setAttribute(Qt.WA_QuitOnClose)
        self.setAttribute(Qt.WA_DeleteOnClose)

        # create instance variables
        self._ui = uic.loadUi('mainwindow.ui', self)
        self._instrumentController = InstrumentController(parent=self)
        self._connectionWidget = ConnectionWidget(parent=self, controller=self._instrumentController)
        self._measureWidget = MeasureWidgetWithSecondaryParameters(parent=self, controller=self._instrumentController)
        self._measureModel = MeasureModel(parent=self, controller=self._instrumentController)

        # init UI
        self._ui.layInstrs.insertWidget(0, self._connectionWidget)
        self._ui.layInstrs.insertWidget(1, self._measureWidget)

        self._init()
예제 #4
0
    def __init__(self, parent=None):
        super().__init__(parent)

        self.setAttribute(Qt.WA_QuitOnClose)
        self.setAttribute(Qt.WA_DeleteOnClose)

        # create instance variables
        self._ui = uic.loadUi('mainwindow.ui', self)
        self._instrumentController = InstrumentController(parent=self)
        self._connectionWidget = ConnectionWidget(
            parent=self, controller=self._instrumentController)
        self._measureWidget = MeasureWidgetWithSecondaryParameters(
            parent=self, controller=self._instrumentController)
        self._measureModel = MeasureModel(
            parent=self, controller=self._instrumentController)
        self._sParamPlotWidget = SParamPlotWidget(
            parent=self, result=self._instrumentController.result)
        self._psmPlotWidget = PsmPlotWidget(
            parent=self, result=self._instrumentController.result)
        self._attPlotWidget = AttPlotWidget(
            parent=self, result=self._instrumentController.result)
        self._rmsePlotWidget = ErrorPlotWidget(
            parent=self, result=self._instrumentController.result)

        self._statWidget = StatWidget(parent=self,
                                      result=self._instrumentController.result)

        # init UI
        self._ui.layInstrs.insertWidget(0, self._connectionWidget)
        self._ui.layInstrs.insertWidget(1, self._measureWidget)
        self._ui.layInstrs.insertWidget(2, self._statWidget, 10)

        self._ui.tabWidget.insertTab(0, self._sParamPlotWidget, 'S-параметры')
        self._ui.tabWidget.insertTab(1, self._psmPlotWidget,
                                     'Отклик фазовращателя')
        self._ui.tabWidget.insertTab(2, self._attPlotWidget,
                                     'Отклик аттенюатора')
        self._ui.tabWidget.insertTab(3, self._rmsePlotWidget,
                                     'Амп. и фаз. ошибки')
        self._init()
예제 #5
0
    def __init__(self, parent=None):
        super().__init__(parent)

        self.setAttribute(Qt.WA_QuitOnClose)
        self.setAttribute(Qt.WA_DeleteOnClose)

        # create instance variables
        self._ui = uic.loadUi('mainwindow.ui', self)
        self._instrumentController = InstrumentController(parent=self)
        self._connectionWidget = ConnectionWidget(parent=self, controller=self._instrumentController)
        self._measureWidget = MeasureWidgetWithSecondaryParameters(parent=self, controller=self._instrumentController)
        self._powSweepWidget = make_sweep_widget('pow', parent=self, controller=self._instrumentController)
        self._freqSweepWidget = make_sweep_widget('freq', parent=self, controller=self._instrumentController)

        self._measureModel = MeasureModel(parent=self, controller=self._instrumentController)

        # init UI
        self._ui.layInstrs.insertWidget(0, self._connectionWidget)
        self._ui.layInstrs.insertWidget(1, self._measureWidget)
        self._ui.tabWidget.insertTab(0, self._powSweepWidget, 'По мощности')
        self._ui.tabWidget.insertTab(1, self._freqSweepWidget, 'По частоте')
        self._ui.tabWidget.setCurrentIndex(0)

        self._init()
예제 #6
0
class MainWindow(QMainWindow):

    instrumentsFound = pyqtSignal()
    sampleFound = pyqtSignal()
    measurementFinished = pyqtSignal()

    def __init__(self, parent=None):
        super().__init__(parent)

        self.setAttribute(Qt.WA_QuitOnClose)
        self.setAttribute(Qt.WA_DeleteOnClose)

        # create instance variables
        self._ui = uic.loadUi('mainwindow.ui', self)
        self._instrumentController = InstrumentController(parent=self)
        self._connectionWidget = ConnectionWidget(
            parent=self, controller=self._instrumentController)
        self._measureWidget = MeasureWidgetWithSecondaryParameters(
            parent=self, controller=self._instrumentController)
        self._plotWidget = PrimaryPlotWidget(
            parent=self, controller=self._instrumentController)

        # init UI
        self._ui.layInstrs.insertWidget(0, self._connectionWidget)
        self._ui.layInstrs.insertWidget(1, self._measureWidget)

        self._ui.tabWidget.insertTab(0, self._plotWidget,
                                     'Автоматическое измерение')

        self._init()

    def _init(self):
        self._connectionWidget.connected.connect(self.on_instrumens_connected)
        self._connectionWidget.connected.connect(
            self._measureWidget.on_instrumentsConnected)

        self._measureWidget.secondaryChanged.connect(
            self._instrumentController.on_secondary_changed)

        self._measureWidget.measureStarted.connect(self.on_measureStarted)
        self._measureWidget.measureComplete.connect(self.on_measureComplete)

        self._instrumentController.pointReady.connect(self.on_point_ready)

        self._measureWidget.updateWidgets(
            self._instrumentController.secondaryParams)
        self._measureWidget.on_params_changed(1)

    def _saveScreenshot(self):
        screen = QGuiApplication.primaryScreen()
        if not screen:
            print('error saving screenshot')
            return
        pixmap = screen.grabWindow(self.winId())

        device = 'demod'
        path = 'png'
        if not os.path.isdir(f'{path}'):
            os.makedirs(f'{path}')

        file_name = f'./{path}/{device}-{datetime.datetime.now().isoformat().replace(":", ".")}.png'
        pixmap.save(file_name)

        full_path = os.path.abspath(file_name)
        Popen(f'explorer /select,"{full_path}"')

    @pyqtSlot()
    def on_instrumens_connected(self):
        print(f'connected {self._instrumentController}')

    @pyqtSlot()
    def on_measureComplete(self):
        print('meas complete')
        self._plotWidget.plot()
        self._instrumentController.result.save_adjustment_template()

    @pyqtSlot()
    def on_measureStarted(self):
        self._plotWidget.clear()

    @pyqtSlot()
    def on_actParams_triggered(self):
        data = [
            ('Корректировка', self._instrumentController.result.adjust),
            ('Калибровка', self._instrumentController.cal_set),
            ('Только основные', self._plotWidget.only_main_states),
            ('Набор для коррекции', [1, '+25', '+85', '-60']),
        ]

        values = fedit(data=data, title='Параметры')
        if not values:
            return

        adjust, cal_set, only_main_states, adjust_set = values

        self._instrumentController.result.adjust = adjust
        self._instrumentController.result.adjust_set = adjust_set
        self._instrumentController.cal_set = cal_set
        self._instrumentController.only_main_states = only_main_states
        self._instrumentController.result.only_main_states = only_main_states
        self._plotWidget.only_main_states = only_main_states

    @pyqtSlot()
    def on_point_ready(self):
        self._ui.pteditProgress.setPlainText(
            self._instrumentController.result.report)
        self._plotWidget.plot()

    def closeEvent(self, _):
        self._instrumentController.saveConfigs()
        self._measureWidget.cancel()
        while self._measureWidget._threads.activeThreadCount() > 0:
            time.sleep(0.1)

    @pyqtSlot()
    def on_btnExcel_clicked(self):
        self._instrumentController.result.export_excel()

    @pyqtSlot()
    def on_btnScreenShot_clicked(self):
        self._saveScreenshot()
예제 #7
0
class Domain(QObject):

    measureFinished = pyqtSignal()
    vcoCharMeasurementFinished = pyqtSignal()

    headers = ['F, Hz', 'Noise, dBc/Hz']

    def __init__(self, parent=None):
        super().__init__(parent)

        self._instruments = InstrumentController()
        self._threadPool = QThreadPool()

        self._vcoCharMeasurement = VCOCharMeasurement()

        self._offset = 0.0
        self._offsetF1 = 0.0
        self._offsetF2 = 0.0
        self._offsetF3 = 0.0
        self._offsetF4 = 0.0
        self._offsetF5 = 0.0
        self._freqOffset = 0.0
        self._ampOffset = 0.0
        self._curOffset = 0.0
        self._markerOffsets = [[0.0] * 5] * 5
        self._markerOffset = self._markerOffsets[0]
        self._deltaFs = [0.0] * 6

        self._freqs = list()
        self._raw_amps = list()
        self._amps = list()
        self._smoothAmps = list()

        self._freq = 0.0
        self._amp = 0.0
        self._cur = 0.0

        self._loadParams()

    def _clear(self):
        self._freqs.clear()
        self._amps.clear()

    def _loadParams(self):
        param_file = 'param.ini'
        if not os.path.isfile(param_file):
            return
        with open(param_file) as f:
            for line in f.readlines():
                label, value = line.strip().split('=')
                if label == 'off1':
                    self._offsetF1 = float(value)
                elif label == 'off2':
                    self._offsetF2 = float(value)
                elif label == 'off3':
                    self._offsetF3 = float(value)
                elif label == 'off4':
                    self._offsetF4 = float(value)
                elif label == 'off5':
                    self._offsetF5 = float(value)
                elif label == 'freq':
                    self._freqOffset = float(value)
                elif label == 'amp':
                    self._ampOffset = float(value)
                elif label == 'cur':
                    self._curOffset = float(value)
                elif label == 'mark':
                    self._markerOffsets = ast.literal_eval(value)
                elif label == 'deltas':
                    self._deltaFs = ast.literal_eval(value)

    def applySettings(self, settings):
        self._markerOffsets.clear()
        self._offsetF1 = settings.offsetF1
        self._offsetF2 = settings.offsetF2
        self._offsetF3 = settings.offsetF3
        self._offsetF4 = settings.offsetF4
        self._offsetF5 = settings.offsetF5
        self._freqOffset = settings.freqOffset
        self._ampOffset = settings.ampOffset
        self._curOffset = settings.curOffset
        self._markerOffsets = settings.markerOffset
        self._deltaFs = settings.deltaFs
        with open('param.ini', mode='wt', encoding='utf-8') as f:
            f.writelines([
                f'off1={self._offsetF1}\n', f'off2={self._offsetF2}\n',
                f'off3={self._offsetF3}\n', f'off4={self._offsetF4}\n',
                f'off5={self._offsetF5}\n', f'freq={self._freqOffset}\n',
                f'amp={self._ampOffset}\n', f'cur={self._curOffset}\n',
                f'mark={self._markerOffsets}\n', f'deltas={self._deltaFs}\n'
            ])

    def connect(self):
        print('find instruments')
        return self._instruments.find()

    def check(self):
        print('check sample presence')
        return self._instruments.test_sample()

    def ref_measure_vco_char(self, params):
        self._vcoCharMeasurement.measure_action = self._instruments.ref_measure_vco_char
        self._vcoCharMeasurement.params = params

        self._vcoCharMeasurement.measure()
        self._vcoCharMeasurement.process()

        self.vcoCharMeasurementFinished.emit()

    def measure(self, params: Params):
        print(f'run measurement with {params}')
        self._clear()
        self._threadPool.start(
            Task(self._measureFunc, self._processingFunc, params))

    def _measureFunc(self, params: Params):
        print(f'start measurement task')
        self._freqs, self._raw_amps, self._freq, self._amp, self._cur = self._instruments.measure(
            params)
        print('end measurement task')

    def _processingFunc(self):
        print('processing stats')
        self._amps = list(map(lambda x: x + self._offset, self._raw_amps))
        self._smoothAmps = savgol_filter(self._amps, 31, 3)

        self.measureFinished.emit()

    def rows(self):
        return len(self._amps)

    def cols(self):
        return 2

    def data(self, row, col):
        if col == 1:
            return self._freqs[row]
        elif col == 2:
            return self._amps[row]

    def ampsForMarkers(self, markers):
        if not self._freqs:
            return []
        amps = [
            self._smoothAmps[self._freqs.index(
                min(self._freqs, key=lambda x: abs(freq - x)))]
            for freq in markers
        ]
        amps = [amp + offset for amp, offset in zip(amps, self._markerOffset)]
        return amps

    @property
    def analyzerAddress(self):
        return self._instruments.analyzer_address

    @analyzerAddress.setter
    def analyzerAddress(self, addr):
        self._instruments.analyzer_address = addr

    @property
    def analyzerName(self):
        return str(self._instruments._analyzer)

    @property
    def xs(self):
        return self._freqs

    @property
    def ys(self):
        return self._amps

    @property
    def smoothYs(self):
        return self._smoothAmps

    @property
    def freq(self):
        return float(self._freq) + self._freqOffset

    @property
    def amp(self):
        return float(self._amp) + self._ampOffset

    @property
    def cur(self):
        return float(self._cur) + self._curOffset