diff --git a/src/nqrduck_autotm/controller.py b/src/nqrduck_autotm/controller.py
index 288d714..35b5bca 100644
--- a/src/nqrduck_autotm/controller.py
+++ b/src/nqrduck_autotm/controller.py
@@ -273,4 +273,42 @@ class AutoTMController(ModuleController):
data = json.load(f)
self.module.model.short_calibration = S11Data.from_json(data["short"])
self.module.model.open_calibration = S11Data.from_json(data["open"])
- self.module.model.load_calibration = S11Data.from_json(data["load"])
\ No newline at end of file
+ self.module.model.load_calibration = S11Data.from_json(data["load"])
+
+ def set_voltages(self, tuning_voltage : str, matching_voltage : str) -> None:
+ """This method is called when the set voltages button is pressed.
+ It writes the specified tuning and matching voltage to the serial connection.
+
+ Args:
+ tuning_voltage (str): The tuning voltage in V.
+ matching_voltage (str): The matching voltage in V.
+ """
+ logger.debug("Setting voltages")
+ MAX_VOLTAGE = 5 # V
+ try:
+ tuning_voltage = float(tuning_voltage)
+ matching_voltage = float(matching_voltage)
+ except ValueError:
+ error = "Could not set voltages. Tuning and matching voltage must be floats"
+ logger.error(error)
+ self.module.view.add_info_text(error)
+ return
+
+ if tuning_voltage < 0 or matching_voltage < 0:
+ error = "Could not set voltages. Tuning and matching voltage must be positive"
+ logger.error(error)
+ self.module.view.add_info_text(error)
+ return
+
+ if tuning_voltage > MAX_VOLTAGE or matching_voltage > MAX_VOLTAGE:
+ error = "Could not set voltages. Tuning and matching voltage must be between 0 and 5 V"
+ logger.error(error)
+ self.module.view.add_info_text(error)
+ return
+
+ logger.debug("Setting tuning voltage to %s V and matching voltage to %s V", 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.")
diff --git a/src/nqrduck_autotm/resources/autotm_widget.ui b/src/nqrduck_autotm/resources/autotm_widget.ui
index 16d3e3c..4e02f66 100644
--- a/src/nqrduck_autotm/resources/autotm_widget.ui
+++ b/src/nqrduck_autotm/resources/autotm_widget.ui
@@ -7,7 +7,7 @@
0
0
1280
- 645
+ 705
@@ -118,7 +118,7 @@
-
-
+
Set Voltages
diff --git a/src/nqrduck_autotm/view.py b/src/nqrduck_autotm/view.py
index 8643bf2..280cb69 100644
--- a/src/nqrduck_autotm/view.py
+++ b/src/nqrduck_autotm/view.py
@@ -44,6 +44,12 @@ class AutoTMView(ModuleView):
self._ui_form.stopEdit.text()
))
+ # On clicking of the setvoltagesButton call the set_voltages method
+ self._ui_form.setvoltagesButton.clicked.connect(lambda: self.module.controller.set_voltages(
+ self._ui_form.tuningBox.text(),
+ self._ui_form.matchingBox.text()
+ ))
+
# On clicking of the calibration button call the on_calibration_button_clicked method
self._ui_form.calibrationButton.clicked.connect(self.on_calibration_button_clicked)
@@ -177,8 +183,6 @@ class AutoTMView(ModuleView):
phase_ax.set_ylim(-180, 180)
phase_ax.invert_yaxis()
-
-
magnitude_ax.set_xlabel("Frequency (MHz)")
magnitude_ax.set_ylabel("S11 (dB)")
magnitude_ax.set_title("S11")
diff --git a/src/nqrduck_autotm/widget.py b/src/nqrduck_autotm/widget.py
index 13fcc0a..0bd74f6 100644
--- a/src/nqrduck_autotm/widget.py
+++ b/src/nqrduck_autotm/widget.py
@@ -12,7 +12,7 @@ from PyQt6 import QtCore, QtGui, QtWidgets
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
- Form.resize(1280, 645)
+ Form.resize(1280, 705)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Preferred, QtWidgets.QSizePolicy.Policy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
@@ -75,9 +75,9 @@ class Ui_Form(object):
self.matchingBox = QtWidgets.QDoubleSpinBox(parent=self.elecTab)
self.matchingBox.setObjectName("matchingBox")
self.gridLayout_3.addWidget(self.matchingBox, 1, 1, 1, 1)
- self.pushButton_2 = QtWidgets.QPushButton(parent=self.elecTab)
- self.pushButton_2.setObjectName("pushButton_2")
- self.gridLayout_3.addWidget(self.pushButton_2, 2, 0, 1, 2)
+ self.setvoltagesButton = QtWidgets.QPushButton(parent=self.elecTab)
+ self.setvoltagesButton.setObjectName("setvoltagesButton")
+ self.gridLayout_3.addWidget(self.setvoltagesButton, 2, 0, 1, 2)
self.tuningBox = QtWidgets.QDoubleSpinBox(parent=self.elecTab)
self.tuningBox.setObjectName("tuningBox")
self.gridLayout_3.addWidget(self.tuningBox, 0, 1, 1, 1)
@@ -176,7 +176,7 @@ class Ui_Form(object):
self.titletypeLabel.setText(_translate("Form", "T&M Type:"))
self.pushButton.setText(_translate("Form", "Homing"))
self.typeTab.setTabText(self.typeTab.indexOf(self.mechTab), _translate("Form", "Mechanical"))
- self.pushButton_2.setText(_translate("Form", "Set Voltages"))
+ self.setvoltagesButton.setText(_translate("Form", "Set Voltages"))
self.label_3.setText(_translate("Form", "Voltage Matching"))
self.label_2.setText(_translate("Form", "Voltage Tuning"))
self.label_4.setText(_translate("Form", "Voltage Resolution"))