12-10-2008 02:19 PM
I wonder whether it is the way I declare the callback function in visual C++ is wrong. I declear the callback function in the dialog head file as static function:
static int32 CVICALLBACK EveryNCallback(TaskHandle taskHandle, int32 everyNsamplesEventType, uInt32 nSamples, void *callbackData);
static int32 CVICALLBACK DoneCallback(TaskHandle taskHandle, int32 status, void *callbackData);
Then implement them in the .cpp file as
static int32 EveryNCallback(TaskHandle taskHandle, int32 everyNsamplesEventType, uInt32 nSamples, void *callbackData)
{
...
}
Is this correct?
12-10-2008 02:56 PM
12-10-2008 03:04 PM
David,
Thank you very much for your reply! I found the error. But I get this error messge now:
Measurements:DAQmx Every N samples Event is not supported within non-buffered tasks. To receive every N samples event notifications, configure your task to use buffering.
Task name:connection.
Here is how I create the task:
TaskHandle taskHandle=0;
DAQmxErrChk(DAQmxCreateTask ("Connection", &taskHandle));
DAQmxErrChk(DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai0,Dev1/ai1","",DAQmx_Val_Cfg_Default,-10.0,10.0,DAQmx_Val_Volts,NULL));
DAQmxErrChk (DAQmxRegisterEveryNSamplesEvent(taskHandle,DAQmx_Val_Acquired_Into_Buffer,1000,0,EveryNCallback,NULL));
DAQmxErrChk (DAQmxRegisterDoneEvent(taskHandle,0,DoneCallback,NULL));
DAQmxErrChk (DAQmxStartTask(taskHandle));
I can't see where is wrong. How to configure the task to use buffering?
12-10-2008 03:27 PM
This is how I define the callback function:
static int32 CVICALLBACK EveryNCallback(TaskHandle taskHandle, int32 everyNsamplesEventType, uInt32 nSamples, void *callbackData)
{
int32 error=0;
char errBuff[2048]={'\0'};
static int totalRead=0;
int32 read=0;
float64 data[1000];
FILE *datafile;
int i;
datafile = fopen("myfile.xls","w+");
if( datafile == NULL )
printf( "The file 'data' was not opened\n" );
else
printf( "The file 'data' was opened\n" );
/*********************************************/
// DAQmx Read Code
/*********************************************/
DAQmxErrChk(DAQmxReadAnalogF64(taskHandle,1000,-1,DAQmx_Val_GroupByChannel,data,2000,&read,NULL));
printf("data number: %d\n",read);
if( read>0 ) {
for (i=0;i<2000;i++)
{
fprintf(datafile,"%f\n",data[i]);
}
fflush(stdout);
}
if( read>0 ) {
printf("Acquired %d samples. Total %d\r",read,totalRead+=read);
printf("Data : %f", data[2]);
fflush(stdout);
}
Error:
if( DAQmxFailed(error) ) {
DAQmxGetExtendedErrorInfo(errBuff,2048);
/*********************************************/
// DAQmx Stop Code
/*********************************************/
DAQmxStopTask(taskHandle);
DAQmxClearTask(taskHandle);
printf("DAQmx Error: %s\n",errBuff);
}
return 0;
}
12-11-2008 01:22 PM
Hi kgy,
You are correct that the DAQmxRegisterEveryNSamplesEvent is only compatible with buffered operations, as the event will be sent when the device sends a specified amount of samples to the buffer. Buffering means that you must configure your task to use a sample clock such that you will be acquiring samples based on hardware-timing rather than software calls. To configure a sample clock, you must simply call the DAQmxCfgSampClkTiming function. With this function, you will set the rate of your acquisition and other parameters of the sample clock to use, in addition to whether you will be doing a finite or continuous acquisition. Generally, you would call this function immediately after creating the channel. I also saw in an above post that you ran the Cont Acq Voltage-Int Clk example, which uses the internal clock to do a buffered acquisition. Thus, you should be able to examine that program to see how the sample clock is configured. Hope this helps,
12-13-2008 05:01 PM