Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Analog reference trigger error using NI-DAQmx Base C API

Hi all

I can't get an analog reference trigger to work using the NI-DAQmx Base 3.0 C API.  I am using a USB-6008 on Windows XP.  I have an analog voltage source connected to AI0 that I want to use as a trigger, and then sample that same input.  Please see code below.  When compiled and run, this code yields the error "Value passed to the Task/Channels In control is invalid." when it gets to DAQmxBaseCfgAnlgEdgeRefTrig(). What string to I need to pass to this function to get it to trigger on AI0? 

 

I have tried using other channel names in DAQmxBaseCfgAnlgEdgeRefTrig(), including "/Dev/ai0" (leading slash), all-caps versions, /Dev/PFI0 (just to see if it would run, not because I want to use PFI0 to trigger), and everything gives the same error.  Help is much appreciated.  Code below.

Thanks

Andrew 

 

#include "NIDAQmxBase.h"
#include <stdio.h>
#include <time.h>

#define DAQmxErrChk(functionCall) { if( DAQmxFailed(error=(functionCall)) ) { goto Error; } }


int main(int argc, char *argv[])
{
    // Task parameters
    int32       error = 0;
    TaskHandle  taskHandle = 0;
    char        errBuff[2048]={'\0'};
    int32       i,j;
    time_t      startTime;
    bool32      done=0;

    // Channel parameters
    char        chan[] = "Dev1/ai0";
    float64     min = -1.0;//volts
    float64     max = 4.0;//volts

    // Timing parameters
    char        clockSource[] = "OnboardClock";
    float64     sampleRate = 100.0; //per second
    float64        triggerLevel = 2.0; //volts
    int32        preTriggerSamples = sampleRate/2; // half a second's worth of samples
    uInt64        numSamples = 2*preTriggerSamples; // total number of samples (includes pre-trigger)

    // Data read parameters
    #define     bufferSize (uInt32)1000
    float64     data[bufferSize * 2];
    int32       pointsToRead = bufferSize;
    int32       pointsRead;
    float64     timeout = 10.0;
    int32       totalRead = 0;


    printf("Press Ctrl-C to exit\n");
    DAQmxErrChk (DAQmxBaseCreateTask("",&taskHandle));
    printf("Configuring AnalogInput Channel\n");
    DAQmxErrChk (DAQmxBaseCreateAIVoltageChan(
        taskHandle,
        chan,
        NULL, //name to give channel -- not supported by API
        DAQmx_Val_Cfg_Default,
        min,
        max,
        DAQmx_Val_Volts,
        NULL
    ));
    printf("Configuring Sample Clock\n");
    DAQmxErrChk (DAQmxBaseCfgSampClkTiming(
        taskHandle,
        clockSource,
        sampleRate,
        DAQmx_Val_Rising,
        DAQmx_Val_FiniteSamps,
        numSamples//total number of samples to acquire
    ));
    printf("Configuring Analog Reference Trigger\n");
    DAQmxErrChk (DAQmxBaseCfgAnlgEdgeRefTrig (
        taskHandle,
        chan, //channel to trigger on
        DAQmx_Val_FallingSlope, //edge to trigger on
        triggerLevel,
        preTriggerSamples
    ));

    printf("Configuring input buffer\n");
    DAQmxErrChk (DAQmxBaseCfgInputBuffer(taskHandle,2*numSamples)); //configure a buffer twice as large as we will need

    // start monitoring
    while( 1 ) {
        printf("Monitoring...\n");
        DAQmxErrChk (DAQmxBaseStartTask(taskHandle));
        DAQmxErrChk (DAQmxBaseReadAnalogF64(
            taskHandle,
            pointsToRead,
            timeout,
            DAQmx_Val_GroupByScanNumber,
            data,
            bufferSize*2,
            &pointsRead,
            NULL
        ));
        DAQmxErrChk (DAQmxBaseStopTask(taskHandle));
        totalRead += pointsRead;
        printf("Trigger\n");

    }
    printf("\nAcquired %d total samples.\n",totalRead);

Error:
    if( DAQmxFailed(error) )
        DAQmxBaseGetExtendedErrorInfo(errBuff,2048);
    if(taskHandle != 0) {
        DAQmxBaseStopTask (taskHandle);
        DAQmxBaseClearTask (taskHandle);
    }
    if( DAQmxFailed(error) )
        printf("DAQmxBase Error: %s\n",errBuff);
    return 0;
}

0 Kudos
Message 1 of 3
(3,751 Views)

Hello,

 

This is not limitation of the DAQmx Base driver or even the DAQmx driver.  The USB-6008 can only do software or digital Start triggers.  The Digital Reference Trigger will not be an option with this hardware.  Please let me know if you have any questions or concerns.  Please look to the linked USB-6008 User Guide and Specificatons digital trigger section on page 20. 

 

Samantha

Application Engineering

National Instruments

http://www.ni.com/support/

Samantha
National Instruments
Applications Engineer
0 Kudos
Message 2 of 3
(3,724 Views)
Ha!  Thanks for pointing that out.  I received the device from a friend and was not aware it didn't support all of the API functionality. 
0 Kudos
Message 3 of 3
(3,722 Views)