[ui] adding recording button, which writes to a nix file
This commit is contained in:
parent
042826721b
commit
1b889312ce
@ -13,7 +13,6 @@ from PyQt6.QtWidgets import (
|
||||
QStatusBar,
|
||||
)
|
||||
|
||||
from pyqtgraph.Qt.QtCore import QThread
|
||||
import uldaq
|
||||
import nixio as nix
|
||||
import pyqtgraph as pg
|
||||
@ -21,6 +20,7 @@ import numpy as np
|
||||
|
||||
|
||||
from pyrelacs.dataio.daq_producer import DaqProducer
|
||||
from pyrelacs.dataio.nix_writer import NixWriter
|
||||
from pyrelacs.dataio.sin_producer import SinProducer
|
||||
from pyrelacs.worker import Worker
|
||||
from pyrelacs.repros.repros import Repro
|
||||
@ -51,13 +51,14 @@ class PyRelacs(QMainWindow):
|
||||
|
||||
self.figure = pg.GraphicsLayoutWidget()
|
||||
|
||||
filename = path.joinpath(path.cwd(), "data.nix")
|
||||
if filename.exists():
|
||||
self.nix_file = nix.File.open(str(filename), nix.FileMode.ReadOnly)
|
||||
filename = path.joinpath(path.cwd(), "calibration.nix")
|
||||
self.nix_file = nix.File.open(str(filename), nix.FileMode.Overwrite)
|
||||
|
||||
self.calibration_plot = CalibrationPlot(self.figure, self.nix_file)
|
||||
# filename = path.joinpath(path.cwd(), "data.nix")
|
||||
# if filename.exists():
|
||||
# self.nix_file = nix.File.open(str(filename), nix.FileMode.ReadOnly)
|
||||
# filename = path.joinpath(path.cwd(), "calibration.nix")
|
||||
# self.nix_file = nix.File.open(str(filename), nix.FileMode.Overwrite)
|
||||
#
|
||||
# self.calibration_plot = CalibrationPlot(self.figure, self.nix_file)
|
||||
# self.nix_file.close()
|
||||
|
||||
self.threadpool = QThreadPool()
|
||||
self.repros = Repro()
|
||||
@ -95,12 +96,14 @@ class PyRelacs(QMainWindow):
|
||||
end = time.time()
|
||||
log.debug(f"Connection to DAQ took {end - start}")
|
||||
|
||||
if hasattr(uldaq, "daq_device"):
|
||||
if hasattr(PyRelacs, "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.sinus_producer = SinProducer(self.buffer)
|
||||
|
||||
self.nix_writer = NixWriter(self.buffer)
|
||||
|
||||
def create_actions(self):
|
||||
self._rlx_exitaction = QAction(QIcon(":/icons/exit.png"), "Exit", self)
|
||||
@ -127,12 +130,12 @@ class PyRelacs(QMainWindow):
|
||||
# self._daq_connectaction.setShortcut(QKeySequence("Alt+d"))
|
||||
self._daq_disconnectaction.triggered.connect(self.disconnect_dac)
|
||||
|
||||
self._daq_calibaction = QAction(
|
||||
QIcon(":/icons/calibration.png"), "Plot calibration", self
|
||||
)
|
||||
self._daq_calibaction.setStatusTip("Calibrate the attenuator device")
|
||||
# self._daq_calibaction.setShortcut(QKeySequence("Alt+d"))
|
||||
self._daq_calibaction.triggered.connect(self.calibration_plot.plot)
|
||||
# self._daq_calibaction = QAction(
|
||||
# QIcon(":/icons/calibration.png"), "Plot calibration", self
|
||||
# )
|
||||
# self._daq_calibaction.setStatusTip("Calibrate the attenuator device")
|
||||
# # self._daq_calibaction.setShortcut(QKeySequence("Alt+d"))
|
||||
# self._daq_calibaction.triggered.connect(self.calibration_plot.plot)
|
||||
|
||||
self._run_action = QAction(QIcon(":/icons/record.png"), "Run", self)
|
||||
self._run_action.triggered.connect(self.run_daq)
|
||||
@ -143,9 +146,12 @@ class PyRelacs(QMainWindow):
|
||||
self._stop_recording = QAction(QIcon(":/icons/stop.png"), "Stop", self)
|
||||
self._stop_recording.triggered.connect(self.stop_recording)
|
||||
|
||||
self._refresh = QAction("Recenter", self)
|
||||
self._refresh.triggered.connect(self.recenter_continously_plot)
|
||||
self._refresh.setShortcut(QKeySequence("Alt+r"))
|
||||
self._recenter_plot = QAction("Recenter", self)
|
||||
self._recenter_plot.triggered.connect(self.recenter_continously_plot)
|
||||
self._recenter_plot.setShortcut(QKeySequence("Alt+r"))
|
||||
|
||||
self._record = QAction(QIcon(":/icons/record.png"), "Record", self)
|
||||
self._record.triggered.connect(self.record)
|
||||
|
||||
self.create_menu()
|
||||
|
||||
@ -164,7 +170,7 @@ class PyRelacs(QMainWindow):
|
||||
device_menu.addAction(self._daq_connectaction)
|
||||
device_menu.addAction(self._daq_disconnectaction)
|
||||
device_menu.addSeparator()
|
||||
device_menu.addAction(self._daq_calibaction)
|
||||
# device_menu.addAction(self._daq_calibaction)
|
||||
device_menu.addAction(self._run_action)
|
||||
|
||||
if help_menu is not None:
|
||||
@ -185,11 +191,13 @@ class PyRelacs(QMainWindow):
|
||||
daq_toolbar = QToolBar("DAQ")
|
||||
daq_toolbar.addAction(self._daq_connectaction)
|
||||
daq_toolbar.addAction(self._daq_disconnectaction)
|
||||
daq_toolbar.addAction(self._daq_calibaction)
|
||||
# daq_toolbar.addAction(self._daq_calibaction)
|
||||
daq_toolbar.addAction(self._run_action)
|
||||
daq_toolbar.addAction(self._run_sinus_action)
|
||||
daq_toolbar.addAction(self._stop_recording)
|
||||
# daq_toolbar.addAction(self._refresh)
|
||||
daq_toolbar.addAction(self._recenter_plot)
|
||||
daq_toolbar.addSeparator()
|
||||
daq_toolbar.addAction(self._record)
|
||||
self.addToolBar(Qt.ToolBarArea.TopToolBarArea, daq_toolbar)
|
||||
|
||||
repro_toolbar = QToolBar("Repros")
|
||||
@ -223,7 +231,7 @@ class PyRelacs(QMainWindow):
|
||||
self.continously_plot.plot()
|
||||
|
||||
def run_sinus(self):
|
||||
sinus_pro = Worker(self.sin_producer.produce_sin)
|
||||
sinus_pro = Worker(self.sinus_producer.produce_sin)
|
||||
sinus_pro.signals.result.connect(self.print_output)
|
||||
sinus_pro.signals.finished.connect(self.thread_complete)
|
||||
sinus_pro.signals.progress.connect(self.progress_fn)
|
||||
@ -231,12 +239,27 @@ class PyRelacs(QMainWindow):
|
||||
|
||||
self.continously_plot.plot()
|
||||
|
||||
def record(self):
|
||||
nix_writer = Worker(self.nix_writer.write_nix)
|
||||
nix_writer.signals.result.connect(self.print_output)
|
||||
nix_writer.signals.finished.connect(self.thread_complete)
|
||||
nix_writer.signals.progress.connect(self.progress_fn)
|
||||
self.threadpool.start(nix_writer)
|
||||
|
||||
def stop_recording(self):
|
||||
self.add_to_textfield("Stopping the recording")
|
||||
if hasattr(PyRelacs, "sin_producer"):
|
||||
self.sin_producer.stop_request()
|
||||
self.continously_plot.stop_plotting()
|
||||
if hasattr(uldaq, "daq_device"):
|
||||
self.nix_writer.stop_writing()
|
||||
|
||||
log.debug("Stopping acquisiton")
|
||||
try:
|
||||
self.sinus_producer.stop_request()
|
||||
log.debug("Stopping Sinus")
|
||||
except AttributeError:
|
||||
log.debug("Did not generate Sinus")
|
||||
|
||||
if hasattr(PyRelacs, "daq_device"):
|
||||
log.debug("Stopping DAQ")
|
||||
self.daq_producer.stop_aquisition()
|
||||
|
||||
def connect_dac(self):
|
||||
@ -247,8 +270,8 @@ class PyRelacs(QMainWindow):
|
||||
self.daq_device.connect()
|
||||
log.debug("connected")
|
||||
except IndexError:
|
||||
log.error("DAQ is not connected")
|
||||
log.error("Please connect a DAQ device to the system")
|
||||
log.info("DAQ is not connected")
|
||||
log.info("Please connect a DAQ device to the system")
|
||||
|
||||
def disconnect_dac(self):
|
||||
try:
|
||||
@ -274,6 +297,7 @@ class PyRelacs(QMainWindow):
|
||||
self.stop_recording()
|
||||
self.add_to_textfield("exiting")
|
||||
self.disconnect_dac()
|
||||
log.info("closing GUI")
|
||||
self.close()
|
||||
|
||||
def on_about(self, e):
|
||||
|
Loading…
Reference in New Issue
Block a user