LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

counting running time back

Hi!

First of all, sorry for the question, maybe it is too easy, but i am still quite a biginner in CVI.
I would like to display in the UIR a counter what counting back, showing how much time left until the process ends.
I have a code similar like this:

           k=......  /*number of elements of a file*/
         
         SetCtrlVal(panelHandle, counter, k);
        
           while(!feof(file) )

         {    .......
             .......
             k--;
          SetCtrlVal(panelHandle, counter, k);
         DisplayPanel;
        }
         
My question is, does the DisplayPanel command make the loop working slower, or is the running time just the same without it?
(without the DisplayPanel the counter doesnt get refreshed)
I am sure there is a much more sofisticated way to see how much time left until the program ends, but i did not find inbuilt command for it.
Thank you for the help,
                                         Andras B-D.
(i have LabWindows 8.0 with academic licence)




         
0 Kudos
Message 1 of 4
(3,301 Views)

Hi Andras, your observations are right, when you are in a loop like your while is, the system executes only the instructions inside the loop and nothing else: neither system events nor drawing events are processed unless they are explicitly permitted. As you have noted, SetCtrlVal does not explicitly updates the user interface. I have never made specific tests on this, but in my opinion DisplayPanel implies an overhead on the system since it redraws the entire panel, I suggest you to use ProcessDrawEvents() instead, that only updates graphical elements that need to.



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 4
(3,289 Views)
Thank you very much!
Regards,

          Andras
0 Kudos
Message 3 of 4
(3,286 Views)
Roberto is correct, ProcessDrawEvents() is the best way to get a display update from inside a loop such as yours.  If your just updating one or two indicators on the display the way you are doing it is fine.  In cases where you want to update a large number of indicators at a rapid rate it is better to use repeated calls to SetCtrlAttribute(panel, control, ATTR_CTRL_VAL, value) for each indicator and then call ProcessDrawEvents() at the end.  Using SetCtrlAttribute() in this way queues the redraw operations so that only one screen redraw is required.  While having a screen redraw in a loop will slow it down, with modern processors and graphics cards, it is not the big problem it was in the past. 
 
One other thing to be aware of;  when executing in a loop like this your main execution thread "blocks" other CVI events.   What that means is you cannot easily break out of the loop you are in from a control (like an Abort Button) on the main panel.  One way this can be solved is by using ProcessSystemEvents() in place ProcessDrawEvents() in your loop, but the price will be slower loop execution.  It is worth playing around with these kind of things to see how much it changes the execution of your program.  The impact of the different functions on each system can vary a lot between different types of hardware or Operating Systems.
 
Good Luck
0 Kudos
Message 4 of 4
(3,268 Views)