[ui] adding checks, refactoring
This commit is contained in:
parent
57d3a83243
commit
ff2d8ebb50
@ -87,11 +87,20 @@ class PyRelacs(QMainWindow):
|
|||||||
self.buffer = CircBuffer(
|
self.buffer = CircBuffer(
|
||||||
size=BUFFERSIZE, samplerate=SAMPLERATE, mutex=self.mutex
|
size=BUFFERSIZE, samplerate=SAMPLERATE, mutex=self.mutex
|
||||||
)
|
)
|
||||||
# self.connect_dac()
|
self.continously_plot = Continously(self.figure, self.buffer)
|
||||||
|
self.continously_plot.plot()
|
||||||
|
|
||||||
|
start = time.time()
|
||||||
|
self.connect_dac()
|
||||||
|
end = time.time()
|
||||||
|
log.debug(f"Connection to DAQ took {end - start}")
|
||||||
|
|
||||||
# self.daq_producer = DaqProducer(self.buffer, self.daq_device, [1, 1])
|
if hasattr(uldaq, "daq_device"):
|
||||||
|
log.debug("Creating Daq Generator")
|
||||||
|
self.daq_producer = DaqProducer(self.buffer, self.daq_device, [1, 1])
|
||||||
|
else:
|
||||||
|
log.debug("Creating Sinus Generator")
|
||||||
self.sin_producer = SinProducer(self.buffer)
|
self.sin_producer = SinProducer(self.buffer)
|
||||||
self.continously_plot = Continously(self.figure, self.buffer)
|
|
||||||
|
|
||||||
def create_actions(self):
|
def create_actions(self):
|
||||||
self._rlx_exitaction = QAction(QIcon(":/icons/exit.png"), "Exit", self)
|
self._rlx_exitaction = QAction(QIcon(":/icons/exit.png"), "Exit", self)
|
||||||
@ -134,8 +143,8 @@ class PyRelacs(QMainWindow):
|
|||||||
self._stop_recording = QAction(QIcon(":/icons/stop.png"), "Stop", self)
|
self._stop_recording = QAction(QIcon(":/icons/stop.png"), "Stop", self)
|
||||||
self._stop_recording.triggered.connect(self.stop_recording)
|
self._stop_recording.triggered.connect(self.stop_recording)
|
||||||
|
|
||||||
self._refresh = QAction("Refresh", self)
|
self._refresh = QAction("Recenter", self)
|
||||||
self._refresh.triggered.connect(self.refresh_plot)
|
self._refresh.triggered.connect(self.recenter_continously_plot)
|
||||||
self._refresh.setShortcut(QKeySequence("Alt+r"))
|
self._refresh.setShortcut(QKeySequence("Alt+r"))
|
||||||
|
|
||||||
self.create_menu()
|
self.create_menu()
|
||||||
@ -180,7 +189,7 @@ class PyRelacs(QMainWindow):
|
|||||||
daq_toolbar.addAction(self._run_action)
|
daq_toolbar.addAction(self._run_action)
|
||||||
daq_toolbar.addAction(self._run_sinus_action)
|
daq_toolbar.addAction(self._run_sinus_action)
|
||||||
daq_toolbar.addAction(self._stop_recording)
|
daq_toolbar.addAction(self._stop_recording)
|
||||||
daq_toolbar.addAction(self._refresh)
|
# daq_toolbar.addAction(self._refresh)
|
||||||
self.addToolBar(Qt.ToolBarArea.TopToolBarArea, daq_toolbar)
|
self.addToolBar(Qt.ToolBarArea.TopToolBarArea, daq_toolbar)
|
||||||
|
|
||||||
repro_toolbar = QToolBar("Repros")
|
repro_toolbar = QToolBar("Repros")
|
||||||
@ -194,29 +203,24 @@ class PyRelacs(QMainWindow):
|
|||||||
repro_toolbar.addAction(repro_action)
|
repro_toolbar.addAction(repro_action)
|
||||||
self.addToolBar(Qt.ToolBarArea.BottomToolBarArea, repro_toolbar)
|
self.addToolBar(Qt.ToolBarArea.BottomToolBarArea, repro_toolbar)
|
||||||
|
|
||||||
def refresh_plot(self):
|
def recenter_continously_plot(self):
|
||||||
self.continously_plot.refresh()
|
self.continously_plot.refresh()
|
||||||
|
|
||||||
def plot_continously(self):
|
def plot_continously(self):
|
||||||
plot_daq = Worker(self.continously_plot.plot_daq)
|
plot_con = Worker(self.continously_plot.plot)
|
||||||
plot_daq.signals.result.connect(self.print_output)
|
plot_con.signals.result.connect(self.print_output)
|
||||||
plot_daq.signals.finished.connect(self.thread_complete)
|
plot_con.signals.finished.connect(self.thread_complete)
|
||||||
plot_daq.signals.progress.connect(self.progress_fn)
|
plot_con.signals.progress.connect(self.progress_fn)
|
||||||
self.threadpool.start(plot_daq)
|
self.threadpool.start(plot_con)
|
||||||
|
|
||||||
def run_daq(self):
|
def run_daq(self):
|
||||||
read_daq = Worker(self.daq_producer.read_analog_continously)
|
read_daq = Worker(self.daq_producer.read_analog_continously)
|
||||||
read_daq.signals.result.connect(self.print_output)
|
read_daq.signals.result.connect(self.print_output)
|
||||||
read_daq.signals.finished.connect(self.thread_complete)
|
read_daq.signals.finished.connect(self.thread_complete)
|
||||||
read_daq.signals.progress.connect(self.progress_fn)
|
read_daq.signals.progress.connect(self.progress_fn)
|
||||||
# plot_daq = Worker(self.continously_plot.plot_daq)
|
|
||||||
# plot_daq.signals.result.connect(self.print_output)
|
|
||||||
# plot_daq.signals.finished.connect(self.thread_complete)
|
|
||||||
# plot_daq.signals.progress.connect(self.progress_fn)
|
|
||||||
self.threadpool.start(read_daq)
|
self.threadpool.start(read_daq)
|
||||||
time.sleep(0.5)
|
|
||||||
self.continously_plot.plot_daq()
|
self.continously_plot.plot()
|
||||||
# self.threadpool.start(plot_daq)
|
|
||||||
|
|
||||||
def run_sinus(self):
|
def run_sinus(self):
|
||||||
sinus_pro = Worker(self.sin_producer.produce_sin)
|
sinus_pro = Worker(self.sin_producer.produce_sin)
|
||||||
@ -225,19 +229,15 @@ class PyRelacs(QMainWindow):
|
|||||||
sinus_pro.signals.progress.connect(self.progress_fn)
|
sinus_pro.signals.progress.connect(self.progress_fn)
|
||||||
self.threadpool.start(sinus_pro)
|
self.threadpool.start(sinus_pro)
|
||||||
|
|
||||||
# plot_daq = Worker(self.continously_plot.plot_daq, self.timer)
|
self.continously_plot.plot()
|
||||||
# plot_daq.signals.result.connect(self.print_output)
|
|
||||||
# plot_daq.signals.finished.connect(self.thread_complete)
|
|
||||||
# plot_daq.signals.progress.connect(self.progress_fn)
|
|
||||||
# self.threadpool.start(plot_daq)
|
|
||||||
|
|
||||||
self.continously_plot.plot_daq()
|
|
||||||
|
|
||||||
def stop_recording(self):
|
def stop_recording(self):
|
||||||
self.add_to_textfield("pressed")
|
self.add_to_textfield("Stopping the recording")
|
||||||
# self._stop_recording.setEnabled(False)
|
if hasattr(PyRelacs, "sin_producer"):
|
||||||
self.sin_producer.stop_request()
|
self.sin_producer.stop_request()
|
||||||
self.continously_plot.stop_plotting()
|
self.continously_plot.stop_plotting()
|
||||||
|
if hasattr(uldaq, "daq_device"):
|
||||||
|
self.daq_producer.stop_aquisition()
|
||||||
|
|
||||||
def connect_dac(self):
|
def connect_dac(self):
|
||||||
devices = uldaq.get_daq_device_inventory(uldaq.InterfaceType.USB)
|
devices = uldaq.get_daq_device_inventory(uldaq.InterfaceType.USB)
|
||||||
@ -250,13 +250,6 @@ class PyRelacs(QMainWindow):
|
|||||||
log.error("DAQ is not connected")
|
log.error("DAQ is not connected")
|
||||||
log.error("Please connect a DAQ device to the system")
|
log.error("Please connect a DAQ device to the system")
|
||||||
|
|
||||||
if hasattr(PyRelacs, "daq_device"):
|
|
||||||
try:
|
|
||||||
self.daq_device.connect()
|
|
||||||
log.debug("Connected")
|
|
||||||
except uldaq.ul_exception.ULException as e:
|
|
||||||
log.error(f"Could not Connect to DAQ: {e}")
|
|
||||||
|
|
||||||
def disconnect_dac(self):
|
def disconnect_dac(self):
|
||||||
try:
|
try:
|
||||||
self.daq_device.disconnect()
|
self.daq_device.disconnect()
|
||||||
|
Loading…
Reference in New Issue
Block a user