LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

SetAsyncTimerAttribute

Bonjour,

Je travaille avec LabWindows/CVI 7.0.

Dans mon programme, j'utilise 16 timers asynchrones avec des durées pouvant prendre des valeurs comprises entre 500  et 10 000 ms. Pour chaque timer que je crée avec la fonction NewAsyncTimer, il n'y a aucune erreur.

Par contre, lorsqu'ensuite  j'appelle SetAsyncTimerAttribute avec l'attribut ASYNC_ATTR_INTERVAL  avec un des timers précédemment créés, la fonction renvoie -2 (No more IDs are available to assign to a new timer).

Comment est-ce possible alors qu'un ID a déjà été attribué à tous les timers que j'ai créé ?

Pouvez-vous m'aider à trouver la source de ce problème ? Y-a-t-il un nombre limité de timer asynchrone dans CVI ?

Merci d'avance.

Yoann
0 Kudos
Message 1 of 8
(4,940 Views)
The same but in english this time... sorry !

Hello !

I work with LabWindows/CVI 7.0.

In my program, I use 16 asynchronous
timers with delays that have values  between 500  and 10 000 ms. For each timer that I have created with the NewAsyncTimer function, no error occurs.

But then when I use
SetAsyncTimerAttribute function with the ASYNC_ATTR_INTERVAL  attribut with one of previous timers, the function returns the error code -2 (No more IDs are available to assign to a new timer).

How is it possible since all timers are already created and have an ID ? Is there a limit for number of asynchronous timers to use in a CVI program ?

Can you help me to resolve this issue ?

Thanks a lot.

Regards,
Yoann
0 Kudos
Message 2 of 8
(4,939 Views)
Yoann:

Yes, there is a limit, and it is 16.

When you call SetAsyncTimerAttribute() specifying ASYNC_ATTR_INTERVAL, CVI attempts to create a new timer with the required interval (note that this is NOT true for other attributes).

So, if you already have 16 timers, this call will fail with error -2.

What you need to do is call DiscardAsyncTimer(), then call NewAsyncTimer() with the new interval.

If you find that you need more than 16 timers, you may be able to use a "frequency divider" in an asynchronous callback to control several periodic events.

Regards,
Colin.
Message 3 of 8
(4,929 Views)
Dear NI/CVI experts,
 
>
> When you call SetAsyncTimerAttribute() specifying ASYNC_ATTR_INTERVAL, CVI attempts to create a new timer
> with the required interval (note that this is NOT true for other attributes).
>
 
Could you please explain why this setting will create a new timer?  Is it necessary to make it function like this?
Is this behavior still true for higher version of CVI, 7.1 and above?
 
Thanks!
 
Daniel
0 Kudos
Message 4 of 8
(4,607 Views)

I've run into the same issue with CVI's Async Timers. 

The timers seem to be "serviced" in order and there is a 16 timer limit as mentioned before.  No timers are freed or changed until the end of the "service loop". (so far as I can tell).  When you change the interval on a timer (I think) a new timer is created and requires 1 more timer "resource" to be free (of the 16 available).  The same is true if you create a new timer from within a Timer.  I had an application that used to use "one shot" Async Timers that would each start a new "One Shot" timer from within their callback.  When you do this, you are essentially limited to 8 Timers since each Timer, needs another timer slot free in order to start the new one. (by either creating one or changing the timer interval)

If you will always be running on Windows, I suggest you look into the Timing functions in the Windows SDK.  They are much more powerful and don't have any arbitrary limits.  The non-intuitive/undocument behavior of CVI's Async Timers has caused me a lot of headaches in the past.

Greg

0 Kudos
Message 5 of 8
(4,575 Views)

Can someone from NI answer the issues discussed in this thread for us?

AsyncTimer is an important function for multi-tasking.  How come NI make it so hard to use it?

Daniel

0 Kudos
Message 6 of 8
(4,467 Views)

As it says in the CVI help, the asynchronous timer is implemented using the Windows 'Multimedia Timer' resource. The limits you are seeing are the limits imposed by Windows: each process may only have 16 multimedia timers active.

Now, once a Windows multimedia timer is created you cannot change its time interval. So the code to change the interval of an asynch timer must involve the destruction of one multimedia timer and the creation of another. Whether it is a good idea to try to create the new timer before the old timer is destroyed could be debated, but it appears to be the way NI have done things. It would be nice if this aspect of behaviour were documented (that - IMO - applies to quite a lot of CVI), but in any case it could be argued that an application that uses that many asynchronous timers either doesn't need to be implemented that way or is trying to do things that shouldn't be done in Windows.

--
Martin
Certified CVI Developer
0 Kudos
Message 7 of 8
(4,453 Views)

There are certainly many other ways to time events then using the Async timers.  As mentioned, if the documentation of the CVI implementation was more complete you might realize that an application timing more then 8-16 things needs to use another tool.    To say that you should not use windows to time that many things is a bit of an overstatement.  The resolution and frequency of events, of course, more the limiting factor for windows rather then the total number.  In my particular application I was had about a dozen things generating software interrupts on different time periods on the order of a few seconds each.  Windows is certainly capable of servicing hundreds of such time intervals.... You just can't do with CVI's Async timers which was at the time my default timer tool. 

Greg

0 Kudos
Message 8 of 8
(4,427 Views)