01-23-2010 01:21 PM - edited 01-23-2010 01:27 PM
Hi,
I met a problem when I was debugging my C++ driving program for a PCIe6361 DAQ card. Could you please help me out?
The application we need is to acquire retriggerable analog input signals for a given number of cycles. According to your example program available online, I managed to achieve this goal: the functioning parts have already worked pretty normal in reading all the data out into the outStream, which could later be saved.
However, I found that the program got stuck at the function "RemoveAllEventHandlers()" when I attempted to stop the task. The function won't accomplish its work, and keeps the process running forever. I remember this function worked perfectly well when I tested it for a simple start-triggerred task. Therefore, I was thinking whether it is the sequence of my "stop the process" functions that result in this problem. I've tried varying the sequence, but no improvement yet. I am wondering whether it could be a systematic bug within the internal operation of the card, or I've missed some important steps during stop process.
The essential parts of the program are posted as below, please advise me of what to do! Thanks a lot!
Wei
Solved! Go to Solution.
01-23-2010 01:26 PM - edited 01-23-2010 01:26 PM
// <**Functioning Sections **> -- Set up task and reader
m_AItask = std::auto_ptr<CNiDAQmxTask>(new CNiDAQmxTask("AI_task"));
m_COtask = std::auto_ptr<CNiDAQmxTask>(new CNiDAQmxTask("CO_task"));
m_AItask->AIChannels.CreateVoltageChannel(...);
m_COtask->COChannels.CreatePulseChannelFrequency( ... );
m_COtask->Triggers.StartTrigger.ConfigureDigitalEdgeTrigger( ... );
m_COtask->Triggers.StartTrigger.SetRetriggerable(true);
m_AItask->Timing.ConfigureSampleClock(...);
m_COtask->Timing.ConfigureImplicit(...);
m_AItask->Control(DAQmxTaskVerify);
m_COtask->Control(DAQmxTaskVerify);
m_reader = std::auto_ptr<CNiDAQmxAnalogMultiChannelReader>
(new CNiDAQmxAnalogMultiChannelReader(m_AItask->Stream));
m_reader->InstallEventHandler(*this, &CConAcqVoltageSamplesAveragerDlg::OnEvent);
m_COtask->Start();
SetTimer(1, 2000, NULL);
m_reader->ReadMultiSampleAsync(m_samples, m_data, NULL);
// <**Stopping the task**> -- remove task and reader after the given cycles have been finished
CWaitCursor wait;
RemoveEventHandler();
CleanUpIfNecessary();
m_start.SetFocus();
KillTimer(1);
m_COtask->Stop();
m_AItask->Stop();
DimControls(false);
// Codes for RemoveEvent Handler(), which are the same as examples given in the driver CD.
void CConAcqVoltageSamplesAveragerDlg::RemoveEventHandler()
{
if(m_reader.get())
{
m_taskRunning = false;
while(!m_reader->RemoveAllEventHandlers()) //<----- Stuck at this point during debugging
{
::Sleep(100);
MSG msg;
while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
}
01-25-2010 01:27 PM
I think you are missing clearing the DAQmx tasks. From the example is the following code:
DAQmxStopTask(analogTask);
DAQmxClearTask(analogTask);
DAQmxStopTask(counterTask);
DAQmxClearTask(counterTask);
You seem to only have the stop tasks.
01-25-2010 01:36 PM
Thanks a lot for your reply!
Should I clear up the task before RemoveAllEventHandlers() ?
My program got suck at RemoveAllEventHandlers() before I stopped the task by m_AItask->stop(). That's why I doubt the effectiveness of this function.
Thanks again!
Wei
01-26-2010 12:30 PM
BTW: I didn't find the operator as you mentioned in your post.
I am using VS C++ 2003. What is the corresponding operator to clear up the task?
I've tried to locate it, but I didn't find anything close in the CNiDAQmxTask Class. Thanks!
Wei
01-27-2010 11:11 AM
That was my fault, I didn't notice the Remove Handler was before the stop. Do you know if its getting stuck in that while loop (ie. is the condition !m_reader->... not changing? Or is another error being thrown.
What could be happening is that a trigger is never coming in, because that is the event that is setup on m_reader. Also, are you having a message display in that remove event while loop, that might be useful.
If this is in fact a situation with the trigger not coming in, go ahead and try this with simulated hardware, which will automatically generate triggers and should bypass that problem. That will tell us if the problem is with the trigger or something else.
01-28-2010 12:50 PM - edited 01-28-2010 12:52 PM
Thanks a lot for your reply!
I tried some of the idea these days, but still none of them seems to be the case. Fortunately, my colleague mentioned that there are some sections in the help of "measure studio" talking about "InstallEventHandler". I realize that in terms of running RemoveEventHandler(), I actually include the "RemoveAllEventHandler()" and "m_task->stop()" insdie the OnEvent(), which seems to violate the rules. I've then clear it up, and the program returns to normal.
Thanks a lot again!
Wanchun