forked from awendt/pyrelacs
adding pyqt6 application
This commit is contained in:
parent
b0fe6c5723
commit
2c963c5085
69
pyrelacs/app.py
Normal file
69
pyrelacs/app.py
Normal file
@ -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()
|
Loading…
Reference in New Issue
Block a user