LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

for loop freezing the system

Hi,

 

I need some help here. I am running a system based on the Duration;

I am starting by getting the test_duration first  and I am using a for loop to stop the system based on the test duration specified.

 

But the for loop is freezing the panel. I cannot do any thing on the panel (like resetting.... no other button works) until the for loop completes.

 

could someone help me here. I don't want the for loop to freeze the panel.

 

Thank you.

 

 

 

 void runTest (int h1, int s1, int p1)

{
       double startTime, endTime;
       int i;
       int duration;
       int x = 2;

 

         GetCtrlVal (panelHandle, PANEL_TEST_DURATION , &test_duration);
         

         startTime = Timer();

   

         startSystem(); //start the system


        SetCtrlVal (panelHandle, PANEL_LED_TR, 1);
       

 

 

       for (i=0; i<test_duration; i++)
            {
               Delay (2);
 
               endTime = Timer();
               duration = endTime - startTime;
   

                if (duration == x)
  
                  {   
                       displayMessages ();
                       x+=2;
  
                 }
          }

 

  stopSystem();
  SetCtrlVal (panelHandle, PANEL_LED_TR, 0);
 

}

0 Kudos
Message 1 of 3
(3,011 Views)

Hi agyna, this is the behaviour you can expect! The fact is that your loop is not processing user interface events, so you are not able to manipulate the UIR and have events fired. You should put a ProcessSystemEvents inside the loop in order to have events processed. Moreover, the main time in your loop is spent into Delay () functon, so you should rewrite the code replacing that instruction with a small loop that processes events.

Take a look at this discussion that examines a situation very similar to yours and make also a search in the forum for ProcessSystemEvents: you will find a lot of useul threads that discuss similar situations and give alternative solutions to them.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 3
(3,007 Views)

Thanks Roberto for the suggestions.

0 Kudos
Message 3 of 3
(3,002 Views)