LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

inaccurate delay using ProsesSystemEvents

Solved!
Go to solution

hi,

I'm suffering inaccurate delay function when using ProcessSystemEvents. I have no need for 1 second accuracy, instead 10 seconds accuracy would be enough. But I need ProcessSystemEvents because I have need to wait quite a long time and doing it by only using Delay() locks the user interface. Below function I'm curretly using and e.g. 300 seconds delay will be 467 seconds without any user interface use. Is there any better solution to improve the accuracy using ProcessSystemEvents ? Or any other method to wait avoiding locking the user interface ?

Regards,

petri

 

void delay(double seconds)
{
 long int max = 0;
 long int index = 0;
 
 max = (long int)seconds/0.1;
 
 for (index=0;index<max;index++)
 {
  ProcessSystemEvents();
  Delay(0.1);
 }
}

0 Kudos
Message 1 of 5
(4,173 Views)
Solution
Accepted by topic author Petri

A long lasting delay loop can be implemented this way:

 

 

void LongDelay (double seconds)

{

  double   tini;

 

  tini = Timer ();

  while (Timer () - tini < seconds) {

    ProcessSystemEvents ();

  }

}

 

However, this is not the optimal solution if this function is called within a control callback, since callbacks should be designed to be as fat as possible.

 

One possible solution is to design a state machine built around a standard UI timer or better an asyncronous timer: this way the user interface level is free and your program can achieve a good performance (depending on the amount of operations in a loop, you may run the machine at 5 or 10 loops/sec). If you want to run this way, you may find in this document a tutorial on state machines; don't let all those LabVIEW citations frighten you  (Smiley Wink): state machine concepts are universal and you can develop fully functional machines in CVI as well as in LV.

Message Edited by Roberto Bozzolo on 10-05-2009 11:47 AM


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 5
(4,172 Views)

thanks Roberto for quick answer. since for a while I programmed with CVI and forgot the Timer() function... That's of course with while more accurate and good enough at the moment.

regards,

petri

0 Kudos
Message 3 of 5
(4,163 Views)
Wouldn't a "syncwait" function call do what you need as well?  I thought a process event's call was more or less done internally by this function as well.
0 Kudos
Message 4 of 5
(4,127 Views)

gtoph wrote:
Wouldn't a "syncwait" function call do what you need as well?  I thought a process event's call was more or less done internally by this function as well.

Unfortunately not: syncwait is equivalente in this respect to Delay (); UI events are ignored during the wait, even UI timers are not honoured while waiting. Only functions executed in different threads remain alive (e.g. an async timer continues working).



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
(4,112 Views)