forked from awendt/pyrelacs
74 lines
2.1 KiB
Python
74 lines
2.1 KiB
Python
from ctypes import Array, c_double
|
|
import uldaq
|
|
import numpy as np
|
|
|
|
from pyrelacs.util.logging import config_logging
|
|
|
|
log = config_logging()
|
|
|
|
|
|
class Repos:
|
|
def __init__(self) -> None:
|
|
devices = uldaq.get_daq_device_inventory(uldaq.InterfaceType.USB)
|
|
log.debug(f"Found daq devices {len(devices)}, connecting to the first one")
|
|
if len(devices) == 0:
|
|
log.error("Did not found daq devices, please connect one")
|
|
exit(1)
|
|
self.daq_device = uldaq.DaqDevice(devices[0])
|
|
self.daq_device.connect()
|
|
log.debug("Connected")
|
|
|
|
def read_analog_daq(
|
|
self,
|
|
channels: list[int],
|
|
duration: int,
|
|
samplerate: float,
|
|
AiInputMode: uldaq.AiInputMode = uldaq.AiInputMode.SINGLE_ENDED,
|
|
Range: uldaq.Range = uldaq.Range.BIP10VOLTS,
|
|
ScanOption: uldaq.ScanOption = uldaq.ScanOption.DEFAULTIO,
|
|
AInScanFlag: uldaq.AInScanFlag = uldaq.AInScanFlag.DEFAULT,
|
|
) -> Array[c_double]:
|
|
|
|
if len(channels) > 2:
|
|
log.error("Please provide only two channels")
|
|
# Get the Ananlog In device and Analog Info
|
|
|
|
ai_device = self.daq_device.get_ai_device()
|
|
ai_info = ai_device.get_info()
|
|
|
|
buffer_len = np.shape(np.arange(0, duration, 1 / samplerate))[0]
|
|
data_analog_input = uldaq.create_float_buffer(1, buffer_len)
|
|
|
|
er = ai_device.a_in_scan(
|
|
channels[0],
|
|
channels[1],
|
|
AiInputMode,
|
|
Range,
|
|
buffer_len,
|
|
samplerate,
|
|
ScanOption,
|
|
AInScanFlag,
|
|
data=data_analog_input,
|
|
)
|
|
ai_device.scan_wait(uldaq.WaitType.WAIT_UNTIL_DONE, timeout=-1)
|
|
log.info(f"Sampled with {er}")
|
|
log.debug("Scanning")
|
|
|
|
return data_analog_input
|
|
|
|
def disconnect_dac(self):
|
|
self.daq_device.disconnect()
|
|
self.daq_device.release()
|
|
|
|
def write_daq(self) -> None:
|
|
pass
|
|
|
|
def run_repo(self) -> None:
|
|
pass
|
|
|
|
def stop_repo(self) -> None:
|
|
pass
|
|
|
|
def reload_repo(self) -> None:
|
|
pass
|