forked from awendt/pyrelacs
53 lines
1.4 KiB
Python
53 lines
1.4 KiB
Python
import ctypes
|
|
|
|
import uldaq
|
|
from IPython import embed
|
|
from pyrelacs.util.logging import config_logging
|
|
import numpy as np
|
|
import matplotlib.pyplot as plt
|
|
|
|
log = config_logging()
|
|
|
|
|
|
class Output_daq:
|
|
def __init__(self) -> None:
|
|
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,
|
|
)
|
|
ao_device.scan_wait(uldaq.WaitType.WAIT_UNTIL_DONE, 11)
|
|
|
|
self.daq_device.disconnect()
|
|
self.daq_device.release()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
daq_input = Output_daq()
|
|
daq_input.write_daq()
|