Example #1
0
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
def AI_filter_delay(device_name):
    """Determine the filter delay for dynamic signal acquistion devices.

    Returns the delay in clock cycles. Absolute delay will vary with sample rate.
    
    Args:
        device_name (str): NI-MAX device name

    Returns:
        int: Number of analog input delays ticks between task start and acquisition start.
    """
    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_PseudoDiff, 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_filter_delay = float64()
    sample_timebase_rate = float64()

    # get delay in number of clock samples
    task.SetAIFilterDelayUnits("", c.DAQmx_Val_SampleClkPeriods)

    task.GetAIFilterDelay("", start_filter_delay)
    task.GetSampClkTimebaseRate(sample_timebase_rate)

    task.ClearTask()

    return int(start_filter_delay.value)