LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

interrupt infinite loop

Hi!

I was wondering if there is a way to interrupt an infinite loop.   I needed the infinite while loop to continuously repeat a statement, however, it freezes all other buttons in the panel (like the exit and reset), nothing can be clicked.

Thank You.


Jem
0 Kudos
Message 1 of 5
(3,988 Views)
I understand there is a ProcessSystemEvents() but how do I incorporate the buttons I want to be active to it? Basically, how do I use it? I tried it by itself and it doesn't do anything.

Thanks,


Jemellie
0 Kudos
Message 2 of 5
(3,983 Views)
Putting the call to ProcessSystemEvents inside your infinite loop should do the trick if I understand your question correctly.
0 Kudos
Message 3 of 5
(3,977 Views)
 int j=1;
while (j=1) {                 
                    // Sends the request qith a delay of five seconds
                       Delay(5);
                       ClientTCPWrite (g_hconversation, &sendData, 4, 1000);
                       MessagePopup("TCP Client", "data sent");
            
                     // Reads the incoming four sets of 4-bytes of information
                       dataSize = sizeof(data_formatted);
                       ClientTCPRead (g_hconversation, &data_formatted, 16, 1000);
                       //SetCtrlVal (PANEL, PANEL_hands, dataSize);
                 
                        siftedData = data_formatted[0];
                       newSiftedData = my_ntohl(siftedData);
                       Ksifted = newSiftedData/1000;
                      PlotStripChart (PANEL, PANEL_SIFTED, &Ksifted, 1, 0, 0,
                                VAL_UNSIGNED_INTEGER);
                         //var = (int)siftedData;
                         SetCtrlVal (PANEL, PANEL_SIFTEDNUMBER, Ksifted);


                         ProcessDrawEvents();
                         ProcessSystemEvents();
                     }

This still doesn't do it! All the other buttons in the user interface is not active.  Nothing can be done on any other thing in the user interface.
0 Kudos
Message 4 of 5
(3,971 Views)

Well, your loop is completely asymmetric: you have a great "blind" Delay and the rest of code which is executed in a few miliseconds! Additionally, the condition to exit from the loop must be catchable in the loop callback, that is your "j" variable must be global to both this function and at least the stop button callback function. An alternative to this is to use a toggle button as the stop button, with no callback associated to it, then substitute the Delay with something like this:

int      stop;
double  tini;

while (1) {
  tini = Timer ();
  while (Timer () - tini < 5.0) {
     ProcessSystemEvents ();
     GetCtrlVal (panelHandle, PANEL_STOPBUTTON, &stop);
     if (stop) break;    // Exit the pause loop
  }
  if (stop) break;    // Exit the test loop

  // you code goes here

}

As a side note, I point you to a possible typo in your code:

while (j=1) actually assigns the valueof 1 to j variable! You should use while (j==1) instead.


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 5 of 5
(3,954 Views)