Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

call DAQmxRegisterEveryNSamplesEvent in managed code

Ciao to all,

I'm integrating the example Cont Acq-Int Clk in my windows form written in Visual C++.

private: System::Void button1_Click(System::Objectsender, System::EventArgse) {

 

	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {

				 int32       error=0;
				 TaskHandle  taskHandle=0;
				 char        errBuff[2048]={'\0'};

				 /*********************************************/
				 // DAQmx Configure Code
				 /*********************************************/
				 DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
				 DAQmxErrChk (DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai0","",DAQmx_Val_Cfg_Default,-10.0,10.0,DAQmx_Val_Volts,NULL));
				 DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,"",10000.0,DAQmx_Val_Rising,DAQmx_Val_ContSamps,1000));

				 DAQmxErrChk (DAQmxRegisterEveryNSamplesEvent(taskHandle,DAQmx_Val_Acquired_Into_Buffer,1000,0,EveryNCallback,NULL));
				 DAQmxErrChk (DAQmxRegisterDoneEvent(taskHandle,0,DoneCallback,NULL));

				 /*********************************************/
				 // DAQmx Start Code
				 /*********************************************/
				 DAQmxErrChk (DAQmxStartTask(taskHandle));

	Error:
				 if( DAQmxFailed(error) )
					 DAQmxGetExtendedErrorInfo(errBuff,2048);
				 if( taskHandle!=0 ) {
					 /*********************************************/
					 // DAQmx Stop Code
					 /*********************************************/
					 DAQmxStopTask(taskHandle);
					 DAQmxClearTask(taskHandle);
				 }
				 if( DAQmxFailed(error) )
					 MessageBox::Show("DAQmx Error");
				 
				 

			 }
			 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];

				 /*********************************************/
				 // DAQmx Read Code
				 /*********************************************/
				 DAQmxErrChk (DAQmxReadAnalogF64(taskHandle,1000,10.0,DAQmx_Val_GroupByScanNumber,data,1000,&read,NULL));
				 if( read>0 ) {
					 //printf("Acquired %d samples. Total %d\r",read,totalRead+=read);
					 fflush(stdout);
				 }

Error:
				 if( DAQmxFailed(error) ) {
					 DAQmxGetExtendedErrorInfo(errBuff,2048);
					 /*********************************************/
					 // DAQmx Stop Code
					 /*********************************************/
					 DAQmxStopTask(taskHandle);
					 DAQmxClearTask(taskHandle);
					 MessageBox::Show("DAQmx Error");
				 }
				 return 0;
			 }

			 int32 CVICALLBACK DoneCallback(TaskHandle taskHandle, int32 status, void *callbackData)
			 {
				 int32   error=0;
				 char    errBuff[2048]={'\0'};

				 // Check to see if an error stopped the task.
				 DAQmxErrChk (status);

Error:
				 if( DAQmxFailed(error) ) {
					 DAQmxGetExtendedErrorInfo(errBuff,2048);
					 DAQmxClearTask(taskHandle);
					 MessageBox::Show("DAQmx Error");
				 }
				 return 0;
			 }

 Now, the methods

DAQmxRegisterEveryNSamplesEvent  and     DAQmxRegisterDoneEvent   must to be called as _cdecl  ..   so unmanaged code!  

How can I call this methods in my windows form  (managed code) ?

 

 
0 Kudos
Message 1 of 2
(5,116 Views)

Here you can fing the entire project 

 

https://github.com/Seio/GUIVS2012ReadDAQ

0 Kudos
Message 2 of 2
(5,093 Views)