diff --git a/pyrelacs/devices/mccdac.py b/pyrelacs/devices/mccdac.py index fb74764..93d3bca 100644 --- a/pyrelacs/devices/mccdac.py +++ b/pyrelacs/devices/mccdac.py @@ -12,13 +12,32 @@ log = config_logging() class MccDac: + """ + Represents the Digital/Analog Converter from Meassuring Computing. + provides methods for writing and reading the Analog / Digital input and output. + + Connects to the DAC device. + + Attributes + ---------- + daq_device : uldaq.DaqDevice + DaqDevice for handling connecting, releasing and disconnecting + ai_device : uldaq.AiDevice + The Analog input Device + ao_device : + Analog output Device + dio_device : + Digital Input Output + """ + 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: + try: + self.daq_device = uldaq.DaqDevice(devices[0]) + except uldaq.ul_exception.ULException as e: log.error("Did not found daq devices, please connect one") - exit(1) - self.daq_device = uldaq.DaqDevice(devices[0]) + raise e try: self.daq_device.connect() except uldaq.ul_exception.ULException: @@ -30,6 +49,10 @@ class MccDac: log.debug("Connected") def connect_dac(self): + """ + Connecting to the DAQ device + + """ 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: @@ -52,6 +75,40 @@ class MccDac: ScanOption: uldaq.ScanOption = uldaq.ScanOption.DEFAULTIO, AInScanFlag: uldaq.AInScanFlag = uldaq.AInScanFlag.DEFAULT, ) -> Array[c_double]: + """ + Reading the analog input of the DAC device + Creates a c_double Array for storing the acquired data + + Parameters + ---------- + channels : list[int] + channels to read from, provide only two int's in a list (ex [0, 1] or [0, 4]) + for sampling from the range(channel0, channel4) + + duration : int + duration of sampling period + + samplerate : float + samplerate for the duration of sampling + + AiInputMode : uldaq.AiInputMode = uldaq.AiInputMode.SINGLE_ENDED + Contains attributes indicating A/D channel input modes. + Compares to Ground + + Range : uldaq.Range = uldaq.Range.BIP10VOLTS + Range of the output + + ScanOption : uldaq.ScanOption = uldaq.ScanOption.DEFAULTIO + Specific Flags for acuiring the input + + AInScanFlag : uldaq.AInScanFlag = uldaq.AInScanFlag.DEFAULT + Scaling of the data + + Returns + ------- + Array[c_double] + + """ assert len(channels) == 2, log.error("You can only provide two channels [0, 1]") if channels[0] != channels[1]: @@ -85,6 +142,37 @@ class MccDac: ScanOption: uldaq.ScanOption = uldaq.ScanOption.DEFAULTIO, AOutScanFlag: uldaq.AOutScanFlag = uldaq.AOutScanFlag.DEFAULT, ) -> Array[c_double]: + """ + Writes data to the DAC device. + Creates a c_double Array for writing the data + + Parameters + ---------- + data : Union[list, npt.NDArray] + data which should be written to the DAC + + channels : list[int] + channels to read from, provide only two int's in a list (ex [0, 1]) + for sampling from the range(channel0, channel1) + DAC 16 has only 2 output channels + + samplerate : float + samplerate for the duration of sampling + + Range : uldaq.Range = uldaq.Range.BIP10VOLTS + Range of the output + + ScanOption : uldaq.ScanOption = uldaq.ScanOption.DEFAULTIO + Specific Flags for acuiring the input + + AOutScanFlag : uldaq.AOutScanFlag = uldaq.AOutScanFlag.DEFAULT + For Scaling the data + + Returns + ------- + Array[c_double] + """ + assert len(channels) == 2, log.error("You can only provide two channels [0, 1]") buffer = c_double * len(data) @@ -109,7 +197,18 @@ class MccDac: return data_analog_output - def set_analog_to_zero(self, channels: list[int] = [0, 1]): + def set_analog_to_zero(self, channels: list[int] = [0, 1]) -> None: + """ + Sets all analog outputs to zero + + Parameters + ---------- + channels : list[int] + channels to read from, provide only two int's in a list (ex [0, 1]) + for sampling from the range(channel0, channel1) + DAC 16 has only 2 output channels + + """ try: err = self.ao_device.a_out_list( channels[0], @@ -126,14 +225,23 @@ class MccDac: log.error("disconnection dac") self.disconnect_dac() - def diggital_trigger(self) -> None: - data = self.read_bit(channel=0) + def digital_trigger(self, ch: int = 0) -> None: + """ + Digital + + Parameters + ---------- + ch : int + + + """ + data = self.read_bit(channel=ch) if data: - self.write_bit(channel=0, bit=0) + self.write_bit(channel=ch, bit=0) time.time_ns() - self.write_bit(channel=0, bit=1) + self.write_bit(channel=ch, bit=1) else: - self.write_bit(channel=0, bit=1) + self.write_bit(channel=ch, bit=1) def write_bit(self, channel: int = 0, bit: int = 1) -> None: self.dio_device.d_config_bit(