Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmx example doesn't run in MFC mode

Previously, I made a conversion software based on MFC and works fine with DAQmx codes.

Now I am testing some counter output and it is not running with MFC.

 

	/*
		Testing procedure 8.8.2011
	*/

	//Beginning of testing code: sweeping source output on Pin 49
		
	TaskHandle  testHandle=0;
	int32       i;
	int         error=0;
	float64     dataFreq[1000];
	float64     dataDC[1000];
	float64     initialDelay = 0.0;
	float64     lowTime = 0.0;    //For duty cycle, D = t/T; t: high time, T: period
	float64     highTime = 0.0;

	// Generating data for duty cycle from 0.50 to 0.80 in 1000 steps
	/*
	dutyStep = (DUTY_MAX-DUTY_MIN)/1000;
	for(i=0;i<1000;++i) {
		dataFreq[i] = 1000.0;
		dataDC[i] = DUTY_MIN + dutyStep*i;
	}
	*/
	
	//Overriding
	lowTime = 1.0;
	highTime = 0.5;
		
	for(i=0; i<1000; i++)
	{
		dataFreq[i] = 1000;
		dataDC[i] = 0.1;
	}
	
	/*********************************************/
	// DAQmx Configure Code
	/*********************************************/
	DAQmxErrChk (DAQmxCreateTask("",&testHandle));
	DAQmxErrChk (DAQmxCreateCOPulseChanFreq(testHandle,"Dev1/ctr0","",DAQmx_Val_Hz,DAQmx_Val_Low, initialDelay, lowTime, highTime));
	DAQmxErrChk (DAQmxCfgImplicitTiming(testHandle,DAQmx_Val_ContSamps,1000));
	DAQmxErrChk (DAQmxStartTask(testHandle));//added
	DAQmxErrChk (DAQmxWriteCtrFreq(testHandle,1000,0,10.0,DAQmx_Val_GroupByChannel, dataFreq, dataDC,NULL,NULL));

			

Error:
	if(testHandle != 0){
		CleanUp(error, testHandle);
	}
	//End of testing code: sweeping source output on Pin 49

This is running fine with Visual C++ 6.0 console environment. I connected an oscilloscope on pin 49 of PCI-6025E and check digital pulses; it shows fines pulses.

But if this code is assigned in a button event function in MFC, it is not working. Am I missing something? I added nidaqmx.lib as a library on both.

 

 

Edited: OK, I fixed it...it needs an interrupt.

 

Thanks,

 

0 Kudos
Message 1 of 4
(3,299 Views)

Hi Simon, 

 

So it works now that you have added the interrupt?

 

~kgarrett

District Sales Engineer
0 Kudos
Message 2 of 4
(3,280 Views)

It sounds weird but message handler after the writing function solved the problem. I am not quite good at C++ but wonder it could work with background thread that checks every writing process. It also works when it has an enough time to produce those. I set the timeout around less than 10 msec, it returned a DAQmx timeout error. So there was an immediate timeout when I used with MFC, I guess. That's why it didn't work with a simple button event handler. 

t

0 Kudos
Message 3 of 4
(3,276 Views)

I see-that is very interesting! Thank you for posting what fixed the issue. It is useful for future readers, and for National Instrument Employees for people like you to take the time to post their solutions. Have a great day, and best of luck with the rest of your application!

 

~kgarrett

 

District Sales Engineer
0 Kudos
Message 4 of 4
(3,260 Views)