forked from awendt/pyrelacs
adding repro toolbar
This commit is contained in:
parent
74007668a9
commit
281640e80c
@ -1,7 +1,20 @@
|
||||
from PyQt6.QtGui import QAction
|
||||
import sys
|
||||
import pathlib
|
||||
|
||||
from PyQt6.QtCore import QSize, Qt
|
||||
from PyQt6.QtWidgets import QApplication, QGridLayout, QPushButton, QWidget, QMainWindow
|
||||
from PyQt6.QtWidgets import (
|
||||
QApplication,
|
||||
QGridLayout,
|
||||
QPushButton,
|
||||
QToolBar,
|
||||
QWidget,
|
||||
QMainWindow,
|
||||
)
|
||||
import tomli
|
||||
import uldaq
|
||||
from IPython import embed
|
||||
import numpy as np
|
||||
|
||||
from pyrelacs.util.logging import config_logging
|
||||
|
||||
@ -13,22 +26,25 @@ class PyRelacs(QMainWindow):
|
||||
super().__init__()
|
||||
self.setWindowTitle("PyRelacs")
|
||||
|
||||
self.daq_connect_button = QPushButton("Connect to Daq")
|
||||
self.daq_connect_button = QPushButton("Connect 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 = QPushButton("Disconnect 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)
|
||||
self.repro_button = QPushButton("Load Repros")
|
||||
self.repro_button.setCheckable(True)
|
||||
self.repro_button.clicked.connect(self.repro)
|
||||
|
||||
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)
|
||||
layout.addWidget(self.repro_button, 1, 0)
|
||||
|
||||
self.toolbar = QToolBar("Repros")
|
||||
self.addToolBar(self.toolbar)
|
||||
|
||||
self.setFixedSize(QSize(400, 300))
|
||||
widget = QWidget()
|
||||
@ -36,15 +52,15 @@ class PyRelacs(QMainWindow):
|
||||
self.setCentralWidget(widget)
|
||||
|
||||
def connect_dac(self):
|
||||
devices = uldaq.get_daq_device_inventory(uldaq.InterfaceType.USB)
|
||||
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])
|
||||
log.debug(f"Found daq devices {len(devices)}, connecting to the first one")
|
||||
self.daq_device.connect()
|
||||
log.debug("Connected")
|
||||
except uldaq.ULException as e:
|
||||
log.debug(f"DAQ was not connected\n {e}")
|
||||
except IndexError:
|
||||
log.debug("DAQ is not connected, closing")
|
||||
QApplication.quit()
|
||||
self.daq_connect_button.setDisabled(True)
|
||||
|
||||
def disconnect_dac(self):
|
||||
@ -58,8 +74,40 @@ class PyRelacs(QMainWindow):
|
||||
except AttributeError:
|
||||
log.debug("DAQ was not connected")
|
||||
|
||||
def send_sinus(self):
|
||||
pass
|
||||
def repro(self):
|
||||
config_path = pathlib.Path(__file__).parent.resolve() / "repro.toml"
|
||||
if not config_path.is_file:
|
||||
log.error("repro.toml not found")
|
||||
QApplication.quit()
|
||||
repors = []
|
||||
|
||||
with open(config_path, mode="rb") as fp:
|
||||
self.config = tomli.load(fp)
|
||||
for r in self.config:
|
||||
repors.append(r)
|
||||
|
||||
individual_repro_button = QAction(f"{repors[0]}", self)
|
||||
individual_repro_button.setStatusTip("Button")
|
||||
individual_repro_button.triggered.connect(self.run_repro)
|
||||
self.toolbar.addAction(individual_repro_button)
|
||||
|
||||
def run_repro(self):
|
||||
log.debug("running repro")
|
||||
time = np.arange(
|
||||
0, self.config["Sinus"]["duration"], 1 / self.config["Sinus"]["fs"]
|
||||
)
|
||||
data = self.config["Sinus"]["amplitude"] * np.sin(
|
||||
2 * np.pi * self.config["Sinus"]["freq"] * time
|
||||
)
|
||||
|
||||
ao_device = self.daq_device.get_ao_device()
|
||||
ao_info = ao_device.get_info()
|
||||
try:
|
||||
err = ao_device.a_out_list(
|
||||
0, 0, [uldaq.Range.BIP2VOLTS], uldaq.AOutListFlag.DEFAULT, data
|
||||
)
|
||||
except uldaq.ULException as e:
|
||||
print(e)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
Loading…
Reference in New Issue
Block a user