Decouple LabVIEW Test Code with the Queued Message Handler
Use LabVIEW's Queued Message Handler to separate UI, acquisition, and logging into message-driven states without rewriting your main loop.
12 Jan 2026, 13:10 UTC

The problem: one loop doing everything
In a typical LabVIEW test application, the main While Loop reads front-panel buttons, acquires DAQmx samples, processes results, and writes files. Adding a new instrument or test step usually means opening that loop, adding wires, and retiming the whole sequence. The UI can also freeze while a slow acquisition runs, because everything shares the same execution thread.
The useful takeaway: the Queued Message Handler (QMH) moves those responsibilities into separate message cases. A single loop dequeues messages and runs the matching case, so you can add instruments or steps by adding messages rather than rewiring the central loop.
How QMH separates concerns
QMH combines two LabVIEW primitives: a queue and a state machine. Each loop iteration calls Dequeue Element, waits for a message, then routes it through a Case Structure. A case can enqueue the next message, pass data through a shift register, or stop the loop. Messages are typically strings or enumerated types, often paired with a data cluster.
This decouples the user interface, hardware acquisition, and processing logic. A button event handler only needs to enqueue Acquire; it does not need to know how the acquisition case is implemented.
Worked example: four-message test skeleton
Assumptions: LabVIEW 2020 SP1 or later on a Windows host. Exact template names vary by release, so confirm availability in your installed version. No FPGA or real-time target is involved; QMH is not deterministic.
Where to run: LabVIEW development environment, normal user permissions. If your Init case opens a DAQmx task, the DAQmx driver must be installed and the hardware present.
- Create a new LabVIEW project and add the QMH design-pattern template if available in your release.
- Define a message enum with cases:
Init,Acquire,Save,Stop. - Pair the enum with a data cluster containing, for example, a channel name and a waveform.
- In the
Initcase, open the instrument or DAQmx task and store the session in a shift register. - In the
Acquirecase, read samples, then enqueueSavewith the data cluster attached. - In the
Savecase, write the data to a file. - In the
Stopcase, clear the task and exit the While Loop.
| Message | Data | Case action |
|---|---|---|
| Init | Instrument name | Open session, store in shift register |
| Acquire | Channel list | Read samples, enqueue Save |
| Save | Waveform cluster | Write to file |
| Stop | None | Clear session, exit loop |
Diagnostic check: run the template with highlight execution enabled. The Dequeue Element node should sit at its border waiting for a message. Manually enqueue Acquire from the front panel or an Enqueue Element node and confirm the corresponding case runs. Then enqueue Stop and verify the loop exits cleanly.
Trade-offs and limitations
- If producers enqueue messages faster than the consumer dequeues them, the queue depth grows and older commands can become stale.
- Errors inside a case do not automatically stop the machine. You must wire error clusters to an error-handling case or
Stop, or the loop can continue past a failure. - QMH is a host-side software architecture. It is not a substitute for FPGA single-cycle timing or deterministic real-time priorities.
- Template names and supported editions change between LabVIEW releases; check your version-specific help before building a standard around it.
Closing: start small, verify the loop
Use QMH when your test application needs to grow beyond a single linear sequence. Begin with the four messages above, verify each case with highlight execution, and add error propagation before connecting real hardware. If you create a test project and decide not to keep it, close LabVIEW without saving or delete the project folder to remove the skeleton files.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.