AERO61021 Chap.9 LabVIEW Programming Structures
LabVIEW Programming Structures
LabVIEW Programming Structures covers the graphical language used for data acquisition, control and the group project in this module. A program is a virtual instrument with two linked windows: a front panel holding controls and indicators, and a block diagram where wires carry data between functions.
Execution follows dataflow, so a node runs only when every input has arrived, and the colour of each wire announces its type: blue integers, orange doubles, green Booleans and pink strings. The chapter then builds the structures that every acquisition VI relies on. For Loops repeat a fixed number of times and can run zero times, while While Loops run at least once and stop when a condition is met.
Tunnels move data across loop edges, shift registers carry a value from one iteration into the next, arrays index from zero, and clusters bundle mixed types such as the error cluster. Timing a loop with a wait, choosing between a chart with history and a graph of whole arrays, and using Boolean or Enum case structures complete the toolkit.
Good practice runs throughout: initialise registers, avoid coercion dots, comment the diagram and stop loops through the conditional terminal.
What this chapter covers
- 01
Virtual instruments, subVIs, front panels and block diagrams
- 02
Controls, indicators, constants and wire colours
- 03
Dataflow execution and explicit type conversion
- 04
For Loops, While Loops and tunnel behaviour
- 05
Shift registers and why they must be initialised
- 06
Arrays, auto-indexing and clusters
- 07
Loop timing, charts, graphs and case structures
Worked example · free
Trace a shift register across three runs
- 2The iteration terminal takes the values 0, 1, 2, 3 and 4, so one complete run of the loop adds 0 + 1 + 2 + 3 + 4 = 10 to whatever the register starts with.
- 2Left unwired, the register keeps its last value between runs, so the indicator reads 10, then 20, then 30.
- 1Wired to a constant 0 outside the loop, the register restarts every run, so the indicator reads 10 each time.
Key terms
- Virtual instrument
- A LabVIEW program, saved as a VI file, made of a front panel and a block diagram.
- Shift register
- A loop terminal pair that passes the value from one iteration into the next.
- Auto-indexed tunnel
- A loop boundary terminal that builds an array from, or reads one element of, an array per iteration.
- Coercion dot
- A marker showing that LabVIEW converted a compatible but different data type at a terminal.
- Error cluster
- A bundled status, code and source value passed between functions to report problems.
LabVIEW Programming Structures FAQ
Do I need to know a text programming language before learning LabVIEW?
No. The lectures state that text-based programming experience is not required, because the language is graphical and built around wiring functions together. What helps instead is reading dataflow: knowing that a node runs when its inputs arrive, that inputs sit on the left of a function, and that wire colour shows the data type.
Repetition does the rest, so practise on any campus computer with simulated data before the hardware sessions.
When should I pick a For Loop rather than a While Loop?
Use a For Loop when the number of repetitions is known, such as generating a block of samples or stepping through an array, and remember it can run zero times. Use a While Loop when the stopping point depends on something happening, such as a Stop button, an error or a tolerance being met. A While Loop always runs at least once, and its iteration terminal starts at zero.
Why does my loop output grow every time I press Run?
An uninitialised shift register keeps the value left from the previous run of the VI, so totals accumulate across runs instead of restarting. Wire a constant to the left-hand register terminal from outside the loop. The same habit avoids other surprises, because the lectures stress that uninitialised values lead to errors and that every shift register should be given a starting value.
What is the difference between a waveform chart and a waveform graph?
A chart stores a history and appends new points as they arrive, which suits slowly changing single values. A graph has no history and redraws a whole array each time, which suits blocks of acquired samples. An XY graph additionally needs separate X and Y arrays of equal length. For block acquisition the graph shows every point received, whereas a chart may show only its recent history.
Assessment move
Treat LabVIEW as a practical skill that grows through repetition rather than a topic to memorise. Start each study session by rebuilding a small VI from an empty block diagram: a numeric control, a conversion from the integer iteration count to a double, a multiply, an indicator, a waveform chart, a Wait function and a Stop button wired to the conditional terminal.
Doing this from memory several times makes the palette locations, the right-click shortcuts and the colour conventions automatic, which frees attention for the acquisition logic later in the semester. Keep context help open with Ctrl+H while you work and read the description of every new function before wiring it. Next, drill the loop structures with paper traces.
Write the iteration number, the shift register value entering and leaving, and the tunnel output for each pass, then run the VI and compare. Do one trace for a For Loop that can run zero times, one for a While Loop that must run once, one for an auto-indexing loop fed by arrays of different lengths, and one for a stacked shift register.
When a result surprises you, the trace usually exposes a missing initial value or an off-by-one stopping test. Then practise data presentation: plot the same values on a chart and on a graph, change the update mode and axis limits, and build an XY graph from two arrays of equal length. Add a case structure selected first by a Boolean and then by an Enum, so you see why many options suit the Enum.
Finally, review your diagrams as a reader would. Remove coercion dots with explicit conversions, add comments, give front-panel objects short labels and longer captions, and make sure everything fits on one screen. The optional challenges posted for the module, and the series estimate of pi, are good tests because they combine loops, shift registers, comparisons and timing in one program, much as the group project will.