The way I manage my queues is maybe a little eccentric.... i create a reentrant subvi for each queue I want to use in my application. I name this queue the same name as the subvi (using a property node for the VI), and the subvi has an input to specify whether to enque or deque (it also has data in, data out and timeout terminals). I put one instance of this vi in the deque loop with timeout set to -1. Then, wherever I want to enque data I drop instances of this subvi with the operation terminal set to enque. This has some memory overhead because an instance of the reentrant VI is created everywhere I use the queue, but that's ok for me because I prefer the readability and convenience. It is easy to see where data is getting into the queue be looking for instances of the queue subvi. With the queue timeout set to -1 the deque operation will suspend until data is placed in the queue... this is what makes this approach event driven. (And is what also creates the need for and exit command for the queue... there is no other way to stop the loop while it is suspended in the deque).

I will send an example by private mail.

George

At 03:37 PM 6/21/2004, you wrote:
Hi Georges,

I think I understand your approach, but it seems to me that the separate loop that is needed in the MainLevel.vi will have the same "problem" as the polling strategy I was mentioning, that is, unecessary activity (you can't use a queue without volontarily polling it, ie you will again need to relieve the CPU of unwanted load by having a Wait 100 ms in your side loop). Plus, how do you enqueue something in a subVi, when the queue is read in the TopLevel.vi ? Somehow you need a Queue RefNum global, if I am not mistaken.
What do you think ?
X.


George Gatling (Contractor) wrote:

One possible solution would involve using queues. Create a queue that uses a cluster of an enum and a variant as the type. Put a loop in your main VI that waits for elements to arrive in the queue. When they show up, it uses the enum to determine which control to update and then casts the variant to the appropriate type and does the update. I uses this method all the time very successfully for things like moving the cursor on a graph around, enabling/disabling menu items, updating control values, hiding/disabling controls or indicators and on and on. Finally, one of the items of my enum is "exit"... and so when the app is exiting it sends the exit message to the UI Update loop to stop it so the application can exit gracefully.
This way you can put a -1 for the timeout on the deque and make your ui updates "event driven".


If this sounds like something you'd like to try but it is still not entirely clear what I am talking about, let me know and I will send you an example.

George

George Gatling Applied Technology Division, SFA Inc. Space Physics Simulation Chamber US Naval Research Laboratory 202-404-5405 (phone) 202-767-3553 (fax)

As you know, these are open forums, you're able to come and listen to what I have to say.
-- George W. Bush, press conference, October 28, 2003







Reply via email to