def AI_start_delay(device_name): if 'PFI0' not in DAQmxGetDevTerminals(device_name): return None task = Task() clock_terminal = '/' + device_name + '/PFI0' rate = DAQmxGetDevAIMaxSingleChanRate(device_name) Vmin, Vmax = DAQmxGetDevAIVoltageRngs(device_name)[0:2] num_samples = 1000 chan = device_name + '/ai0' task.CreateAIVoltageChan(chan, "", c.DAQmx_Val_RSE, Vmin, Vmax, c.DAQmx_Val_Volts, None) task.CfgSampClkTiming("", rate, c.DAQmx_Val_Rising, c.DAQmx_Val_ContSamps, num_samples) task.CfgDigEdgeStartTrig(clock_terminal, c.DAQmx_Val_Rising) start_trig_delay = float64() delay_from_sample_clock = float64() sample_timebase_rate = float64() task.GetStartTrigDelay(start_trig_delay) task.GetDelayFromSampClkDelay(delay_from_sample_clock) task.GetSampClkTimebaseRate(sample_timebase_rate) task.ClearTask() total_delay_in_ticks = start_trig_delay.value + delay_from_sample_clock.value total_delay_in_seconds = total_delay_in_ticks / sample_timebase_rate.value return total_delay_in_seconds
def AI_start_delay(device_name): """Empirically determines the analog inputs' start delay. Args: device_name (str): NI-MAX device name Returns: float: Analog input start delay in seconds. `None` if analog inputs not supported. """ if 'PFI0' not in DAQmxGetDevTerminals(device_name): return None task = Task() clock_terminal = '/' + device_name + '/PFI0' rate = DAQmxGetDevAIMaxSingleChanRate(device_name) Vmin, Vmax = DAQmxGetDevAIVoltageRngs(device_name)[0:2] num_samples = 1000 chan = device_name + '/ai0' supp_types = DAQmxGetPhysicalChanAITermCfgs(chan) if supp_types & c.DAQmx_Val_Bit_TermCfg_RSE: input_type = c.DAQmx_Val_RSE elif supp_types & c.DAQmx_Val_Bit_TermCfg_Diff: input_type = c.DAQmx_Val_Diff elif supp_types & c.DAQmx_Val_Bit_TermCfg_PseudoDIFF: input_type = c.DAQmx_Val_PseudoDiff task.CreateAIVoltageChan( chan, "", input_type, Vmin, Vmax, c.DAQmx_Val_Volts, None ) task.CfgSampClkTiming( "", rate, c.DAQmx_Val_Rising, c.DAQmx_Val_ContSamps, num_samples ) task.CfgDigEdgeStartTrig(clock_terminal, c.DAQmx_Val_Rising) start_trig_delay = float64() delay_from_sample_clock = float64() sample_timebase_rate = float64() try: task.GetStartTrigDelay(start_trig_delay) except PyDAQmx.DAQmxFunctions.AttributeNotSupportedInTaskContextError: # device does not have a Start Trigger Delay property # is likely a dynamic signal acquisition device with filter # delays instead. start_trig_delay.value = 0 try: task.GetDelayFromSampClkDelay(delay_from_sample_clock) except PyDAQmx.DAQmxFunctions.AttributeNotSupportedInTaskContextError: # seems simultaneous sampling devices do not have this property, # so assume it is zero delay_from_sample_clock.value = 0 task.GetSampClkTimebaseRate(sample_timebase_rate) task.ClearTask() total_delay_in_ticks = start_trig_delay.value + delay_from_sample_clock.value total_delay_in_seconds = total_delay_in_ticks / sample_timebase_rate.value return total_delay_in_seconds