Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

RemoveAllEventHandler() could NOT terminate the events

Solved!
Go to solution

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

Message Edited by springface on 01-23-2010 01:27 PM
0 Kudos
Message 1 of 7
(7,506 Views)

// <**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);
            }
        }
    }
}

Message Edited by springface on 01-23-2010 01:26 PM
0 Kudos
Message 2 of 7
(7,505 Views)

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.

Doug Farrell
Solutions Marketing - Automotive
National Instruments

National Instruments Automotive Solutions
0 Kudos
Message 3 of 7
(7,477 Views)

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

0 Kudos
Message 4 of 7
(7,474 Views)

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

0 Kudos
Message 5 of 7
(7,451 Views)

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.

Doug Farrell
Solutions Marketing - Automotive
National Instruments

National Instruments Automotive Solutions
0 Kudos
Message 6 of 7
(7,435 Views)
Solution
Accepted by topic author springface

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 

Message Edited by springface on 01-28-2010 12:52 PM
0 Kudos
Message 7 of 7
(7,407 Views)