diff --git a/pyrelacs/ui/mainwindow.py b/pyrelacs/ui/mainwindow.py index 8f635b1..351c7a0 100644 --- a/pyrelacs/ui/mainwindow.py +++ b/pyrelacs/ui/mainwindow.py @@ -1,5 +1,7 @@ import time from pathlib import Path as path +from datetime import datetime +from dataclasses import asdict from PyQt6.QtGui import QAction, QIcon, QKeySequence from PyQt6.QtCore import Qt, QSize, QThreadPool, QMutex @@ -13,9 +15,8 @@ from PyQt6.QtWidgets import ( QStatusBar, ) -from pyqtgraph.Qt.QtCore import QThread -import uldaq -import nixio as nix + +import nixio import pyqtgraph as pg import quantities as pq @@ -110,6 +111,7 @@ class PyRelacs(QMainWindow): self.sinus_producer = SinProducer(self.buffer) self.nix_writer = NixWriter(self.buffer) + self.create_nix_file(f"{_root}/test.nix", self.config.metadata) def create_actions(self): self._rlx_exitaction = QAction(QIcon(":/icons/exit.png"), "Exit", self) @@ -222,6 +224,22 @@ class PyRelacs(QMainWindow): repro_toolbar.addAction(repro_action) self.addToolBar(Qt.ToolBarArea.BottomToolBarArea, repro_toolbar) + def create_nix_file(self, file_path, metadata): + self.nix_file = nixio.File.open( + path=f"{file_path}", mode=nixio.FileMode.Overwrite + ) + self.block = self.nix_file.create_block("recording", "testfile") + self.section = self.nix_file.create_section("metadata", "config.yaml") + for key, value in asdict(metadata).items(): + self.section[key] = value + + self.data_array_analog1 = self.block.create_data_array( + "Analog1", "ndarray", shape=(1000,), dtype=nixio.DataType.Double + ) + self.data_array_analog2 = self.block.create_data_array( + "Analog2", "ndarray", shape=(1000,), dtype=nixio.DataType.Double + ) + def recenter_continously_plot(self): self.continously_plot.refresh() @@ -251,12 +269,33 @@ class PyRelacs(QMainWindow): self.continously_plot.plot() def record(self): - nix_writer = Worker(self.nix_writer.write_nix) + self.create_nix_file("test.nix", self.config.metadata) + log.debug("Created nix file") + + nix_writer = Worker( + self.nix_writer.write_nix, + data_array=self.data_array_analog1, + mutex=self.mutex, + channel=0, + chunk_size=1000, + ) 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) + nix_writer2 = Worker( + self.nix_writer.write_nix, + data_array=self.data_array_analog2, + mutex=self.mutex, + channel=0, + chunk_size=1000, + ) + nix_writer2.signals.result.connect(self.print_output) + nix_writer2.signals.finished.connect(self.thread_complete) + nix_writer2.signals.progress.connect(self.progress_fn) + self.threadpool.start(nix_writer2) + def stop_recording(self): self.add_to_textfield("Stopping the recording") self.continously_plot.stop_plotting() @@ -272,6 +311,8 @@ class PyRelacs(QMainWindow): if hasattr(PyRelacs, "daq_device"): log.debug("Stopping DAQ") self.daq_producer.stop_aquisition() + embed() + exit() def run_repro(self, n, fn): self.text.appendPlainText(f"started Repro {n}, {fn}")