Implemented switching of signal pathway.

This commit is contained in:
jupfi 2023-08-18 14:57:38 +02:00
parent e2a7bc997f
commit 11ab6c7e93
4 changed files with 189 additions and 125 deletions

View file

@ -2,8 +2,10 @@ import logging
import numpy as np
import json
from serial.tools.list_ports import comports
from PyQt6.QtTest import QTest
from PyQt6 import QtSerialPort
from PyQt6.QtCore import QThread, pyqtSignal, pyqtSlot
from PyQt6.QtCore import QThread, pyqtSignal, pyqtSlot, Qt
from PyQt6.QtWidgets import QApplication
from nqrduck.module.module_controller import ModuleController
from .model import S11Data, LookupTable
@ -93,12 +95,8 @@ class AutoTMController(ModuleController):
self.module.model.clear_data_points()
self.module.view.create_frequency_sweep_spinner_dialog()
# Print the command 'f<start>f<stop>f<step>' to the serial connection
try:
command = "f%sf%sf%s" % (start_frequency, stop_frequency, FREQUENCY_STEP)
self.module.model.serial.write(command.encode("utf-8"))
except AttributeError:
logger.error("Could not start frequency sweep. No device connected.")
self.module.view.frequency_sweep_spinner.hide()
command = "f%sf%sf%s" % (start_frequency, stop_frequency, FREQUENCY_STEP)
self.send_command(command)
def on_ready_read(self) -> None:
"""This method is called when data is received from the serial connection."""
@ -166,7 +164,7 @@ class AutoTMController(ModuleController):
command = "s%s" % next_frequency
LUT.started_frequency = next_frequency
logger.debug("Starting next voltage sweep: %s", command)
serial.write(command.encode("utf-8"))
self.send_command(command)
def on_short_calibration(self, start_frequency: float, stop_frequency: float) -> None:
"""This method is called when the short calibration button is pressed.
@ -333,11 +331,9 @@ class AutoTMController(ModuleController):
tuning_voltage,
matching_voltage,
)
try:
command = "v%sv%s" % (matching_voltage, tuning_voltage)
self.module.model.serial.write(command.encode("utf-8"))
except AttributeError:
logger.error("Could not set voltages. No device connected.")
command = "v%sv%s" % (matching_voltage, tuning_voltage)
self.send_command(command)
def generate_lut(
self,
@ -405,4 +401,38 @@ class AutoTMController(ModuleController):
# We write the first command to the serial connection
command = "s%s" % (start_frequency)
self.module.model.serial.write(command.encode("utf-8"))
self.send_command(command)
def switch_to_preamp(self) -> None:
""" This method is used to send the command 'cp' to the atm system. This switches the signal pathway of the atm system to 'RX' to 'Preamp'.
This is the mode for either NQR or NMR measurements or if on wants to check the tuning of the probe coil on a network analyzer.
"""
logger.debug("Switching to preamp")
self.send_command("cp")
def switch_to_atm(self) -> None:
""" This method is used to send the command 'ca' to the atm system. This switches the signal pathway of the atm system to 'RX' to 'ATM.
In this state the atm system can be used to measure the reflection coefficient of the probecoils.
"""
logger.debug("Switching to atm")
self.send_command("ca")
def send_command(self, command : str) -> None:
""" This method is used to send a command to the active serial connection.
Args:
command (str): The command that should be send to the atm system.
"""
logger.debug("Sending command %s", command)
try:
self.module.model.serial.write(command.encode("utf-8"))
# Wait for 0.5 seconds
QTest.qWait(500)
# Make sure that the command is being send
QApplication.processEvents()
except AttributeError:
logger.error("Could not send command. No device connected.")
self.module.view.add_error_text("Could not send command. No device connected.")

View file

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>1280</width>
<height>777</height>
<height>862</height>
</rect>
</property>
<property name="sizePolicy">
@ -91,7 +91,7 @@
<item>
<widget class="QTabWidget" name="typeTab">
<property name="currentIndex">
<number>1</number>
<number>0</number>
</property>
<widget class="QWidget" name="mechTab">
<attribute name="title">
@ -99,7 +99,7 @@
</attribute>
<layout class="QVBoxLayout" name="verticalLayout" stretch="0">
<item>
<widget class="QPushButton" name="pushButton">
<widget class="QPushButton" name="homingButton">
<property name="text">
<string>Homing</string>
</property>
@ -111,38 +111,29 @@
<attribute name="title">
<string>Electrical</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_3" rowstretch="0,0,0,0,0,0,0,0,0,0,0">
<item row="3" column="0" colspan="2">
<widget class="QPushButton" name="setvoltagesButton">
<layout class="QGridLayout" name="gridLayout_3" rowstretch="0,0,0,0,0,0,0,0,0,0,0,0,0">
<item row="5" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Set Voltages</string>
<string>Voltage Resolution</string>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QDoubleSpinBox" name="stopfrequencyBox"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_9">
<property name="font">
<font>
<bold>true</bold>
</font>
</property>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Set Voltages:</string>
<string>Voltage Tuning</string>
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="QLabel" name="label_14">
<property name="text">
<string>Frequency Step (MHz)</string>
</property>
</widget>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="tuningBox"/>
</item>
<item row="6" column="1">
<widget class="QDoubleSpinBox" name="startfrequencyBox"/>
<item row="8" column="1">
<widget class="QDoubleSpinBox" name="frequencystepBox"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_11">
@ -156,18 +147,8 @@
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QDoubleSpinBox" name="resolutionBox"/>
</item>
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="matchingBox"/>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Voltage Resolution</string>
</property>
</widget>
<item row="6" column="1">
<widget class="QDoubleSpinBox" name="startfrequencyBox"/>
</item>
<item row="9" column="0" colspan="2">
<widget class="QPushButton" name="generateLUTButton">
@ -176,16 +157,6 @@
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="QDoubleSpinBox" name="frequencystepBox"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Voltage Matching</string>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="label_13">
<property name="text">
@ -193,10 +164,46 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<item row="5" column="1">
<widget class="QDoubleSpinBox" name="resolutionBox"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_9">
<property name="font">
<font>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Voltage Tuning</string>
<string>Set Voltages:</string>
</property>
</widget>
</item>
<item row="11" column="0">
<widget class="QLabel" name="label_15">
<property name="text">
<string>RF Switch:</string>
</property>
</widget>
</item>
<item row="10" column="0" colspan="2">
<widget class="QPushButton" name="viewLUTButton">
<property name="text">
<string>View LUT</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QPushButton" name="setvoltagesButton">
<property name="text">
<string>Set Voltages</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Voltage Matching</string>
</property>
</widget>
</item>
@ -207,13 +214,27 @@
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="tuningBox"/>
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="matchingBox"/>
</item>
<item row="10" column="0" colspan="2">
<widget class="QPushButton" name="viewLUTButton">
<item row="8" column="0">
<widget class="QLabel" name="label_14">
<property name="text">
<string>View LUT</string>
<string>Frequency Step (MHz)</string>
</property>
</widget>
</item>
<item row="12" column="0">
<widget class="QPushButton" name="switchpreampButton">
<property name="text">
<string>Preamplifier</string>
</property>
</widget>
</item>
<item row="12" column="1">
<widget class="QPushButton" name="switchATMButton">
<property name="text">
<string>ATM</string>
</property>
</widget>
</item>

View file

@ -19,7 +19,6 @@ from PyQt6.QtWidgets import (
QTableWidgetItem,
)
from PyQt6.QtCore import pyqtSlot, Qt
from PyQt6.QtTest import QTest
from nqrduck.module.module_view import ModuleView
from nqrduck.contrib.mplwidget import MplWidget
from .widget import Ui_Form
@ -80,6 +79,12 @@ class AutoTMView(ModuleView):
# On clicking of the calibration button call the on_calibration_button_clicked method
self._ui_form.calibrationButton.clicked.connect(self.on_calibration_button_clicked)
# On clicking of the switchpreampButton call the switch_preamp method
self._ui_form.switchpreampButton.clicked.connect(self.module.controller.switch_to_preamp)
# On clicking of the switchATMButton call the switch_atm method
self._ui_form.switchATMButton.clicked.connect(self.module.controller.switch_to_atm)
# Connect the measurement finished signal to the plot_measurement slot
self.module.model.measurement_finished.connect(self.plot_measurement)
@ -312,10 +317,6 @@ class AutoTMView(ModuleView):
matching_voltage = str(self.module.model.LUT.data[frequency][0])
self.module.controller.set_voltages(tuning_voltage, matching_voltage)
# Wait for 0.5 seconds
QTest.qWait(500)
QApplication.processEvents()
class CalibrationWindow(QWidget):
def __init__(self, module, parent=None):
super().__init__()

View file

@ -12,7 +12,7 @@ from PyQt6 import QtCore, QtGui, QtWidgets
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(1280, 777)
Form.resize(1280, 862)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Preferred, QtWidgets.QSizePolicy.Policy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
@ -62,71 +62,80 @@ class Ui_Form(object):
self.mechTab.setObjectName("mechTab")
self.verticalLayout = QtWidgets.QVBoxLayout(self.mechTab)
self.verticalLayout.setObjectName("verticalLayout")
self.pushButton = QtWidgets.QPushButton(parent=self.mechTab)
self.pushButton.setObjectName("pushButton")
self.verticalLayout.addWidget(self.pushButton)
self.homingButton = QtWidgets.QPushButton(parent=self.mechTab)
self.homingButton.setObjectName("homingButton")
self.verticalLayout.addWidget(self.homingButton)
self.typeTab.addTab(self.mechTab, "")
self.elecTab = QtWidgets.QWidget()
self.elecTab.setObjectName("elecTab")
self.gridLayout_3 = QtWidgets.QGridLayout(self.elecTab)
self.gridLayout_3.setObjectName("gridLayout_3")
self.setvoltagesButton = QtWidgets.QPushButton(parent=self.elecTab)
self.setvoltagesButton.setObjectName("setvoltagesButton")
self.gridLayout_3.addWidget(self.setvoltagesButton, 3, 0, 1, 2)
self.label_4 = QtWidgets.QLabel(parent=self.elecTab)
self.label_4.setObjectName("label_4")
self.gridLayout_3.addWidget(self.label_4, 5, 0, 1, 1)
self.stopfrequencyBox = QtWidgets.QDoubleSpinBox(parent=self.elecTab)
self.stopfrequencyBox.setObjectName("stopfrequencyBox")
self.gridLayout_3.addWidget(self.stopfrequencyBox, 7, 1, 1, 1)
self.label_9 = QtWidgets.QLabel(parent=self.elecTab)
font = QtGui.QFont()
font.setBold(True)
self.label_9.setFont(font)
self.label_9.setObjectName("label_9")
self.gridLayout_3.addWidget(self.label_9, 0, 0, 1, 1)
self.label_14 = QtWidgets.QLabel(parent=self.elecTab)
self.label_14.setObjectName("label_14")
self.gridLayout_3.addWidget(self.label_14, 8, 0, 1, 1)
self.startfrequencyBox = QtWidgets.QDoubleSpinBox(parent=self.elecTab)
self.startfrequencyBox.setObjectName("startfrequencyBox")
self.gridLayout_3.addWidget(self.startfrequencyBox, 6, 1, 1, 1)
self.label_2 = QtWidgets.QLabel(parent=self.elecTab)
self.label_2.setObjectName("label_2")
self.gridLayout_3.addWidget(self.label_2, 1, 0, 1, 1)
self.tuningBox = QtWidgets.QDoubleSpinBox(parent=self.elecTab)
self.tuningBox.setObjectName("tuningBox")
self.gridLayout_3.addWidget(self.tuningBox, 1, 1, 1, 1)
self.frequencystepBox = QtWidgets.QDoubleSpinBox(parent=self.elecTab)
self.frequencystepBox.setObjectName("frequencystepBox")
self.gridLayout_3.addWidget(self.frequencystepBox, 8, 1, 1, 1)
self.label_11 = QtWidgets.QLabel(parent=self.elecTab)
font = QtGui.QFont()
font.setBold(True)
self.label_11.setFont(font)
self.label_11.setObjectName("label_11")
self.gridLayout_3.addWidget(self.label_11, 4, 0, 1, 1)
self.resolutionBox = QtWidgets.QDoubleSpinBox(parent=self.elecTab)
self.resolutionBox.setObjectName("resolutionBox")
self.gridLayout_3.addWidget(self.resolutionBox, 5, 1, 1, 1)
self.matchingBox = QtWidgets.QDoubleSpinBox(parent=self.elecTab)
self.matchingBox.setObjectName("matchingBox")
self.gridLayout_3.addWidget(self.matchingBox, 2, 1, 1, 1)
self.label_4 = QtWidgets.QLabel(parent=self.elecTab)
self.label_4.setObjectName("label_4")
self.gridLayout_3.addWidget(self.label_4, 5, 0, 1, 1)
self.startfrequencyBox = QtWidgets.QDoubleSpinBox(parent=self.elecTab)
self.startfrequencyBox.setObjectName("startfrequencyBox")
self.gridLayout_3.addWidget(self.startfrequencyBox, 6, 1, 1, 1)
self.generateLUTButton = QtWidgets.QPushButton(parent=self.elecTab)
self.generateLUTButton.setObjectName("generateLUTButton")
self.gridLayout_3.addWidget(self.generateLUTButton, 9, 0, 1, 2)
self.frequencystepBox = QtWidgets.QDoubleSpinBox(parent=self.elecTab)
self.frequencystepBox.setObjectName("frequencystepBox")
self.gridLayout_3.addWidget(self.frequencystepBox, 8, 1, 1, 1)
self.label_3 = QtWidgets.QLabel(parent=self.elecTab)
self.label_3.setObjectName("label_3")
self.gridLayout_3.addWidget(self.label_3, 2, 0, 1, 1)
self.label_13 = QtWidgets.QLabel(parent=self.elecTab)
self.label_13.setObjectName("label_13")
self.gridLayout_3.addWidget(self.label_13, 7, 0, 1, 1)
self.label_2 = QtWidgets.QLabel(parent=self.elecTab)
self.label_2.setObjectName("label_2")
self.gridLayout_3.addWidget(self.label_2, 1, 0, 1, 1)
self.label_12 = QtWidgets.QLabel(parent=self.elecTab)
self.label_12.setObjectName("label_12")
self.gridLayout_3.addWidget(self.label_12, 6, 0, 1, 1)
self.tuningBox = QtWidgets.QDoubleSpinBox(parent=self.elecTab)
self.tuningBox.setObjectName("tuningBox")
self.gridLayout_3.addWidget(self.tuningBox, 1, 1, 1, 1)
self.resolutionBox = QtWidgets.QDoubleSpinBox(parent=self.elecTab)
self.resolutionBox.setObjectName("resolutionBox")
self.gridLayout_3.addWidget(self.resolutionBox, 5, 1, 1, 1)
self.label_9 = QtWidgets.QLabel(parent=self.elecTab)
font = QtGui.QFont()
font.setBold(True)
self.label_9.setFont(font)
self.label_9.setObjectName("label_9")
self.gridLayout_3.addWidget(self.label_9, 0, 0, 1, 1)
self.label_15 = QtWidgets.QLabel(parent=self.elecTab)
self.label_15.setObjectName("label_15")
self.gridLayout_3.addWidget(self.label_15, 11, 0, 1, 1)
self.viewLUTButton = QtWidgets.QPushButton(parent=self.elecTab)
self.viewLUTButton.setObjectName("viewLUTButton")
self.gridLayout_3.addWidget(self.viewLUTButton, 10, 0, 1, 2)
self.setvoltagesButton = QtWidgets.QPushButton(parent=self.elecTab)
self.setvoltagesButton.setObjectName("setvoltagesButton")
self.gridLayout_3.addWidget(self.setvoltagesButton, 3, 0, 1, 2)
self.label_3 = QtWidgets.QLabel(parent=self.elecTab)
self.label_3.setObjectName("label_3")
self.gridLayout_3.addWidget(self.label_3, 2, 0, 1, 1)
self.label_12 = QtWidgets.QLabel(parent=self.elecTab)
self.label_12.setObjectName("label_12")
self.gridLayout_3.addWidget(self.label_12, 6, 0, 1, 1)
self.matchingBox = QtWidgets.QDoubleSpinBox(parent=self.elecTab)
self.matchingBox.setObjectName("matchingBox")
self.gridLayout_3.addWidget(self.matchingBox, 2, 1, 1, 1)
self.label_14 = QtWidgets.QLabel(parent=self.elecTab)
self.label_14.setObjectName("label_14")
self.gridLayout_3.addWidget(self.label_14, 8, 0, 1, 1)
self.switchpreampButton = QtWidgets.QPushButton(parent=self.elecTab)
self.switchpreampButton.setObjectName("switchpreampButton")
self.gridLayout_3.addWidget(self.switchpreampButton, 12, 0, 1, 1)
self.switchATMButton = QtWidgets.QPushButton(parent=self.elecTab)
self.switchATMButton.setObjectName("switchATMButton")
self.gridLayout_3.addWidget(self.switchATMButton, 12, 1, 1, 1)
self.typeTab.addTab(self.elecTab, "")
self.verticalLayout_2.addWidget(self.typeTab)
self.titlefrequencyLabel = QtWidgets.QLabel(parent=Form)
@ -194,7 +203,7 @@ class Ui_Form(object):
self.horizontalLayout_2.setStretch(1, 1)
self.retranslateUi(Form)
self.typeTab.setCurrentIndex(1)
self.typeTab.setCurrentIndex(0)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
@ -206,19 +215,22 @@ class Ui_Form(object):
self.label_10.setText(_translate("Form", "Connected to:"))
self.connectButton.setText(_translate("Form", "Connect"))
self.titletypeLabel.setText(_translate("Form", "T&M Type:"))
self.pushButton.setText(_translate("Form", "Homing"))
self.homingButton.setText(_translate("Form", "Homing"))
self.typeTab.setTabText(self.typeTab.indexOf(self.mechTab), _translate("Form", "Mechanical"))
self.setvoltagesButton.setText(_translate("Form", "Set Voltages"))
self.label_9.setText(_translate("Form", "Set Voltages:"))
self.label_14.setText(_translate("Form", "Frequency Step (MHz)"))
self.label_11.setText(_translate("Form", "Generate LUT:"))
self.label_4.setText(_translate("Form", "Voltage Resolution"))
self.generateLUTButton.setText(_translate("Form", "Start Voltage Sweep"))
self.label_3.setText(_translate("Form", "Voltage Matching"))
self.label_13.setText(_translate("Form", "Stop Frequency (MHz)"))
self.label_2.setText(_translate("Form", "Voltage Tuning"))
self.label_12.setText(_translate("Form", "Start Frequency (MHz)"))
self.label_11.setText(_translate("Form", "Generate LUT:"))
self.generateLUTButton.setText(_translate("Form", "Start Voltage Sweep"))
self.label_13.setText(_translate("Form", "Stop Frequency (MHz)"))
self.label_9.setText(_translate("Form", "Set Voltages:"))
self.label_15.setText(_translate("Form", "RF Switch:"))
self.viewLUTButton.setText(_translate("Form", "View LUT"))
self.setvoltagesButton.setText(_translate("Form", "Set Voltages"))
self.label_3.setText(_translate("Form", "Voltage Matching"))
self.label_12.setText(_translate("Form", "Start Frequency (MHz)"))
self.label_14.setText(_translate("Form", "Frequency Step (MHz)"))
self.switchpreampButton.setText(_translate("Form", "Preamplifier"))
self.switchATMButton.setText(_translate("Form", "ATM"))
self.typeTab.setTabText(self.typeTab.indexOf(self.elecTab), _translate("Form", "Electrical"))
self.titlefrequencyLabel.setText(_translate("Form", "Frequency Sweep:"))
self.label_8.setText(_translate("Form", "MHz"))