Compare commits
7 Commits
calibratio
...
54f0d61fc9
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
54f0d61fc9 | ||
|
|
815838eab7 | ||
|
|
314e609472 | ||
|
|
2719d49eb0 | ||
|
|
a0c524326d | ||
|
|
c2285f3750 | ||
|
|
9327d1bac9 |
81
pyrelacs/dataio/buffer.py
Normal file
81
pyrelacs/dataio/buffer.py
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
import time
|
||||||
|
import faulthandler
|
||||||
|
from collections import deque
|
||||||
|
|
||||||
|
from pyqtgraph import transformToArray
|
||||||
|
import uldaq
|
||||||
|
import numpy as np
|
||||||
|
from IPython import embed
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
|
from pyrelacs.util.logging import config_logging
|
||||||
|
|
||||||
|
log = config_logging()
|
||||||
|
faulthandler.enable()
|
||||||
|
|
||||||
|
|
||||||
|
class DataBuffer:
|
||||||
|
def __init__(self, channels, samples):
|
||||||
|
self.channels = channels
|
||||||
|
self.samples = samples
|
||||||
|
|
||||||
|
def read_analog_continously(
|
||||||
|
self,
|
||||||
|
device: uldaq.DaqDevice,
|
||||||
|
samplerate: float = 40_000.0,
|
||||||
|
):
|
||||||
|
data_array = []
|
||||||
|
|
||||||
|
max_len_buffer = self.channels * self.samples
|
||||||
|
self.buffer = deque(maxlen=max_len_buffer)
|
||||||
|
|
||||||
|
samples_per_channel = 40_000
|
||||||
|
self.device = device
|
||||||
|
self.ai_device = self.device.get_ai_device()
|
||||||
|
|
||||||
|
data_analog_input = uldaq.create_float_buffer(
|
||||||
|
self.channels, samples_per_channel
|
||||||
|
)
|
||||||
|
|
||||||
|
er = self.ai_device.a_in_scan(
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
uldaq.AiInputMode.SINGLE_ENDED,
|
||||||
|
uldaq.Range.BIP10VOLTS,
|
||||||
|
samples_per_channel,
|
||||||
|
samplerate,
|
||||||
|
uldaq.ScanOption.CONTINUOUS,
|
||||||
|
uldaq.AInScanFlag.DEFAULT,
|
||||||
|
data=data_analog_input,
|
||||||
|
)
|
||||||
|
|
||||||
|
daq_status = uldaq.ScanStatus.IDLE
|
||||||
|
while daq_status == uldaq.ScanStatus.IDLE:
|
||||||
|
daq_status = self.ai_device.get_scan_status()[0]
|
||||||
|
prev_count = 0
|
||||||
|
prev_index = 0
|
||||||
|
while daq_status != uldaq.ScanStatus.IDLE:
|
||||||
|
daq_status, transfer_status = self.ai_device.get_scan_status()
|
||||||
|
|
||||||
|
# The index into the data buffer immediately following the last sample transferred.
|
||||||
|
curren_index = transfer_status.current_index
|
||||||
|
# total samples since start of the scan
|
||||||
|
total_samples = transfer_status.current_total_count
|
||||||
|
# The number of samples per channel transferred since the scan started
|
||||||
|
channel_samples = transfer_status.current_scan_count
|
||||||
|
|
||||||
|
self.ai_device.scan_stop()
|
||||||
|
|
||||||
|
|
||||||
|
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")
|
||||||
|
try:
|
||||||
|
daq_device = uldaq.DaqDevice(devices[0])
|
||||||
|
except uldaq.ul_exception.ULException as e:
|
||||||
|
log.error("Did not found daq devices, please connect one")
|
||||||
|
raise e
|
||||||
|
daq_device.connect()
|
||||||
|
|
||||||
|
buf = DataBuffer(channels=2, samples=100_000)
|
||||||
|
buf.read_analog_continously(daq_device)
|
||||||
@@ -11,7 +11,7 @@ from pyrelacs.util.logging import config_logging
|
|||||||
log = config_logging()
|
log = config_logging()
|
||||||
|
|
||||||
|
|
||||||
class MccDac:
|
class MccDaq:
|
||||||
"""
|
"""
|
||||||
Represents the Digital/Analog Converter from Meassuring Computing.
|
Represents the Digital/Analog Converter from Meassuring Computing.
|
||||||
provides methods for writing and reading the Analog / Digital input and output.
|
provides methods for writing and reading the Analog / Digital input and output.
|
||||||
@@ -43,6 +43,7 @@ class MccDac:
|
|||||||
except uldaq.ul_exception.ULException:
|
except uldaq.ul_exception.ULException:
|
||||||
self.disconnect_dac()
|
self.disconnect_dac()
|
||||||
self.connect_dac()
|
self.connect_dac()
|
||||||
|
|
||||||
self.ai_device = self.daq_device.get_ai_device()
|
self.ai_device = self.daq_device.get_ai_device()
|
||||||
self.ao_device = self.daq_device.get_ao_device()
|
self.ao_device = self.daq_device.get_ao_device()
|
||||||
self.dio_device = self.daq_device.get_dio_device()
|
self.dio_device = self.daq_device.get_dio_device()
|
||||||
@@ -6,10 +6,8 @@ import uldaq
|
|||||||
from IPython import embed
|
from IPython import embed
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
from scipy.signal import welch
|
|
||||||
from scipy.signal import find_peaks
|
|
||||||
|
|
||||||
from pyrelacs.devices.mccdac import MccDac
|
from pyrelacs.devices.mccdaq import MccDaq
|
||||||
from pyrelacs.util.logging import config_logging
|
from pyrelacs.util.logging import config_logging
|
||||||
|
|
||||||
log = config_logging()
|
log = config_logging()
|
||||||
@@ -17,7 +15,7 @@ log = config_logging()
|
|||||||
faulthandler.enable()
|
faulthandler.enable()
|
||||||
|
|
||||||
|
|
||||||
class Calibration(MccDac):
|
class Calibration(MccDaq):
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.SAMPLERATE = 40_000.0
|
self.SAMPLERATE = 40_000.0
|
||||||
|
|||||||
@@ -11,19 +11,20 @@ from PyQt6.QtWidgets import (
|
|||||||
QStatusBar,
|
QStatusBar,
|
||||||
)
|
)
|
||||||
import uldaq
|
import uldaq
|
||||||
import numpy as np
|
|
||||||
import nixio as nix
|
import nixio as nix
|
||||||
import pyqtgraph as pg
|
import pyqtgraph as pg
|
||||||
|
|
||||||
from pathlib import Path as path
|
from pathlib import Path as path
|
||||||
from scipy.signal import welch, find_peaks
|
|
||||||
|
|
||||||
from pyrelacs.worker import Worker
|
from pyrelacs.worker import Worker
|
||||||
from pyrelacs.repros.repros import Repro
|
from pyrelacs.repros.repros import Repro
|
||||||
from pyrelacs.util.logging import config_logging
|
from pyrelacs.dataio.buffer import DataBuffer
|
||||||
|
|
||||||
from pyrelacs.ui.about import AboutDialog
|
from pyrelacs.ui.about import AboutDialog
|
||||||
from pyrelacs.ui.plots.calibration import CalibrationPlot
|
from pyrelacs.ui.plots.calibration import CalibrationPlot
|
||||||
|
|
||||||
|
from pyrelacs.util.logging import config_logging
|
||||||
|
|
||||||
log = config_logging()
|
log = config_logging()
|
||||||
_root = path(__file__).parent.parent
|
_root = path(__file__).parent.parent
|
||||||
|
|
||||||
@@ -51,6 +52,7 @@ class PyRelacs(QMainWindow):
|
|||||||
self.threadpool = QThreadPool()
|
self.threadpool = QThreadPool()
|
||||||
self.repros = Repro()
|
self.repros = Repro()
|
||||||
|
|
||||||
|
# self.buffers = DataBuffer(channels=1, samples=100_000)
|
||||||
self.text = QPlainTextEdit()
|
self.text = QPlainTextEdit()
|
||||||
self.text.setReadOnly(True)
|
self.text.setReadOnly(True)
|
||||||
|
|
||||||
@@ -179,9 +181,6 @@ class PyRelacs(QMainWindow):
|
|||||||
except uldaq.ul_exception.ULException as e:
|
except uldaq.ul_exception.ULException as e:
|
||||||
log.error(f"Could not Connect to DAQ: {e}")
|
log.error(f"Could not Connect to DAQ: {e}")
|
||||||
self.daq_connect_button.setDisabled(True)
|
self.daq_connect_button.setDisabled(True)
|
||||||
else:
|
|
||||||
log.debug("Already handeld the error")
|
|
||||||
pass
|
|
||||||
|
|
||||||
def disconnect_dac(self):
|
def disconnect_dac(self):
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user