forked from awendt/pyrelacs
adding digital trigger
This commit is contained in:
parent
ebf7fe89bf
commit
fa3c704497
@ -1,5 +1,6 @@
|
|||||||
from ctypes import Array, c_double
|
from ctypes import Array, c_double
|
||||||
from typing import Union
|
from typing import Union
|
||||||
|
from IPython import embed
|
||||||
import numpy.typing as npt
|
import numpy.typing as npt
|
||||||
import uldaq
|
import uldaq
|
||||||
import numpy as np
|
import numpy as np
|
||||||
@ -30,16 +31,15 @@ class Repos:
|
|||||||
ScanOption: uldaq.ScanOption = uldaq.ScanOption.DEFAULTIO,
|
ScanOption: uldaq.ScanOption = uldaq.ScanOption.DEFAULTIO,
|
||||||
AInScanFlag: uldaq.AInScanFlag = uldaq.AInScanFlag.DEFAULT,
|
AInScanFlag: uldaq.AInScanFlag = uldaq.AInScanFlag.DEFAULT,
|
||||||
) -> Array[c_double]:
|
) -> Array[c_double]:
|
||||||
|
if channels[0] == channels[1]:
|
||||||
if len(channels) > 2:
|
channel_len = 1
|
||||||
log.error("Please provide only two channels")
|
else:
|
||||||
# Get the Ananlog In device and Analog Info
|
channel_len = len(channels)
|
||||||
|
assert len(channels) == 2, log.error("Please provide a list with two ints")
|
||||||
|
|
||||||
ai_device = self.daq_device.get_ai_device()
|
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]
|
buffer_len = np.shape(np.arange(0, duration, 1 / samplerate))[0]
|
||||||
data_analog_input = uldaq.create_float_buffer(1, buffer_len)
|
data_analog_input = uldaq.create_float_buffer(channel_len, buffer_len)
|
||||||
|
|
||||||
er = ai_device.a_in_scan(
|
er = ai_device.a_in_scan(
|
||||||
channels[0],
|
channels[0],
|
||||||
@ -52,8 +52,7 @@ class Repos:
|
|||||||
AInScanFlag,
|
AInScanFlag,
|
||||||
data=data_analog_input,
|
data=data_analog_input,
|
||||||
)
|
)
|
||||||
ai_device.scan_wait(uldaq.WaitType.WAIT_UNTIL_DONE, timeout=-1)
|
# ai_device.scan_wait(uldaq.WaitType.WAIT_UNTIL_DONE, timeout=-1)
|
||||||
log.debug("Scanning")
|
|
||||||
|
|
||||||
return data_analog_input
|
return data_analog_input
|
||||||
|
|
||||||
@ -61,13 +60,11 @@ class Repos:
|
|||||||
self,
|
self,
|
||||||
data: Union[list, npt.NDArray],
|
data: Union[list, npt.NDArray],
|
||||||
channels: list[int],
|
channels: list[int],
|
||||||
duration: int,
|
|
||||||
samplerate: float,
|
samplerate: float,
|
||||||
AiInputMode: uldaq.AiInputMode = uldaq.AiInputMode.SINGLE_ENDED,
|
|
||||||
Range: uldaq.Range = uldaq.Range.BIP10VOLTS,
|
Range: uldaq.Range = uldaq.Range.BIP10VOLTS,
|
||||||
ScanOption: uldaq.ScanOption = uldaq.ScanOption.DEFAULTIO,
|
ScanOption: uldaq.ScanOption = uldaq.ScanOption.DEFAULTIO,
|
||||||
AInScanFlag: uldaq.AOutScanFlag = uldaq.AOutScanFlag.DEFAULT,
|
AOutScanFlag: uldaq.AOutScanFlag = uldaq.AOutScanFlag.DEFAULT,
|
||||||
) -> Array[c_double]:
|
):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
@ -92,6 +89,7 @@ class Repos:
|
|||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
Array[c_double]
|
Array[c_double]
|
||||||
|
ao_device
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@ -101,7 +99,6 @@ class Repos:
|
|||||||
log.debug(f"Created C_double data {data_analog_output}")
|
log.debug(f"Created C_double data {data_analog_output}")
|
||||||
ao_device = self.daq_device.get_ao_device()
|
ao_device = self.daq_device.get_ao_device()
|
||||||
ao_info = ao_device.get_info()
|
ao_info = ao_device.get_info()
|
||||||
ao_device.set_trigger
|
|
||||||
|
|
||||||
err = ao_device.a_out_scan(
|
err = ao_device.a_out_scan(
|
||||||
channels[0],
|
channels[0],
|
||||||
@ -110,22 +107,31 @@ class Repos:
|
|||||||
int(len(data)),
|
int(len(data)),
|
||||||
samplerate,
|
samplerate,
|
||||||
ScanOption,
|
ScanOption,
|
||||||
AInScanFlag,
|
AOutScanFlag,
|
||||||
data_analog_output,
|
data_analog_output,
|
||||||
)
|
)
|
||||||
ao_device.scan_wait(uldaq.WaitType.WAIT_UNTIL_DONE, 11)
|
log.info(f"The actual scan rate was {err}")
|
||||||
|
# ao_device.scan_wait(uldaq.WaitType.WAIT_UNTIL_DONE, 11)
|
||||||
|
|
||||||
return data_analog_output
|
return data_analog_output, ao_device
|
||||||
|
|
||||||
def digital_trigger(self, portn):
|
|
||||||
|
|
||||||
|
def digital_trigger(self, portn: int = 0, data: int = 1) -> None:
|
||||||
|
log.info(f"{self.daq_device}")
|
||||||
dio_device = self.daq_device.get_dio_device()
|
dio_device = self.daq_device.get_dio_device()
|
||||||
dio_device.d_bit_out(uldaq.DigitalPortType.FIRSTPORTA, bit_number=portn, data=1)
|
|
||||||
|
dio_device.d_config_bit(
|
||||||
|
uldaq.DigitalPortType.AUXPORT, portn, uldaq.DigitalDirection.OUTPUT
|
||||||
|
)
|
||||||
|
|
||||||
|
dio_device.d_bit_out(uldaq.DigitalPortType.AUXPORT, bit_number=portn, data=data)
|
||||||
|
|
||||||
def disconnect_dac(self):
|
def disconnect_dac(self):
|
||||||
self.daq_device.disconnect()
|
self.daq_device.disconnect()
|
||||||
self.daq_device.release()
|
self.daq_device.release()
|
||||||
|
|
||||||
|
def clean_up():
|
||||||
|
pass
|
||||||
|
|
||||||
def run_repo(self) -> None:
|
def run_repo(self) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user