08-08-2011 12:20 PM - edited 08-08-2011 12:28 PM
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,
08-09-2011 05:29 PM
Hi Simon,
So it works now that you have added the interrupt?
~kgarrett
08-09-2011 06:13 PM
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
08-10-2011 05:25 PM
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