Atos
2008-08-13 12:40:22 UTC
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:
#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: