01-03-2006 04:52 AM
01-03-2006 10:43 AM
01-03-2006 11:39 AM
Thanks a lot John for this remarks and your kindness; I am new to this kind of list, and I was a little lost to post my message.
I am working on a Linux redhat PC, using a gcc compiler. My OS is not specified as supported, but I installed the
driver without any issue, and the code /usr/local/natinst/nidaqmxbase/examples/ai/contAcquireNChan.c works fine.
The slittly modified code that does not work is the following :
// Timing parameters
char clockSource[] = "OnboardClock";
//uInt64 samplesPerChan = 1000;
float64 sampleRate = 250.0;//5000.0;
// Data read parameters
#define bufferSize (uInt32)1000
float64 data[bufferSize];
//int32 pointsToRead = bufferSize;
int32 pointsRead;
float64 timeout = 10.0;
int32 totalRead = 0;
// test
FILE *testfile;
if ((testfile = (FILE *)fopen("/srv/gxre-napp3/vol4/soubeel/to/tmp/ecg.txt","w"))==NULL) {
fprintf(stderr,"cannot open test file");
exit(-1); }
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,));
DAQmxErrChk (DAQmxBaseCfgInputBuffer(taskHandle,100000)); //use a 100,000 sample DMA buffer
DAQmxErrChk (DAQmxBaseStartTask(taskHandle));
// The loop will quit after 10 seconds
startTime = time(NULL);
while( time(NULL)<startTime+10 ) {
DAQmxErrChk (DAQmxBaseReadAnalogF64(taskHandle,-1/*pointsToRead*/,timeout,DAQmx_Val_GroupByScanNumber,data,bufferSize,&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 <pointsRead ; ++i)
fprintf (testfile,"%f\n",data[i]);
}
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;
01-03-2006 12:02 PM
01-03-2006 01:39 PM
Hi All-
I second John's suggestion to explicitly set the number of samples to what you expect; the "-1" setting for samples to read does not function properly in NI-DAQmx Base. The most common behavior is that exactly two samples are returned, and this seems to be exactly what you're seeing in your app.
Hopefully this helps-
01-03-2006 02:24 PM
Tom and John,
Thanks a lot for your help; I was thinking I was making a stupid mistake somewhere...(It is a pitty that the -1 not working is not in the README file of the DAQmx Base driver).
My goal is to read values and analyse them as real time as possible. The problem is that if I read them 5 by 5 at a frequency of 250Hz,
it takes time to read the values, and I will be more and more late compare to the current acquired values. I guess the only choice that I
have is to store the "system time" before the acquisition, then before the next acquisition, and compute how many samples have been acquired in between, knowning the sample rate of the acquisition.
Any other suggestion using the DAQmx Base C functions ?
Thanks again for this precious help,
Elisabeth
01-03-2006 02:48 PM
01-04-2006 06:41 AM
Thanks a lot John, for this all lot of information.
I am working on a linux PC with an USB6008, so I think I cannot switch to DAQmx driver.
So I will keep the DAQmx Base, and try out your suggested solution.
Thanks a lot again and Happy new year !
Elisabeth
01-05-2006 06:27 AM
John, I tried your suggestion but it does not work. The code is the following :
float64 sampleRate = 250.0;//5000.0;
// Data read parameters
#define bufferSize (uInt32)1000
float64 data[bufferSize];
int32 pointsToRead = bufferSize;
int32 pointsRead;
float64 timeout = 0.1;
int32 totalRead = 0;
// test
FILE *testfile;
if ((testfile = (FILE *)fopen("/srv/gxre-napp3/vol4/soubeel/to/tmp/ecg.txt","w"))==NULL) {
fprintf(stderr,"cannot open test file");
exit(-1); }
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,pointsToRead));
DAQmxErrChk (DAQmxBaseCfgInputBuffer(taskHandle,100000)); //use a 100,000 sample DMA buffer
DAQmxErrChk (DAQmxBaseStartTask(taskHandle));
// The loop will quit after 10 seconds
startTime = time(NULL);
while( time(NULL)<startTime+10 ) {
sleep(1);
error = DAQmxBaseReadAnalogF64(taskHandle,pointsToRead,timeout,DAQmx_Val_GroupByScanNumber,data,bufferSize,&pointsRead,NULL);
if( DAQmxFailed(error) ) {
DAQmxBaseGetExtendedErrorInfo(errBuff,2048);
printf("DAQmxBase Error: %s, err or code : %d\n",errBuff,error);
}
if(taskHandle != 0) {
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 <pointsRead ; ++i)
fprintf (testfile,"%f\n",data[i]);
}
}
printf("\nAcquired %d total samples.\n",totalRead);
01-05-2006 10:34 AM