Compare commits

...

5 Commits

6 changed files with 94 additions and 64 deletions

19
poetry.lock generated
View File

@ -688,6 +688,21 @@ files = [
[package.dependencies]
ptyprocess = ">=0.5"
[[package]]
name = "pglive"
version = "0.7.6"
description = "Live plot for PyqtGraph"
optional = false
python-versions = "<3.13,>=3.9"
files = [
{file = "pglive-0.7.6-py3-none-any.whl", hash = "sha256:6203e377954725d6602ba5a08055f92bef1688d2236c76cf4e1b35c9bb896ff4"},
{file = "pglive-0.7.6.tar.gz", hash = "sha256:5e3a91a0bb800a8c9c8513a595d742eb0aba5b8b783a6f1bbb51ab7b0d2528ec"},
]
[package.dependencies]
numpy = ">=1.26.0,<2.0.0"
pyqtgraph = ">=0.13.3,<0.14.0"
[[package]]
name = "pillow"
version = "10.4.0"
@ -1179,5 +1194,5 @@ files = [
[metadata]
lock-version = "2.0"
python-versions = "^3.10"
content-hash = "c661a83b9d93748d39d3e4577f20e3b534a35f270231b6f48a9f13498a3658bd"
python-versions = ">=3.10, <3.13"
content-hash = "e5e345e3e4d28ac0e7de7727be130454201be1949be08158e744cdc6089a3f66"

View File

@ -21,7 +21,7 @@ include = [
]
[tool.poetry.dependencies]
python = "^3.10"
python = ">=3.10, <3.13"
uldaq = "^1.2.3"
typer = "^0.12.5"
matplotlib = "^3.9.2"
@ -32,6 +32,7 @@ scipy = "^1.14.1"
nixio = "^1.5.3"
pyqtgraph = "^0.13.7"
pytest = "^8.3.3"
pglive = "^0.7.6"
[tool.poetry.scripts]
pyrelacs = "pyrelacs.app:main"

View File

@ -29,7 +29,7 @@ class CircBuffer:
def channel_count(self):
return self.__channels
def totocount(self, channel: int = 0):
def totalcount(self, channel: int = 0):
return self.__totalcount[channel]
def is_full(self, channel: int = 0):

View File

@ -128,7 +128,7 @@ class DaqProducer:
log.debug(transfer_status.current_index)
log.debug(transfer_status.current_total_count)
log.debug(transfer_status.current_scan_count)
log.debug(self.buffer.totocount())
log.debug(self.buffer.totalcount())
log.debug("Appending last chunk")
if prev_index + chunk_size > len(data_in) - 1:

View File

@ -1,11 +1,10 @@
import time
from pathlib import Path as path
from re import I
from PyQt6.QtGui import QAction, QIcon, QKeySequence
from PyQt6.QtCore import Qt, QSize, QThreadPool, QTimer
from PyQt6.QtCore import Qt, QSize, QThreadPool
from PyQt6.QtWidgets import (
QGridLayout,
QPushButton,
QToolBar,
QWidget,
QMainWindow,
@ -13,6 +12,11 @@ from PyQt6.QtWidgets import (
QMenuBar,
QStatusBar,
)
from pglive.sources.data_connector import DataConnector
from pglive.sources.live_plot import LiveLinePlot
from pglive.sources.live_plot_widget import LivePlotWidget
import uldaq
import nixio as nix
import pyqtgraph as pg
@ -26,6 +30,7 @@ from pyrelacs.dataio.circbuffer import CircBuffer
from pyrelacs.ui.about import AboutDialog
from pyrelacs.ui.plots.calibration import CalibrationPlot
from pyrelacs.ui.plots.continously import Continously
from pyrelacs.util.logging import config_logging
@ -62,7 +67,6 @@ class PyRelacs(QMainWindow):
self.setMenuBar(QMenuBar(self))
self.setStatusBar(QStatusBar(self))
self.create_actions()
self.create_buttons()
self.create_toolbars()
layout = QGridLayout()
@ -73,10 +77,11 @@ class PyRelacs(QMainWindow):
widget.setLayout(layout)
self.setCentralWidget(widget)
self.buffer = CircBuffer(size=1_000_000, samplerate=20)
self.buffer = CircBuffer(size=1_000_000, samplerate=40_000)
self.connect_dac()
self.daq_producer = DaqProducer(self.buffer, self.daq_device, [1, 1])
self.plot_daq()
self.continously_plot = Continously(self.figure, self.buffer)
def create_actions(self):
self._rlx_exitaction = QAction(QIcon(":/icons/exit.png"), "Exit", self)
@ -110,9 +115,12 @@ class PyRelacs(QMainWindow):
# self._daq_calibaction.setShortcut(QKeySequence("Alt+d"))
self._daq_calibaction.triggered.connect(self.calibration_plot.plot)
self._run_action = QAction(QIcon(":/icons/calibration.png"), "Run", self)
self._run_action = QAction(QIcon(":/icons/record.png"), "Run", self)
self._run_action.triggered.connect(self.run_daq)
self._stop_recording = QAction(QIcon(":/icons/record.png"), "Stop", self)
self._stop_recording.triggered.connect(self.stop_recording)
self.create_menu()
def create_menu(self):
@ -153,6 +161,7 @@ class PyRelacs(QMainWindow):
daq_toolbar.addAction(self._daq_disconnectaction)
daq_toolbar.addAction(self._daq_calibaction)
daq_toolbar.addAction(self._run_action)
daq_toolbar.addAction(self._stop_recording)
self.addToolBar(Qt.ToolBarArea.TopToolBarArea, daq_toolbar)
repro_toolbar = QToolBar("Repros")
@ -166,62 +175,30 @@ class PyRelacs(QMainWindow):
repro_toolbar.addAction(repro_action)
self.addToolBar(Qt.ToolBarArea.BottomToolBarArea, repro_toolbar)
def create_buttons(self):
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 Daq")
self.daq_disconnect_button.setCheckable(True)
self.daq_disconnect_button.clicked.connect(self.disconnect_dac)
self.plot_calibration_button = QPushButton("Plot Calibration")
self.plot_calibration_button.setCheckable(True)
self.plot_calibration_button.clicked.connect(self.calibration_plot.plot)
self.daq_run_button = QPushButton("Run")
self.daq_run_button.setCheckable(True)
self.daq_run_button.clicked.connect(self.run_daq)
def plot_daq(self):
self.figure.setBackground("w")
self.daq_plot = self.figure.addPlot(row=0, col=0)
self.time = list(range(10))
pen = pg.mkPen("red")
self.data = list(range(10))
self.line = self.daq_plot.plot(self.time, self.data, pen=pen)
self.item_index = 0
self.timer = QTimer()
self.timer.setInterval(50)
self.timer.timeout.connect(self.update_plot)
self.timer.start()
# self.update_plot()
def update_plot(self):
self.time = self.time[1:]
self.time.append(self.time[-1] + 1)
self.data = self.data[1:]
log.debug(self.buffer.totocount())
if self.buffer.totocount() > 20:
try:
log.debug(self.item_index)
item = self.buffer.get(self.item_index)
self.item_index += 1
except IndexError:
item = 0
else:
item = 0
self.data.append(item)
self.line.setData(self.time, self.data)
def plot_continously(self):
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(plot_daq)
def run_daq(self):
read_daq = Worker(self.daq_producer.read_analog_continously)
read_daq.signals.result.connect(self.print_output)
read_daq.signals.finished.connect(self.thread_complete)
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)
time.sleep(0.5)
self.continously_plot.plot_daq()
# self.threadpool.start(plot_daq)
def stop_recording(self):
self.add_to_textfield("pressed")
self._stop_recording.setEnabled(False)
def connect_dac(self):
devices = uldaq.get_daq_device_inventory(uldaq.InterfaceType.USB)
@ -240,14 +217,11 @@ class PyRelacs(QMainWindow):
log.debug("Connected")
except uldaq.ul_exception.ULException as e:
log.error(f"Could not Connect to DAQ: {e}")
self.daq_connect_button.setDisabled(True)
def disconnect_dac(self):
try:
self.daq_device.disconnect()
self.daq_device.release()
self.daq_disconnect_button.setDisabled(True)
self.daq_connect_button.setEnabled(True)
except AttributeError:
log.debug("DAQ was not connected")

View File

@ -0,0 +1,40 @@
import pyqtgraph as pg
from PyQt6.QtCore import QTimer
from pyrelacs.dataio.circbuffer import CircBuffer
from pyrelacs.util.logging import config_logging
log = config_logging()
class Continously:
def __init__(self, figure: pg.GraphicsLayoutWidget, buffer: CircBuffer):
self.figure = figure
self.buffer = buffer
def plot_daq(self, *args, **kwargs):
self.figure.setBackground("w")
self.daq_plot = self.figure.addPlot(row=0, col=0)
self.time = list(range(10))
pen = pg.mkPen("red")
self.data = list(range(10))
self.line = self.daq_plot.plot(self.time, self.data, pen=pen)
self.item = 0
self.timer = QTimer()
self.timer.setInterval(1)
self.timer.timeout.connect(self.update_plot)
self.timer.start()
def update_plot(self):
if self.buffer.totalcount() > 100:
if self.buffer.write_index() > self.item:
self.time = self.time[1:]
self.time.append(self.time[-1] + 1)
self.data = self.data[1:]
item = self.buffer.get(self.item)
self.data.append(item)
self.line.setData(self.time, self.data)
self.item += 1
else:
pass