Example Code

Queueing Events in LabVIEW

Code and Documents

Attachment

Overview


Event-driven applications can be easily made in LabVIEW using the Event Structure. However, even while the Event Structure will monitor and queue events as they occur, it will not provide information about the events waiting for their turn to run. Specifically, if you trigger an event and the code associated with that event takes several minutes to complete, you can trigger more events while that code finishes. The newly triggered events will wait for the first event’s code to complete before they run. Unfortunately, the Event Structure does not give you any way to see what events are waiting, how many events are waiting nor will you be able to manipulate the events waiting. This example program will show you how you can implement your own, user defined queue to use with an Event Structure.

Implementation 

This example VI contains a queue that stores events generated by an Event Structure in a Producer Loop. Rather than having the code for each event run in the Event Structure, the Event Structure quickly passes what event occurred out and enqueues that information. That information is than dequeued in a Consumer Loop where the code for each event actually runs. When the code for the first event finishes in the Consumer Loop, the next event in the queue’s code will run next… While the Producer Loop is enqueueing events and the Consumer Loop is dequeueing elements and running code, the queue can be read and manipulated anywhere on the block diagram. In this example VI, there is a Monitor Loop that monitors # of elements in queue and queue elements. There is also a mechanism for clearing the queue.

 

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Contributors