LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

I need to create a timer dispalaying on the screen. so I wrote a nice function using "Delay" command. But I can not minimize the window when running the program. What can I do? will multithreading help?

int countDown1()
{
 double hoursLeft, minutesLeft, secondsLeft;
 int timeLeft =  glbHoursToStart * 3600 + glbMinutesToStart * 60 + glbSecondsToStart;
 DisplayPanel(panelHandleForTimer);
 while (timeLeft > 0){
  hoursLeft = timeLeft/3600;
  minutesLeft = (timeLeft%3600)/60;
  secondsLeft = hoursLeft*3600 + minutesLeft*60 + (timeLeft%3600)%60;
  SetCtrlVal(panelHandleForTimer, TIMER_HOURS_LEFT,hoursLeft);
  SetCtrlVal(panelHandleForTimer, TIMER_MINUTES_LEFT,minutesLeft);
  SetCtrlVal(panelHandleForTimer, TIMER_SECONDS_LEFT,secondsLeft);
  Delay(1);
  timeLeft-=1;
 }
 
 return 1;
}
0 Kudos
Message 1 of 7
(4,054 Views)
Hi,

I would prefer using counters which are available with panels.
You can add a counter as if it was a button or text box, it is in the same menu.
So add 3 counters, one for hours, one for minutes and one for seconds and associate a callback for each counter.

It's better than use Delay(), I think so.

Another thing : you can try adding to your code the function SystemProcessEvents().

Hope it will help.
0 Kudos
Message 2 of 7
(4,043 Views)
Hi  NI_device_user_sb,

"ProcessSystemEvents" it is, and it did solve the problem.

Thanks

0 Kudos
Message 3 of 7
(4,020 Views)

Hi,

 

It is far easier to use the built Timer  and add the counter funciton as timer callback. It is not very accurate, but if you call it every second it is tolerable, certainly comparable with your Delay().

 

You ca read each time the system clock, so the accuracy wil l be much better.

 

An alternative is to use assynchronous timer and the respecive callback function. It is better at keeping the delay intervals when you need rapid updates (tmillisecond  to hundreds of miliseconds update interval ranges)

 

layosh

0 Kudos
Message 4 of 7
(3,971 Views)

DrorProgrammer, do you really think ProcessSystemEvents did solve the problem ?

so, start your countdown, then start dragging your window all around the screen. is your countdown accurate ? i bet it is not...

 

to understand the problem, you should read some documentation about events, event queues, and how events are processed by CVI (and the underlying operating system).

asynchronous timers will be far better.

0 Kudos
Message 5 of 7
(3,940 Views)

Hi,

 

In my opinion, having a multi-threaded application would be the best solution.

But it is harder to code! isn't it?

 

 

0 Kudos
Message 6 of 7
(3,926 Views)

it is not harder to code. it only implies you know how threads interact and which functions to call for creating/starting/stopping a thread. in fact, it is quite easy once you know how to do it. 

 

also, note that the asynchronous timer functions of CVI are implemented using a thread, so it will take care of all the gory thread details for you. those functions can be accessed after adding the asynctmr.fp instrument to your project: this instrument is in <CVI install dir>\toolslib\toolbox.

0 Kudos
Message 7 of 7
(3,923 Views)