This example shows how the Producer/Consumer architecture can be used to take in and process user events. The outcome of the program is that the LabVIEW window will move onscreen based on user inputs.
This application has a user interface with four directional control buttons and a queue status indicator. The block diagram has one loop that collects user interface events and updates the queue indicator (Producer loop), and another loop that takes the user interface data and moves the window accordingly (Consumer loop). This example makes use of the buffered communication in Queue Operations functions
How to Use
Open the attached code Move-Window.vi.
Run the program.
Press the Up, Down, Left, and/or Right buttons.
These commands are captured in the Producer Loop. The Consumer Loop processes the commands.
Press the front panel buttons quickly.
The queue on the front panel shows the commands in the order that the buttons were pressed. As the commands are processed in a first-in/first-out manner, the queue updates.
Press Stop to complete the program.
In this program, Stop halts all window movements, and commands are left in the queue. It is possible to alter the program so that the queue is emptied (i.e. commands are executed) before the program stops running.
Erika Technical Support Engineer National Instruments
Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.