Compare commits
No commits in common. "ff2d8ebb50914fe756ea7289a0d58a4beb765a4a" and "b5f8d7663d021b03000d3917e0d189aa3bc3b4ca" have entirely different histories.
ff2d8ebb50
...
b5f8d7663d
@ -22,8 +22,6 @@ class DaqProducer:
|
|||||||
self.ai_device = self.device.get_ai_device()
|
self.ai_device = self.device.get_ai_device()
|
||||||
self.channels = channels
|
self.channels = channels
|
||||||
|
|
||||||
self.stop = False
|
|
||||||
|
|
||||||
def read_analog_continously(
|
def read_analog_continously(
|
||||||
self,
|
self,
|
||||||
*args,
|
*args,
|
||||||
@ -69,7 +67,7 @@ class DaqProducer:
|
|||||||
while daq_status != uldaq.ScanStatus.IDLE:
|
while daq_status != uldaq.ScanStatus.IDLE:
|
||||||
prev_count = 0
|
prev_count = 0
|
||||||
prev_index = 0
|
prev_index = 0
|
||||||
while not self.stop:
|
while time.time() - start_time < 10:
|
||||||
daq_status, transfer_status = self.ai_device.get_scan_status()
|
daq_status, transfer_status = self.ai_device.get_scan_status()
|
||||||
# The index into the data buffer immediately following the last sample transferred.
|
# The index into the data buffer immediately following the last sample transferred.
|
||||||
current_index = transfer_status.current_index
|
current_index = transfer_status.current_index
|
||||||
@ -156,20 +154,17 @@ class DaqProducer:
|
|||||||
break
|
break
|
||||||
return "Done. "
|
return "Done. "
|
||||||
|
|
||||||
def stop_aquisition(self):
|
|
||||||
self.stop = True
|
if __name__ == "__main__":
|
||||||
|
devices = uldaq.get_daq_device_inventory(uldaq.InterfaceType.USB)
|
||||||
|
log.debug(f"Found daq devices {len(devices)}, connecting to the first one")
|
||||||
# if __name__ == "__main__":
|
try:
|
||||||
# devices = uldaq.get_daq_device_inventory(uldaq.InterfaceType.USB)
|
daq_device = uldaq.DaqDevice(devices[0])
|
||||||
# log.debug(f"Found daq devices {len(devices)}, connecting to the first one")
|
except uldaq.ul_exception.ULException as e:
|
||||||
# try:
|
log.error("Did not found daq devices, please connect one")
|
||||||
# daq_device = uldaq.DaqDevice(devices[0])
|
raise e
|
||||||
# except uldaq.ul_exception.ULException as e:
|
daq_device.connect()
|
||||||
# log.error("Did not found daq devices, please connect one")
|
|
||||||
# raise e
|
buf = CircBuffer(size=1_000_000, samplerate=100)
|
||||||
# daq_device.connect()
|
producer = DaqProducer(buf, daq_device, [1, 1])
|
||||||
#
|
producer.read_analog_continously()
|
||||||
# buf = CircBuffer(size=1_000_000, samplerate=100)
|
|
||||||
# producer = DaqProducer(buf, daq_device, [1, 1])
|
|
||||||
# producer.read_analog_continously()
|
|
||||||
|
@ -87,20 +87,11 @@ class PyRelacs(QMainWindow):
|
|||||||
self.buffer = CircBuffer(
|
self.buffer = CircBuffer(
|
||||||
size=BUFFERSIZE, samplerate=SAMPLERATE, mutex=self.mutex
|
size=BUFFERSIZE, samplerate=SAMPLERATE, mutex=self.mutex
|
||||||
)
|
)
|
||||||
self.continously_plot = Continously(self.figure, self.buffer)
|
# self.connect_dac()
|
||||||
self.continously_plot.plot()
|
|
||||||
|
|
||||||
start = time.time()
|
# self.daq_producer = DaqProducer(self.buffer, self.daq_device, [1, 1])
|
||||||
self.connect_dac()
|
self.sin_producer = SinProducer(self.buffer)
|
||||||
end = time.time()
|
self.continously_plot = Continously(self.figure, self.buffer)
|
||||||
log.debug(f"Connection to DAQ took {end - start}")
|
|
||||||
|
|
||||||
if hasattr(uldaq, "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)
|
|
||||||
|
|
||||||
def create_actions(self):
|
def create_actions(self):
|
||||||
self._rlx_exitaction = QAction(QIcon(":/icons/exit.png"), "Exit", self)
|
self._rlx_exitaction = QAction(QIcon(":/icons/exit.png"), "Exit", self)
|
||||||
@ -143,8 +134,8 @@ class PyRelacs(QMainWindow):
|
|||||||
self._stop_recording = QAction(QIcon(":/icons/stop.png"), "Stop", self)
|
self._stop_recording = QAction(QIcon(":/icons/stop.png"), "Stop", self)
|
||||||
self._stop_recording.triggered.connect(self.stop_recording)
|
self._stop_recording.triggered.connect(self.stop_recording)
|
||||||
|
|
||||||
self._refresh = QAction("Recenter", self)
|
self._refresh = QAction("Refresh", self)
|
||||||
self._refresh.triggered.connect(self.recenter_continously_plot)
|
self._refresh.triggered.connect(self.refresh_plot)
|
||||||
self._refresh.setShortcut(QKeySequence("Alt+r"))
|
self._refresh.setShortcut(QKeySequence("Alt+r"))
|
||||||
|
|
||||||
self.create_menu()
|
self.create_menu()
|
||||||
@ -189,7 +180,7 @@ class PyRelacs(QMainWindow):
|
|||||||
daq_toolbar.addAction(self._run_action)
|
daq_toolbar.addAction(self._run_action)
|
||||||
daq_toolbar.addAction(self._run_sinus_action)
|
daq_toolbar.addAction(self._run_sinus_action)
|
||||||
daq_toolbar.addAction(self._stop_recording)
|
daq_toolbar.addAction(self._stop_recording)
|
||||||
# daq_toolbar.addAction(self._refresh)
|
daq_toolbar.addAction(self._refresh)
|
||||||
self.addToolBar(Qt.ToolBarArea.TopToolBarArea, daq_toolbar)
|
self.addToolBar(Qt.ToolBarArea.TopToolBarArea, daq_toolbar)
|
||||||
|
|
||||||
repro_toolbar = QToolBar("Repros")
|
repro_toolbar = QToolBar("Repros")
|
||||||
@ -203,24 +194,29 @@ class PyRelacs(QMainWindow):
|
|||||||
repro_toolbar.addAction(repro_action)
|
repro_toolbar.addAction(repro_action)
|
||||||
self.addToolBar(Qt.ToolBarArea.BottomToolBarArea, repro_toolbar)
|
self.addToolBar(Qt.ToolBarArea.BottomToolBarArea, repro_toolbar)
|
||||||
|
|
||||||
def recenter_continously_plot(self):
|
def refresh_plot(self):
|
||||||
self.continously_plot.refresh()
|
self.continously_plot.refresh()
|
||||||
|
|
||||||
def plot_continously(self):
|
def plot_continously(self):
|
||||||
plot_con = Worker(self.continously_plot.plot)
|
plot_daq = Worker(self.continously_plot.plot_daq)
|
||||||
plot_con.signals.result.connect(self.print_output)
|
plot_daq.signals.result.connect(self.print_output)
|
||||||
plot_con.signals.finished.connect(self.thread_complete)
|
plot_daq.signals.finished.connect(self.thread_complete)
|
||||||
plot_con.signals.progress.connect(self.progress_fn)
|
plot_daq.signals.progress.connect(self.progress_fn)
|
||||||
self.threadpool.start(plot_con)
|
self.threadpool.start(plot_daq)
|
||||||
|
|
||||||
def run_daq(self):
|
def run_daq(self):
|
||||||
read_daq = Worker(self.daq_producer.read_analog_continously)
|
read_daq = Worker(self.daq_producer.read_analog_continously)
|
||||||
read_daq.signals.result.connect(self.print_output)
|
read_daq.signals.result.connect(self.print_output)
|
||||||
read_daq.signals.finished.connect(self.thread_complete)
|
read_daq.signals.finished.connect(self.thread_complete)
|
||||||
read_daq.signals.progress.connect(self.progress_fn)
|
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)
|
self.threadpool.start(read_daq)
|
||||||
|
time.sleep(0.5)
|
||||||
self.continously_plot.plot()
|
self.continously_plot.plot_daq()
|
||||||
|
# self.threadpool.start(plot_daq)
|
||||||
|
|
||||||
def run_sinus(self):
|
def run_sinus(self):
|
||||||
sinus_pro = Worker(self.sin_producer.produce_sin)
|
sinus_pro = Worker(self.sin_producer.produce_sin)
|
||||||
@ -229,15 +225,19 @@ class PyRelacs(QMainWindow):
|
|||||||
sinus_pro.signals.progress.connect(self.progress_fn)
|
sinus_pro.signals.progress.connect(self.progress_fn)
|
||||||
self.threadpool.start(sinus_pro)
|
self.threadpool.start(sinus_pro)
|
||||||
|
|
||||||
self.continously_plot.plot()
|
# plot_daq = Worker(self.continously_plot.plot_daq, self.timer)
|
||||||
|
# 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()
|
||||||
|
|
||||||
def stop_recording(self):
|
def stop_recording(self):
|
||||||
self.add_to_textfield("Stopping the recording")
|
self.add_to_textfield("pressed")
|
||||||
if hasattr(PyRelacs, "sin_producer"):
|
# self._stop_recording.setEnabled(False)
|
||||||
self.sin_producer.stop_request()
|
self.sin_producer.stop_request()
|
||||||
self.continously_plot.stop_plotting()
|
self.continously_plot.stop_plotting()
|
||||||
if hasattr(uldaq, "daq_device"):
|
|
||||||
self.daq_producer.stop_aquisition()
|
|
||||||
|
|
||||||
def connect_dac(self):
|
def connect_dac(self):
|
||||||
devices = uldaq.get_daq_device_inventory(uldaq.InterfaceType.USB)
|
devices = uldaq.get_daq_device_inventory(uldaq.InterfaceType.USB)
|
||||||
@ -250,6 +250,13 @@ class PyRelacs(QMainWindow):
|
|||||||
log.error("DAQ is not connected")
|
log.error("DAQ is not connected")
|
||||||
log.error("Please connect a DAQ device to the system")
|
log.error("Please connect a DAQ device to the system")
|
||||||
|
|
||||||
|
if hasattr(PyRelacs, "daq_device"):
|
||||||
|
try:
|
||||||
|
self.daq_device.connect()
|
||||||
|
log.debug("Connected")
|
||||||
|
except uldaq.ul_exception.ULException as e:
|
||||||
|
log.error(f"Could not Connect to DAQ: {e}")
|
||||||
|
|
||||||
def disconnect_dac(self):
|
def disconnect_dac(self):
|
||||||
try:
|
try:
|
||||||
self.daq_device.disconnect()
|
self.daq_device.disconnect()
|
||||||
|
@ -14,18 +14,18 @@ class Continously:
|
|||||||
self.figure = figure
|
self.figure = figure
|
||||||
self.buffer = buffer
|
self.buffer = buffer
|
||||||
|
|
||||||
def plot(self, *args, **kwargs):
|
def plot_daq(self, *args, **kwargs):
|
||||||
self.figure.setBackground("w")
|
self.figure.setBackground("w")
|
||||||
|
|
||||||
prev_plot = self.figure.getItem(row=0, col=0)
|
prev_plot = self.figure.getItem(row=0, col=0)
|
||||||
if prev_plot:
|
if prev_plot:
|
||||||
self.figure.removeItem(prev_plot)
|
self.figure.removeItem(prev_plot)
|
||||||
self.continous_ax = self.figure.addPlot(row=0, col=0)
|
self.continous_plot = self.figure.addPlot(row=0, col=0)
|
||||||
|
|
||||||
pen = pg.mkPen("red")
|
pen = pg.mkPen("red")
|
||||||
self.time = np.zeros(self.buffer.size)
|
self.time = np.zeros(self.buffer.size)
|
||||||
self.data = np.zeros(self.buffer.size)
|
self.data = np.zeros(self.buffer.size)
|
||||||
self.line = self.continous_ax.plot(
|
self.line = self.continous_plot.plot(
|
||||||
self.time,
|
self.time,
|
||||||
self.data,
|
self.data,
|
||||||
pen=pen,
|
pen=pen,
|
||||||
@ -40,7 +40,7 @@ class Continously:
|
|||||||
self.timer.start()
|
self.timer.start()
|
||||||
|
|
||||||
def update_plot(self):
|
def update_plot(self):
|
||||||
# log.debug(self.buffer.totalcount())
|
log.debug(self.buffer.totalcount())
|
||||||
if self.buffer.totalcount() > self.CHUNK_PLOT:
|
if self.buffer.totalcount() > self.CHUNK_PLOT:
|
||||||
log.debug(self.buffer.totalcount())
|
log.debug(self.buffer.totalcount())
|
||||||
try:
|
try:
|
||||||
@ -72,4 +72,4 @@ class Continously:
|
|||||||
self.timer.stop()
|
self.timer.stop()
|
||||||
|
|
||||||
def refresh(self):
|
def refresh(self):
|
||||||
self.continous_ax.enableAutoRange()
|
self.continous_plot.enableAutoRange()
|
||||||
|
Loading…
Reference in New Issue
Block a user