LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Delay() pauses everything

I have a countdown module whiche relies on Delay(1) to pause for a second
before showing the next number down. Apparently when Delay (1) is exceuting,
tier functions are not updated until Delay() is done. This causes my program
to miss events monitored by the timer loopback and EVENT_TIMER_TICK: Is
there a way around this?

Thanks

Luis Villa
0 Kudos
Message 1 of 4
(3,069 Views)
Yes when calling delay() you program cannot do anything else, unless you use multithreading which I would not recommend unless you absolutly need it, and this does not look like such an application. Either move your fuction for updating/checking the countdown to you timer fuction or use something like this:

i = 5;
while (i--)
{ Delay(.2);
ProcessSystemEvents();
}

This is not an accuate method for producing an one second delay. Because you never know how long the ProcessSystemEvents call takes. For short countdowns this sould be accurate enough.
0 Kudos
Message 2 of 4
(3,069 Views)
To realise accurate 5s delay you can modify code like this:

double start=Timer();

for(;;)
{ ProcessSystemEvents();
Delay(.1); // 0.1s accuracy
if (Timer()-start>5.0)
break;
}



U¿ytkownik jimmidude w wiadomooci do grup dyskusyjnych
napisa³:5065000000050000006C210000-986092468000@quiq.com...
> Yes when calling delay() you program cannot do anything else, unless
> you use multithreading which I would not recommend unless you
> absolutly need it, and this does not look like such an application.
> Either move your fuction for updating/checking the countdown to you
> timer fuction or use something like this:
>
> i = 5;
> while (i--)
> { Delay(.2);
> ProcessSystemEvents();
> }
>
> This is not an accuate
method for producing an one second delay.
> Because you never know how long the ProcessSystemEvents call takes.
> For short countdowns this sould be accurate enough.
0 Kudos
Message 4 of 4
(3,069 Views)
Since you already have a timer control, you can obtain the initial time count (in seconds) with Timer() and store it in a global variable and next compare it in you timer callback with *(double *)eventData1, which returns the actual time count (in seconds too) at the moment the timer event is fired: when the difference between the latter and the former becomes > 1 you can update the indicator on your panel.
I agree with jimmidude that the real pace of timer callback is not predictable under Windows, but maybe the countdown update is not so crucial to your application (a way of informing the operator that the program is alive or so).
Roberto


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 3 of 4
(3,069 Views)