Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

continuous data acquisition, visual c, excel

 I try the ANSI C Example program:   ContAcq-IntClk.c. Everything is fine.

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? 

0 Kudos
Message 11 of 16
(4,827 Views)

These articles seem to indicate there is not much you have to change going from the C examples to VC++. Have you tried checking out MSDN for examples of C++ callbacks and how to use them?

 

 

With warm regards,

David D.
0 Kudos
Message 12 of 16
(4,823 Views)

 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?

0 Kudos
Message 13 of 16
(4,822 Views)

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;

}

0 Kudos
Message 14 of 16
(4,819 Views)

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,

 

Daniel S.
National Instruments
0 Kudos
Message 15 of 16
(4,794 Views)
Thank you very much! This problem has been solved.
0 Kudos
Message 16 of 16
(4,775 Views)