LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How rapidly can I disable an asyncronous timer?

In my application I have a timer that runs 4 times per second checking the hardware connected. When some start condition is matched, a test function must be executed that runs for several seconds. During this time no other functions must be launched.

When using a conventional timer, I setup my application as follows:

Timer callback:
// Check for serial hardware connected
// In case the starting condition is encountered:
// PostDeferredCall the testing routine
// else
// display some diagnostic value
// End of timer function

Testing routine:
// Disable timer execution
SetCtrlAttribute (panel, control, ATTR_ENABLED, 0);
// Run the tests
// ...
// At the very end, enable timer again

This structure work
s well: only one testing routine is launched at a time.

When transferring my application to asyncronous timers, I found that more than one testing routine are launched. Seems that when a timer event is executing, there are some more events (3 or 4) queued in the system, so that even if the first instruction in the testing routine is disabling the timer, some more timer events are still executed.

Disabling the timer inside the timer callback istself has not solved the problem (and I don't even know if this is correct or not).

I had to use a global flag set in the testing routine that causes the timer callback to end immediately after called.

What can be happening? Is my hipothesis correct or am I missing some basic concept regarding asyncronous timers?

CVI 6.0.0 on a Celeron machine with WINXP Pro. No other applications running.

Thanks
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 1 of 2
(3,006 Views)
Hello

I was not able to reproduce this effect on my system. The async timer should just cause the callback to occur in a seperate thread, and in your case perhaps the SetAttribute function was unable to get the criticalSection handle to be able to disable the callbacks fast events. Which is why you still might have a couple of events firing before it gets disabled.
You can see the code for the async timer under ..\CVI70\toolslib\toolbox\asynctmr.c

One thing that might be easier in your case would be to shcedule a function in a threadpool instead of using the async timer. And have a while loop in the thread with a Sleep function ( include windows.h for the Sleep function) of 0.25s. This way, your function would run 4 times in a second in another thread and yo
u wont need to worry about disabling callbacks. When the condition is met, the test function would run for a few seconds and no other function will be launched.

I hope this helps

Bilal Durrani
NI
Bilal Durrani
NI
0 Kudos
Message 2 of 2
(3,006 Views)