Discussion:
DAQmxBase Acquiring at high frequency
(too old to reply)
Atos
2008-08-13 12:40:22 UTC
Permalink
Hi everyone, Part of my job is to acquire continously on multiple channels using NIDAQmxBase. As I faced problems in my application I decide to work with the provided examples but I doesn't succeed to make them work. Here are my needs :12 Channels48000 Hertz Here is my code (contAcquireNChan.c with a few modifications): #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, Dev1/ai1";
    char        chan[] = "Dev1/ai0, Dev1/ai1, Dev1/ai2, Dev1/ai3, Dev1/ai4, Dev1/ai5, Dev1/ai6, Dev1/ai7, Dev1/ai8, Dev1/ai9, Dev1/ai10, Dev1/ai11";
    float64     min = -10.0;
    float64     max = 10.0;

    // Timing parameters
    char        clockSource[] = "OnboardClock";
    uInt64      samplesPerChan = 1000;
    float64     sampleRate = 48000.0;

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


    printf("Press Ctrl-C to exit\n");
    DAQmxErrChk (DAQmxBaseCreateTask("",&taskHandle));
    DAQmxErrChk (DAQmxBaseCreateAIVoltageChan(taskHandle,chan,"",DAQmx_Val_Cfg_Default,min,max,DAQmx_Val_Volts,NULL));
    DAQmxErrChk (DAQmxBaseCfgSampClkTiming(taskHandle,clockSource,sampleRate,DAQmx_Val_Rising,DAQmx_Val_ContSamps,samplesPerChan));
    DAQmxErrChk (DAQmxBaseCfgInputBuffer(taskHandle,144000));     DAQmxErrChk (DAQmxBaseStartTask(taskHandle));

    // The loop will quit after 10 seconds
    printf ("Acquisition starting\n");

    startTime = time(NULL);
    while( time(NULL)<startTime+50 ) {
        DAQmxErrChk (DAQmxBaseReadAnalogF64(taskHandle,pointsToRead,timeout,DAQmx_Val_GroupByScanNumber,data,bufferSize*12,&pointsRead,NULL));
        totalRead += pointsRead;
        printf("Acquired %d samples. Total %d\n",pointsRead,totalRead);
        // Just print out the first 10 points of the last data read
        for (i = 0; i < 10; ++i)
            printf ("data0[%d] = %f\tdata1[%d] = %f\n",i,data[2*i],i,data[2*i+1]);

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

Error:
Atos
2008-08-13 12:40:22 UTC
Permalink
A few more informations (forgotten) : I run on linux (RHEL4 and RHEL5)I tried on two differents machines (PentiumD 2.8Ghz, 1Go RAM  and C2D 3GHz, 2Go RAM) The approximately same code works with NIDAQmx (but this last isn't supported on RHEL5 that's the reason why I try NIDAQmxBase)
R_Duval
2008-08-14 16:10:11 UTC
Permalink
Hi Sylvain. Could you send us a screen of the error message?Thanks in advance. Regards.
Loading...