Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading mutiple channels with DAQmxBaseReadAnalogF64

I am trying to read 1 sample from two different analog inputs on a USB6009 device. I tried doing a very simple modification to the acquire1Scan.c example but the second channel is not being read. Am I doing something wrong here. I think I highlighted all the changes I made to the example.

    // Task parameters
    int32       error = 0;
    TaskHandle  taskHandle = 0;
    char        errBuff[2048]={'\0'};

    // Channel parameters
    char        chan[] = "Dev1/ai0:1";
    float64     min = -10.0;
    float64     max = 10.0;

    // Timing parameters
    uInt64      samplesPerChan = 1;

    // Data read parameters
    float64     data[2];
    int32       pointsToRead = 1;
    int32       pointsRead;
    float64     timeout = 10.0;


    DAQmxErrChk (DAQmxBaseCreateTask("",&taskHandle));
    DAQmxErrChk (DAQmxBaseCreateAIVoltageChan(taskHandle,chan,"",DAQmx_Val_RSE,min,max,DAQmx_Val_Volts,NULL));
    DAQmxErrChk (DAQmxBaseStartTask(taskHandle));
    DAQmxErrChk (DAQmxBaseReadAnalogF64(taskHandle,pointsToRead,timeout,DAQmx_Val_GroupByChannel,data,samplesPerChan,&pointsRead,NULL));

    printf ("Acquired reading: %f, %f\n", data[0], data[1]);

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

0 Kudos
Message 1 of 2
(2,833 Views)
Well, I solved my own problem. The example acquire1Scan.c is incorrect or at least is misleading with the chosen variable names. The sixth input argument to DAQmxBaseReadAnalogF64 is called samplesPerChan in the example, but if you look at the documentation for the function, this is actually arraySizeInSamps.

You might want to correct this!


0 Kudos
Message 2 of 2
(2,817 Views)