From 2c963c50855c5a86279784803a8bfa2c865deb07 Mon Sep 17 00:00:00 2001 From: wendtalexander Date: Tue, 17 Sep 2024 11:18:14 +0200 Subject: [PATCH] adding pyqt6 application --- pyrelacs/app.py | 69 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 pyrelacs/app.py diff --git a/pyrelacs/app.py b/pyrelacs/app.py new file mode 100644 index 0000000..4f8a37e --- /dev/null +++ b/pyrelacs/app.py @@ -0,0 +1,69 @@ +import sys +from PyQt6.QtCore import QSize, Qt +from PyQt6.QtWidgets import QApplication, QGridLayout, QPushButton, QWidget, QMainWindow +import uldaq + +from pyrelacs.util.logging import config_logging + +log = config_logging() + + +class PyRelacs(QMainWindow): + def __init__(self): + super().__init__() + self.setWindowTitle("PyRelacs") + + self.daq_connect_button = QPushButton("Connect to Daq") + self.daq_connect_button.setCheckable(True) + self.daq_connect_button.clicked.connect(self.connect_dac) + + self.daq_disconnect_button = QPushButton("Disconnect to Daq") + self.daq_disconnect_button.setCheckable(True) + self.daq_disconnect_button.clicked.connect(self.disconnect_dac) + + self.send_data_button = QPushButton("Send Sinus") + self.send_data_button.setCheckable(True) + self.send_data_button.clicked.connect(self.send_sinus) + + layout = QGridLayout() + layout.addWidget(self.daq_connect_button, 0, 0) + layout.addWidget(self.daq_disconnect_button, 0, 1) + layout.addWidget(self.send_data_button, 1, 0) + + self.setFixedSize(QSize(400, 300)) + widget = QWidget() + widget.setLayout(layout) + self.setCentralWidget(widget) + + def connect_dac(self): + try: + devices = uldaq.get_daq_device_inventory(uldaq.InterfaceType.USB) + + log.debug(f"Found daq devices {len(devices)}, connecting to the first one") + self.daq_device = uldaq.DaqDevice(devices[0]) + self.daq_device.connect() + log.debug("Connected") + except uldaq.ULException as e: + log.debug(f"DAQ was not connected\n {e}") + self.daq_connect_button.setDisabled(True) + + def disconnect_dac(self): + try: + log.debug(f"{self.daq_device}") + self.daq_device.disconnect() + self.daq_device.release() + log.debug(f"{self.daq_device}") + self.daq_disconnect_button.setDisabled(True) + self.daq_connect_button.setEnabled(True) + except AttributeError: + log.debug("DAQ was not connected") + + def send_sinus(self): + pass + + +if __name__ == "__main__": + app = QApplication(sys.argv) + window = PyRelacs() + window.show() + app.exec()