[ui] adding pglive, trying to plot continious data
This commit is contained in:
parent
bf72f90009
commit
5ec5cc8644
@ -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")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user