Compare commits
No commits in common. "b5f8d7663d021b03000d3917e0d189aa3bc3b4ca" and "25d16cc5fd37ac6b93ac9d9140033db26bd9b05f" have entirely different histories.
b5f8d7663d
...
25d16cc5fd
@ -1,17 +1,10 @@
|
||||
from typing import Tuple
|
||||
import numpy as np
|
||||
from IPython import embed
|
||||
from pyqtgraph.Qt.QtCore import QMutex
|
||||
|
||||
|
||||
class CircBuffer:
|
||||
def __init__(
|
||||
self,
|
||||
size: int,
|
||||
mutex: QMutex,
|
||||
channels: int = 1,
|
||||
samplerate: int = 40_000,
|
||||
):
|
||||
def __init__(self, size: int, channels: int = 1, samplerate: int = 40_000):
|
||||
self.__size = size
|
||||
self.__channels = channels
|
||||
self.__samplereate = samplerate
|
||||
@ -23,7 +16,7 @@ class CircBuffer:
|
||||
self.__is_full = [False for i in range(channels)]
|
||||
self.__totalcount = [0 for i in range(channels)]
|
||||
self.__overflows = [0 for i in range(channels)]
|
||||
self.mutex = mutex
|
||||
self.__read_increment = samplerate * 0.1
|
||||
|
||||
@property
|
||||
def size(self):
|
||||
@ -47,7 +40,6 @@ class CircBuffer:
|
||||
return self.__index[channel]
|
||||
|
||||
def append(self, item, channel: int = 0):
|
||||
self.mutex.lock()
|
||||
self.__buffer[channel, self.write_index(channel)] = item
|
||||
self.__index[channel] = (self.write_index(channel) + 1) % self.__size
|
||||
self.__totalcount[channel] += 1
|
||||
@ -57,7 +49,6 @@ class CircBuffer:
|
||||
if self.__index[channel] == 0:
|
||||
self.__is_full[channel] = True
|
||||
self.__overflows[channel] += 1
|
||||
self.mutex.unlock()
|
||||
|
||||
def get_all(self, channel: int = 0):
|
||||
"""
|
||||
|
@ -2,7 +2,7 @@ import time
|
||||
from pathlib import Path as path
|
||||
|
||||
from PyQt6.QtGui import QAction, QIcon, QKeySequence
|
||||
from PyQt6.QtCore import Qt, QSize, QThreadPool, QMutex, QTimer
|
||||
from PyQt6.QtCore import Qt, QSize, QThreadPool
|
||||
from PyQt6.QtWidgets import (
|
||||
QGridLayout,
|
||||
QToolBar,
|
||||
@ -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
|
||||
@ -45,9 +44,6 @@ class PyRelacs(QMainWindow):
|
||||
Qt.ToolButtonStyle.ToolButtonTextBesideIcon
|
||||
) # Ensure icons are displayed with text
|
||||
self.setWindowTitle("PyRelacs")
|
||||
self.mutex = QMutex()
|
||||
self.timer = QTimer(self)
|
||||
self.timer.setInterval(200)
|
||||
|
||||
self.figure = pg.GraphicsLayoutWidget()
|
||||
|
||||
@ -84,14 +80,13 @@ class PyRelacs(QMainWindow):
|
||||
end = time.time()
|
||||
log.debug(f"Buffer allocation took {end - start}")
|
||||
|
||||
self.buffer = CircBuffer(
|
||||
size=BUFFERSIZE, samplerate=SAMPLERATE, mutex=self.mutex
|
||||
)
|
||||
self.buffer = CircBuffer(size=BUFFERSIZE, samplerate=SAMPLERATE)
|
||||
# self.connect_dac()
|
||||
|
||||
# self.daq_producer = DaqProducer(self.buffer, self.daq_device, [1, 1])
|
||||
self.sin_producer = SinProducer(self.buffer)
|
||||
self.continously_plot = Continously(self.figure, self.buffer)
|
||||
self.continously_plot.plot_daq()
|
||||
|
||||
def create_actions(self):
|
||||
self._rlx_exitaction = QAction(QIcon(":/icons/exit.png"), "Exit", self)
|
||||
@ -134,10 +129,6 @@ class PyRelacs(QMainWindow):
|
||||
self._stop_recording = QAction(QIcon(":/icons/stop.png"), "Stop", self)
|
||||
self._stop_recording.triggered.connect(self.stop_recording)
|
||||
|
||||
self._refresh = QAction("Refresh", self)
|
||||
self._refresh.triggered.connect(self.refresh_plot)
|
||||
self._refresh.setShortcut(QKeySequence("Alt+r"))
|
||||
|
||||
self.create_menu()
|
||||
|
||||
def create_menu(self):
|
||||
@ -180,7 +171,6 @@ class PyRelacs(QMainWindow):
|
||||
daq_toolbar.addAction(self._run_action)
|
||||
daq_toolbar.addAction(self._run_sinus_action)
|
||||
daq_toolbar.addAction(self._stop_recording)
|
||||
daq_toolbar.addAction(self._refresh)
|
||||
self.addToolBar(Qt.ToolBarArea.TopToolBarArea, daq_toolbar)
|
||||
|
||||
repro_toolbar = QToolBar("Repros")
|
||||
@ -194,9 +184,6 @@ class PyRelacs(QMainWindow):
|
||||
repro_toolbar.addAction(repro_action)
|
||||
self.addToolBar(Qt.ToolBarArea.BottomToolBarArea, repro_toolbar)
|
||||
|
||||
def refresh_plot(self):
|
||||
self.continously_plot.refresh()
|
||||
|
||||
def plot_continously(self):
|
||||
plot_daq = Worker(self.continously_plot.plot_daq)
|
||||
plot_daq.signals.result.connect(self.print_output)
|
||||
@ -225,13 +212,13 @@ class PyRelacs(QMainWindow):
|
||||
sinus_pro.signals.progress.connect(self.progress_fn)
|
||||
self.threadpool.start(sinus_pro)
|
||||
|
||||
# plot_daq = Worker(self.continously_plot.plot_daq, self.timer)
|
||||
# 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)
|
||||
|
||||
self.continously_plot.plot_daq()
|
||||
# self.continously_plot.plot_daq()
|
||||
|
||||
def stop_recording(self):
|
||||
self.add_to_textfield("pressed")
|
||||
|
@ -1,8 +1,9 @@
|
||||
import time
|
||||
import pyqtgraph as pg
|
||||
from IPython import embed
|
||||
import numpy as np
|
||||
from pyqtgraph.Qt.QtCore import QTimer
|
||||
|
||||
from PyQt6.QtCore import QTimer
|
||||
from pyrelacs.dataio.circbuffer import CircBuffer
|
||||
from pyrelacs.util.logging import config_logging
|
||||
|
||||
@ -16,16 +17,11 @@ class Continously:
|
||||
|
||||
def plot_daq(self, *args, **kwargs):
|
||||
self.figure.setBackground("w")
|
||||
|
||||
prev_plot = self.figure.getItem(row=0, col=0)
|
||||
if prev_plot:
|
||||
self.figure.removeItem(prev_plot)
|
||||
self.continous_plot = self.figure.addPlot(row=0, col=0)
|
||||
|
||||
self.daq_plot = self.figure.addPlot(row=0, col=0)
|
||||
pen = pg.mkPen("red")
|
||||
self.time = np.zeros(self.buffer.size)
|
||||
self.data = np.zeros(self.buffer.size)
|
||||
self.line = self.continous_plot.plot(
|
||||
self.line = self.daq_plot.plot(
|
||||
self.time,
|
||||
self.data,
|
||||
pen=pen,
|
||||
@ -33,8 +29,8 @@ class Continously:
|
||||
)
|
||||
|
||||
# self.plot_index = 0
|
||||
self.CHUNK_PLOT = 1_000
|
||||
self.timer = QTimer()
|
||||
self.CHUNK_PLOT = 10_000
|
||||
self.timer.setInterval(200)
|
||||
self.timer.timeout.connect(self.update_plot)
|
||||
self.timer.start()
|
||||
@ -45,8 +41,7 @@ class Continously:
|
||||
log.debug(self.buffer.totalcount())
|
||||
try:
|
||||
times, items = self.buffer.read(
|
||||
self.buffer.write_index() - self.CHUNK_PLOT - 1_000,
|
||||
extend=self.CHUNK_PLOT,
|
||||
self.buffer.write_index() - self.CHUNK_PLOT, extend=self.CHUNK_PLOT
|
||||
)
|
||||
except IndexError as e:
|
||||
items = np.zeros(self.CHUNK_PLOT)
|
||||
@ -70,6 +65,3 @@ class Continously:
|
||||
|
||||
def stop_plotting(self):
|
||||
self.timer.stop()
|
||||
|
||||
def refresh(self):
|
||||
self.continous_plot.enableAutoRange()
|
||||
|
Loading…
Reference in New Issue
Block a user