2
0
forked from awendt/pyrelacs

adding threading to fix segementation fault

This commit is contained in:
wendtalexander
2024-09-18 10:25:22 +02:00
parent 25cd1c0585
commit e19c147059
2 changed files with 132 additions and 14 deletions

View File

@@ -1,8 +1,9 @@
from PyQt6.QtGui import QAction
import sys
import pathlib
import ctypes
from PyQt6.QtCore import QSize, Qt
from PyQt6.QtCore import QSize, QThreadPool, Qt
from PyQt6.QtWidgets import (
QApplication,
QGridLayout,
@@ -17,6 +18,7 @@ from IPython import embed
import numpy as np
from pyrelacs.util.logging import config_logging
from pyrelacs.daq_thread import Worker
log = config_logging()
@@ -25,6 +27,7 @@ class PyRelacs(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("PyRelacs")
self.threadpool = QThreadPool()
self.daq_connect_button = QPushButton("Connect Daq")
self.daq_connect_button.setCheckable(True)
@@ -92,22 +95,53 @@ class PyRelacs(QMainWindow):
self.toolbar.addAction(individual_repro_button)
def run_repro(self):
daq_thread = Worker(self.read_daq)
self.threadpool.start(daq_thread)
def on_scan_finished(self):
log.debug("Scan finished")
def read_daq(self, progress_callback):
log.debug("running repro")
time = np.arange(
0, self.config["Sinus"]["duration"], 1 / self.config["Sinus"]["fs"]
)
data = self.config["Sinus"]["amplitude"] * np.sin(
2 * np.pi * self.config["Sinus"]["freq"] * time
)
time = np.arange(0, 10, 1 / 30_000.0)
data = 2 * np.sin(2 * np.pi * 10 * time)
buffer = ctypes.c_double * len(time)
buffer_ai = uldaq.create_float_buffer(1, len(time))
data_c = buffer(*data)
log.debug(f"Created C_double data {data_c}")
ao_device = self.daq_device.get_ao_device()
ao_info = ao_device.get_info()
try:
err = ao_device.a_out_list(
0, 0, [uldaq.Range.BIP2VOLTS], uldaq.AOutListFlag.DEFAULT, data
)
except uldaq.ULException as e:
print(e)
ai_device = self.daq_device.get_ai_device()
er = ai_device.a_in_scan(
1,
1,
uldaq.AiInputMode.SINGLE_ENDED,
uldaq.Range.BIP10VOLTS,
int(len(data)),
30_000.0,
uldaq.ScanOption.EXTTRIGGER,
uldaq.AInScanFlag.DEFAULT,
data=buffer_ai,
)
# ai_device.scan_wait(uldaq.WaitType.WAIT_UNTIL_DONE, timeout=-1)
err = ao_device.a_out_scan(
0,
0,
uldaq.Range.BIP10VOLTS,
int(len(data)),
30_000.0,
uldaq.ScanOption.DEFAULTIO,
uldaq.AOutScanFlag.DEFAULT,
data_c,
)
# INFO: Need to wait for the acquistion
self.daq_disconnect_button.setDisabled(True)
self.daq_connect_button.setEnabled(True)
embed()
exit()
if __name__ == "__main__":