moving to repos.py

This commit is contained in:
wendtalexander 2024-09-23 11:54:05 +02:00
parent 2100a0205f
commit ebf7fe89bf

View File

@ -2,6 +2,7 @@ import ctypes
import uldaq
from IPython import embed
from pyrelacs.repros.repos import Repos
from pyrelacs.util.logging import config_logging
import numpy as np
import matplotlib.pyplot as plt
@ -9,40 +10,23 @@ import matplotlib.pyplot as plt
log = config_logging()
class Output_daq:
class Output_daq(Repos):
def __init__(self) -> None:
devices = uldaq.get_daq_device_inventory(uldaq.InterfaceType.USB)
self.daq_device = uldaq.DaqDevice(devices[0])
self.daq_device.connect()
super().__init__()
# devices = uldaq.get_daq_device_inventory(uldaq.InterfaceType.USB)
# self.daq_device = uldaq.DaqDevice(devices[0])
# self.daq_device.connect()
def write_daq(self):
log.debug("running repro")
time = np.arange(0, 10, 1 / 30_000.0)
data = 2 * np.sin(2 * np.pi * 10 * time)
buffer = ctypes.c_double * 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()
log.debug(
f"Analog info,\n Channels available {ao_info.get_num_chans()}, \n Max Samplerate: {ao_info.get_max_scan_rate()}"
)
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,
data = 2 * np.sin(2 * np.pi * 1 * time)
self.send_analog_dac(
data, [0, 0], 30_000, ScanOption=uldaq.ScanOption.EXTTRIGGER
)
ao_device.scan_wait(uldaq.WaitType.WAIT_UNTIL_DONE, 11)
def trigger(self):
self.digital_trigger(1)
self.daq_device.disconnect()
self.daq_device.release()
@ -50,3 +34,4 @@ class Output_daq:
if __name__ == "__main__":
daq_input = Output_daq()
daq_input.write_daq()
# daq_input.trigger()