LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I determine the size of an event queue?

Hi,
 
I'd like to be able to programmatically determine how many events are in queue so that I can change how they are processed based on how far behind the loop is.
 
Is there a way to easily do this in labview? 
 
I suppose I could create an identical parallel event loop that just counts the events as they come in, and then subtract the ones that get processed by the main event loop, but it seems like there should be an easier way.
 
I'm using LV 8.1
 
Thanks,
Greg
0 Kudos
Message 1 of 8
(4,856 Views)
I dont think the actual queue is exposed but the simple method is to not handle any code (that takes any significatn ie>50ms amount of time) in the event structure and send the event to a second loop for action.  The event que should not be recieving events at significant rates (>10 Events/second) to the queue should not build up.  In good programming style the event strtucture should not block program execution, so the event queue should noy build up. 
 
Paul
Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
0 Kudos
Message 2 of 8
(4,851 Views)
The Get Queue Status function will return the number of elements in the queue.

I agree that in normal conditions a queue shouldn't "fill up" or get behind, but if the queue is accepting all sort of events from various places (e.g., external instruments, say), you could have a "building up" situation. In this I would reconsider the way the events are being handled.
0 Kudos
Message 3 of 8
(4,843 Views)
Let me make sure I understand the recomendation.
 
Most events come in at about 10Hz.  (For each new datapoint.)  These events are processed quickly (display to screen and save to file).  But every once in awhile, an event is triggered that takes a while to process (analyze previous data, generate report), and then the loop falls behind.
 
So you are recomending running two event loops, one waiting for the faster events and one waiting for the slower events?
 
That makes sense.  I just want to make sure I understand correctly.
 
Thanks.
0 Kudos
Message 4 of 8
(4,833 Views)

So you are recomending running two event loops, one waiting for the faster events and one waiting for the slower events?

I wouldn't put it that way.
Any event that takes 'long' (eg. a significant amount of time), should be processed in a consumer loop.
So the event arives in the normal event structure, and is than feed to a consumer loop via a queue.
In the LabVIEW examples there is a framework example called 'Produces/consumer with events' (or something like that).

If you have a specific type of event generating very fast and you are only interested in the last a notifier might be usefull.

Ton
Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
0 Kudos
Message 5 of 8
(4,795 Views)
Is this question about getting the number of events in the event queue or getting the number of items in a queue?  I might have misread the question.
Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
0 Kudos
Message 6 of 8
(4,782 Views)
The original questions is about number of events in the event queue.  I think you had it right because the Get Queue Status only seems to work with a regular queue.
 
It seems that the conversation has eveolved to one of architecture though, and Ton has given me the terminology to better describe my problem.
 
It turns out that I am running a producer/consumer structure using the event structure as the messaging method, I just didn't know it was called that.  The producer and consumer loops are normally approximately synchronized; however, because sometimes an event occurs that takes more time to process, the consumer loop falls behind the producer loop.  A little bit is ok, but falling behind too much is no good.  That is why I was interested in determining how many events were in the queue.
 
You guys have convinced me that I need to change the structure of the program though.
 
It seems like I have two good options:
1) Add the fast  processes to the producer loop and leave the slow processes in the consumer loop.
2) Create two consumer loops, one for fast processes and one for slow ones.
 
Is one of these methods better than another?  Intuitively, the second seems more sound since the producer loop should just be producing, but my intuition has failed me before. 🙂
 
Thanks.
0 Kudos
Message 7 of 8
(4,773 Views)
Second!
I'd go for multiple event queues.

You could do this by name.
So create a queue (with a seperate loop) that is called 'slow', one that is called 'fast' etc.

Ton
Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
0 Kudos
Message 8 of 8
(4,769 Views)