11 LabVIEW
11 LabVIEW
Figure 1: LabVIEW VI Front Panel (l) and Block Diagram (r) windows
7. Now we can begin LabVIEW “programming”. Right-click anywhere on the front panel and LabVIEW will show
the Controls palette containing many goodies you can place on your front panel. The Modern category
should already be open. Point to String & Path to expose that subpalette and select String Indicator. Back on
the front panel, click where you’d like this indicator placed. You should also notice an icon appear in your
block diagram representing this front panel indicator. Front panel indicators are the standard method of
presenting LabVIEW program output data.
8. Next we will create a string constant for the output message. Right-click anywhere on the block diagram and
LabVIEW will show the Functions palette containing numerous program elements and subVIs you can add to
your program. The Programming category should already be open. Point to String to expose that subpalette
and then select String Constant. Back on the block diagram, click to the left of the String indicator icon and
immediately type in the “Hello World!” message you’d like to display (see figure 2). Notice the concept of
how program elements are graphically displayed on the block diagram window. Click anywhere outside the
string constant icon to complete its placement.
9. Now for the fundamental concept of LabVIEW programming – “wiring”. In the block diagram, hover the
mouse pointer just to the right of the string constant to reveal a spool of wire near its output terminal.
(Left)click to anchor that end of your wire. Move the wire spool to the left side of the string indicator icon
and click again to anchor the other end of your first wire. Things should appear as shown in figure 2.
2
GET130 Intro to Engineering Technology Lab 11: LabVIEW
10. Believe it or not, you have just completed your first LabVIEW VI! To see if it works properly, click the run
button also shown in figure 2. Your message string should appear in the string indicator. Hurrah, you have
just run your first LabVIEW program! Save your masterpiece then close this VI.
11. To demonstrate a bit more LabVIEW programming, let’s build a “dial-controlled meter”. In the LabVIEW
project explorer window, right-click on My Computer and create another new VI. Save this new VI as
Meter.vi.
12. Right-click on the front panel then select Modern -> Numeric -> Dial (or Knob) and place it on the front
panel. Right-click again and place a Modern -> Numeric -> Meter (see figure 3).
13. You should now see two icons on the block diagram, one for the Dial and one for the Meter. Hover the
mouse pointer near the right side of the Dial icon to reveal the wire spool. Notice how the Dial, being a front
panel control, produces an output terminal on the block diagram. Front panel controls are the standard
method of accepting user input into a LabVIEW program. Connect the Dial’s output to the Meter’s input.
Things should appear similar to that shown in figure 3. Save the updated VI.
14. Change the dial setting to arbitrary values and click Run each time. Verify that the meter updates to the
same dial value each time you run. Now, if it would only run continuously…
15. Although there is a Run Continuously button next to the regular Run button, this is not the desired method
to getting a VI to repeat. Note that when you run continuous (try it!), the graph paper background in the
front panel disappears to indicate the VI is running and the meter updates instantly as you change the dial
setting; however, the only way to stop the VI is to abort it with the stop sign button to the right of run
continuous. This technique is so not cool.
16. The proper way to make a VI iterate, as in any programming language, is to add a loop. Make sure your VI is
stopped as you cannot modify a running VI. Right-click on the block diagram and select Programming ->
Structures -> While Loop. Left click and drag a while loop to completely enclose both dial and meter icons as
shown in figure 4.
3
GET130 Intro to Engineering Technology Lab 11: LabVIEW
17. Notice that at this point, the Run button now appears broken because you have at least one error in your VI.
Click the Run button to see the Error list dialog with descriptions of your error(s). Click the Show Error button
and LabVIEW will even show where in your block diagram it has detected the problem. LabVIEW seems
almost smart enough to automatically correct programming errors! Close the Error list window.
18. The current problem is that the “termination condition” for the while loop is not defined. Let’s add a “stop”
button to the VI… On the block diagram immediately to the left of the stop icon in the while loop, right-click
once you see the wire spool and select Create Control. Notice how LabVIEW adds a second control to the
block diagram and its corresponding STOP button to the front panel. You can reposition the stop icon in the
block diagram and the STOP button on the front panel for a better layout as shown in figure 5. You can also
resize the STOP button and turn off the redundant “stop” label on the front panel (right-click on the stop
button then select Visible Items -> Label to remove its check mark). Note the asterisk to the right of the
block diagram window title indicating that program changes have been made but not yet saved to disk. Save
your VI noting that the asterisk disappears.
19. Run this new version and verify for correct operation. When finished, click the STOP button to properly
terminate the VI. Now it’s cool.
4
GET130 Intro to Engineering Technology Lab 11: LabVIEW
22. Referring to figure 6c, construct the block diagram as shown. All of the math operators used in this VI are
found on the Programming -> Numeric subpalette and are summarized in figure 6b. Note that you do not
need to place the box around the discriminant; it is only shown for emphasis. To properly configure the
compound arithmetic operator:
a. after placing it on the block diagram, right-click it and select Change Mode -> Multiply
b. grab either its top or bottom ‘handle’ and increase its height to three “stories”
5
GET130 Intro to Engineering Technology Lab 11: LabVIEW
23. Save your VI. Using the coefficients in the two examples of the calculator lab (ex. 4.1 and 4.2), run your
quadratic solving VI and verify for proper results. And to think, you did this all with “graphical
programming”!
24. Alternatively, mathematic problems can also be solved using LabVIEW’s “Formula Node” feature as shown in
figure 7. Copy your Quadratic.vi to a new version, Quadratic2.vi using File -> Save As. In the Save dialog box,
be sure to select Open additional copy. Also make sure Add copy to project is checked.
25. In this new version, delete all the math operators in the block diagram then select Edit -> Remove Broken
Wires (or just type Ctrl-B). Place a Programming -> Structures -> Formula Node as shown in figure 7. Right-
click on the formula node’s borders and select Add Input for each of the three coefficients on the left and
Add Output for the outputs on the right. Name the inputs a, b, c and the outputs x1, x2. Inside the formula
node box, type the formulae exactly as shown. Also complete the wiring as shown.
26. Save your alternate version. Run it as in step 23 and verify the same answers. Graphical method or
mathematical method – LabVIEW does not discriminate.
6
GET130 Intro to Engineering Technology Lab 11: LabVIEW
7
GET130 Intro to Engineering Technology Lab 11: LabVIEW
• The Wait (ms) function injects a time delay into the loop so that we can visually follow the front panel as
it is updated. Feel free to try different values here.
• The up/down arrows on the while loop’s borders are a “shift register” which serves as a history
mechanism from one loop iteration to the next. In this VI, this shift register accumulates the total value
of all the cards in a hand. Right-click on the loop’s border and select Add Shift Register. The 0 to the far
left sets the initial value to zero.
29. Once you complete building this VI, save it then run it a few times to see how it works. Card # will display
how many cards are “dealt” to your hand, Current Card is the value each card as they are dealt, and Total is
the total sum of the hand.
A highly useful feature of LabVIEW is its built-in help system. In addition to a fully-detailed help facility, LabVIEW
also features a “context” help feature.
30. On the Help menu of any LabVIEW window, turn on Show Context Help - a check mark should appear there
along with a separate context help window. Mouse over the various (yellow) operators and program
elements in your block diagram to see an instantaneous help display in that window. This is very handy!
Another very ‘kewl’ feature of LabVIEW is its “execution highlighting” feature which visually shows the flow of
data through your VI as it executes. Indeed, LabVIEW is known as a “dataflow” language. So if you’ve ever
wondered how a computer runs a program, you came to right place!
31. Click the Highlight execution button on (figure 9) then run your VI while watching the block diagram “come
to life” via execution animation. Amazing, no?