Tutorial Labview: 1. Open and Run A Vi
Tutorial Labview: 1. Open and Run A Vi
Tutorial Labview: 1. Open and Run A Vi
Tutorial LabVIEW
1. Open and Run a VI
Your objective is to open, run, and explore the components of a VI.
Open the Temperature System Demo VI.
In the LabVIEW dialog box, click the Find Examples button to display the Find
Examples dialog box. If you already opened a VI, select HelpFind Examples to
display the Find Examples dialog box.
Click the Search tab and enter temperatures.
From the list of examples, double-click Temperature System Demo.vi to open the VI.
You also can open the VI by selecting FileOpen and navigating to
labview\examples\apps\tempsys.llb\Temperature System Demo.vi.
1.1. Front Panel
This VI simulates a temperature acquisition and analysis application. The VI compares the
temperature value to a high and low value and displays the value on the chart, and plots a
histogram of the data on another chart.
Run the VI by clicking the Run button in the toolbar. The button changes
appearance to indicate that the VI is running.
Select WindowShow Tools Palette to display the Tools palette.
If the Automatic Tool Selection LED in the Tools palette is not lit, click the Automatic
Tool Selection button to enable automatic tool selection.
Move the cursor over the slider in the System Controls section. LabVIEW selects the
Operating tool.
Click and drag the slider to change the value. Notice the speed of the simulated
acquisition changes as you change the value.
You operate LabVIEW controls just as you would similar real controls. Other ways to
operate knob controls using the Operating tool include:
Clicking the black region of the slider to move the slider to the value at the point you
clicked.
Clicking the digital display and entering a number. If you use this method, the Enter
button appears on the toolbar. LabVIEW does not pass the value to the control
until you click this button or press the <Enter> key.
Click the Abort Execution button in the toolbar to stop the VI.
1.2. Block Diagram
Display the block diagram for the Temperature System Demo VI by selecting
WindowShow Diagram. This block diagram contains several basic elements of
2
LabVIEW programming, including structures, functions, and subVIs. You also can
press the <Ctrl-E> keys to display the block diagram.
Double-click the Temperature Status subVI icon to display the front panel of the
subVI.
Click the Run Continuously button and adjust the value of the High Limit and
Low Limit knobs. Notice the Temperature Status VI is a fully functional VI that
performs basic comparisons between the Temperature and the High Limit and Low
Limit values. When the temperature is greater than the High Limit, the Over Limit
indicator turns red. When the temperature is less than the Low Limit, the Under Limit
indicator turns blue.
When you run the Temperature System Demo VI, it calls the Temperature Status
subVI to perform this basic comparison.
Click the Run Continuously button again to stop the VI from continuously running.
Close the front panel for the Temperature Status VI by selecting FileClose.
Do not close the Temperature System Demo VI, because you will use it in the next
chapter.
2. Use the LabVIEW Help Utilities
Your objective is to become familiar with the Context Help and the LabVIEW Help.
If it is not already open from Chapter 1, open the Temperature System Demo VI by selecting
FileOpen and navigating to labview\examples\apps\tempsys.llb\Temperature System
Demo.vi.
2.1. Context Help
Display the block diagram by selecting WindowShow Diagram or by pressing the
<Ctrl-E> keys.
Display the Context Help window by selecting HelpShow Context Help or by
pressing the <Ctrl-H> keys.
The Context Help window displays information about the functions and wires as you
move the cursor over each object.
o Move the cursor over the Temperature Status VI icon. A description of the VI
appears in the Context Help window.
o Move the cursor over the terminals of the Temperature Status VI. LabVIEW
selects the Wiring tool and the corresponding terminals blink in the Context
Help window as the tool moves over them.
o Move the cursor over a wire. The Context Help window displays the data type
of the wire.
2.2. VI and Function Reference in the LabVIEW Help
Move the cursor over the Initialize Array function, on the upper left of the block
diagram. A blue link appears at the bottom of the Context Help window.
This link displays the reference information for the Initialize Array function in the
LabVIEW Help. The function reference information in the LabVIEW Help is more
3
detailed than the information in the Context Help window. Most VIs and functions that
ship with LabVIEW have links in the Context Help window to detailed VI and
function reference in the LabVIEW Help.
Click the blue link at the bottom of the Context Help window to view the function
reference information in the LabVIEW Help.
2.3. How To Instructions in LabVIEW Help
In addition to VI and function reference information, the LabVIEW Help contains overview
and procedural information about LabVIEW features. Select HelpVI, Function, and How-
To Help to display the LabVIEW Help.
When you are finished with this tutorial, use the Contents, Index, and Search tabs to browse
the LabVIEW Help to learn more about LabVIEW.
2.4. Printed and PDF Documentation and Full Text Searches
LabVIEW includes extensive documentation for new and experienced LabVIEW users. All
LabVIEW manuals and Application Notes are also available as PDFs. You must have Adobe
Acrobat Reader 4.0 or later installed to view the PDFs. Refer to the Adobe Systems
Incorporated Web site to download Acrobat Reader. Refer to the NI Product Manuals Library
for updated documentation resources.
The LabVIEW Bookshelf is a powerful front end for all the printed and PDF documentation.
You can search PDF versions of all the LabVIEW manuals and Application Notes.
In LabVIEW, open the LabVIEW Bookshelf by selecting HelpSearch the LabVIEW
Bookshelf.
In the LabVIEW Bookshelf, click the Search to display a search dialog box.
Enter temperature for your search string and click Search. Note the different results,
separated by document. Double-click one of the documents to view the results.
Click the Next Highlight button to go to the next highlighted instance of
temperature.
Perform a more specific search. Click the Search button to perform a new search.
Enter single-buffered analog output and click Search.
Double-click the document listed to view the results.
When you are finished, close Acrobat Reader.
4
3. Create a VI
Your objective is to build a simple VI that converts a Celsius temperature reading to
Fahrenheit.
3.1. Front Panel
Open a new front panel by selecting FileNew VI or by pressing <Ctrl-N>. If you
closed all VIs, click the New VI button in the LabVIEW dialog box.
Select WindowShow Controls Palette to display the Controls palette. You also can
access a temporary Controls palette by right-clicking an open area of the front panel.
Select a thermometer from the ControlsNumeric palette and place it on the front
panel.
Type deg C in the label text box and click the Enter button on the toolbar or click
anywhere on the front panel to complete the new label. If the label is not highlighted,
double-click the label to highlight the label and enter the text for the label.
If you click outside the text box without entering text, the label defaults to thermometer. To
show the label again, right-click the control and select Visible ItemsLabel from the shortcut
menu.
By default, a thermometer is an indicator because it displays a data value. In this VI,
however, use the deg C thermometer as a control because it is the data source. Right-
click the deg C thermometer and select Change to Control from the shortcut menu.
To make it easier to precisely enter a value into the deg C thermometer, make the
Digital Display visible. To do this, right-click the thermometer and select Visible
ItemsDigital Display from the shortcut menu.
Now that you have a thermometer control for the Celsius temperature, you need an indicator
to display the Fahrenheit value.
Select another thermometer from the ControlsNumeric palette and place it on the
front panel.
Label this thermometer deg F as you did in step 3 and make the Digital Display visible
as you did in step 5.
Because this thermometer will display temperatures in degrees Fahrenheit, change the scale of
the thermometer so it can display readings higher than 100 degrees.
To change the scale of the deg F thermometer, double-click the topmost value of the
scale and type 212, which is the Fahrenheit equivalent of 100 degrees Celsius, the
highest visible value on the deg C thermometer.
Press the <Enter> key.
(Optional) Use the Positioning tool to rearrange or resize objects. Move the cursor
over the center of an object to select the Positioning tool.
o To move an object, click the object and release the mouse button to select the
object. A moving dashed outline called a marquee highlights the object. Drag
the object to move it.
5
o To resize an object, move the cursor over a corner of the object to display
resizing handles . Move the Positioning tool over a resizing handle to change
the tool to the resizing cursor. Use the resizing cursor to drag the resizing
handles until the dashed border outlines the size you want, and release the
mouse button.
Your front panel should look similar to the following image.
3.2. Block Diagram
Open the block diagram by selecting WindowShow Diagram, or by clicking the
block diagram window behind the front panel window. You also can press <Ctrl-e> to
switch between the front panel and block diagram windows.
Notice the objects on the block diagram. These objects are terminals that correspond to
the thermometer control and indicator you placed on the front panel.
To convert a Celsius temperature value to Fahrenheit, multiply the Celsius value by
1.8 and add 32. Use the functions on the FunctionsNumeric palette to build a block
diagram that does this.
Select WindowShow Functions Palette to show the Functions palette. You also can
access a temporary Functions palette by right-clicking an open area of the block
diagram.
Select a Multiply function from the FunctionsNumeric palette and drag it to the
block diagram. Before you click the mouse button to drop the Multiply function on the
block diagram, drag the function just to the right of the deg C terminal.
Notice when you hold the function close to the terminal, LabVIEW automatically
draws a wire to one of the terminals on the Multiply function. When LabVIEW draws
a wire between the function and the deg C terminal, click the mouse button to place
the function on the block diagram. Notice the deg C terminal is wired to the Multiply
function.
(Optional) If you placed the Multiply function without a wire connection to the deg C
terminal, wire them together by completing the following steps.
6
o Move the cursor over the black arrow on the right side of the deg C terminal.
The terminal blinks, and LabVIEW selects the Wiring tool.
o Click the deg C terminal to tack a wire to the terminal. You do not need to hold
down the mouse button.
o Move the cursor to a terminal on the Multiply function until the terminal
blinks.
o Click to tack down the wire and wire the two terminals together.
You need to multiply the deg C value by 1.8. Right-click the unwired input terminal
on the Multiply function and select CreateConstant. LabVIEW creates a numeric
constant value and wires it to the input terminal, with the numeric value highlighted
for you to enter a value. Type 1.8 and click the Enter button, or click anywhere on the
block diagram.
You need to add 32 to complete the calculation. Select an Add function from the
FunctionsNumeric palette and drag it to the block diagram. Before you click the
mouse to place the Add function on the block diagram, drag the function just to the
right of the output terminal of the Multiply function.
When a wire that connects the output terminal of the Multiply function and one of the
input terminals of the Add function appears, click the mouse button to place the
function on the block diagram. LabVIEW automatically wires the two functions
together.
If the functions are not wired together, use the Wiring tool as described in step 4.
Right-click the unwired input terminal of the Add function and select
CreateConstant, as you did in step 4. Type 32 and click the Enter button or click
anywhere on the block diagram.
Now that youve multiplied the deg C value by 1.8 and added 32, you need to pass the
value to the deg F terminal. Wire the output terminal of the Add function to the deg F
terminal, as described in step 4.
Your block diagram is now complete, and should look similar to the following image.
Select FileSave and save the VI as Convert C to F.vi in the labview\activity
directory.
3.3. Running the VI
On the front panel, double-click the digital display of the deg C thermometer and enter
37, which is normal body temperature in Celsius.
7
Run the VI by clicking on the Run button. Notice that LabVIEW converts the Celsius
temperature to 98.6 degrees Fahrenheit and displays it on the deg F thermometer and
its digital display. Enter other values in the deg C thermometer and run the VI.
Close the VI by selecting FileClose to close the VI.
4. Document a VI
Your objective is to document a VI that you have created.
4.1. Front Panel
If it is not already open from Chapter 3, open the Convert C to F VI by selecting
FileOpen and navigating to labview\activity\solution\Convert C to F.vi.
Select FileVI Properties and select Documentation from the pull-down menu to
display the documentation properties of the VI.
Type the description for the VI, as shown in the following illustration, and click the
OK button.
Right-click the deg C thermometer and select Description and Tip from the shortcut
menu. Type the description and tip information for the control, as shown in the
following illustration, and click the OK button.
8
Right-click the deg F thermometer and select Description and Tip from the shortcut
menu. Enter Displays the calculated Fahrenheit temperature for the description, and
Fahrenheit temperature for the tip. Click the OK button.
Move the cursor over the deg C thermometer. Notice the information you entered in
the deg C Tip field of the Description and Tip dialog box shows up as a tip strip.
Select HelpShow Context Help to display the Context Help window. Move the
cursor over the deg C thermometer and then over the deg F thermometer. Notice the
information you entered in the Description and Tip dialog box appears in the Context
Help window.
Move the cursor over the icon in the upper right corner of the block diagram or front
panel window. The description you entered in the Documentation page of the VI
Properties dialog box appears in the Context Help window.
Save the VI.
5. Debug a VI
Your objective is to use the probe tool and the probe window and to examine data flow in the
block diagram using execution highlighting.
5.1. Probes
If it is not already open from Chapter 4, open the Convert C to F VI by selecting FileOpen
and navigating to labview\activity\solution\Convert C to F.vi.
Block Diagram
Select WindowShow Diagram.
If the Tools palette is not open, select WindowShow Tools Palette.
9
Select the Probe tool from the Tools palette and click the wire coming out of the
Multiply function. A Probe window appears with the title [1] Probe and a yellow
glyph with the number of the probe appears on the wire, as shown in the following
illustration.
If automatic tool selection is enabled and you move the cursor over objects on the front panel
or block diagram, LabVIEW automatically selects the corresponding tool from the Tools
palette. However, you must manually select the Breakpoint, Probe, and Coloring tools.
Front Panel
Return to the front panel. Move the Probe window so you can view the probe value
and both of the thermometer values. Run the VI. The value at the probe appears in the
[1] Probe window.
Close the [1] Probe window by clicking the close box at the top of the Probe window
title bar.
5.2. Execution Highlighting and Single-Stepping
Another useful debugging technique is to examine the flow of data in the block diagram using
the execution highlighting feature.
Block Diagram
On the block diagram, begin execution highlighting by clicking the Highlight
Execution button , in the toolbar. The Highlight Execution button changes to an
illuminated light bulb .
Click the Run button to run the VI. Notice that execution highlighting animates the VI
block diagram execution. Moving dots represent the flow of data through the VI. Also
notice that data values appear on the wires and display the values contained in the
wires at that time, as shown in the following block diagram, just as if you had probed
the wire.
Begin single-stepping by clicking the Step Into button in the toolbar.
10
Click the Step Over button until the VI finishes executing.
Finish executing the block diagram by clicking the Step Out button in the toolbar.
Clicking this button completes all remaining steps in the block diagram.
6. Search for Example VIs
Your objective is to become familiar with the example VIs, which demonstrate the basic
graphical programming elements in LabVIEW.
LabVIEW includes hundreds of example VIs you can use and incorporate into your own VIs.
You can modify an example to fit your application, or you can copy and paste from one or
more examples into your own VI.
In the LabVIEW dialog box, click the Find Examples button to display the Find
Examples dialog box. If you already opened a VI, select HelpFind Examples to
display the Find Examples dialog box.
On the Browse tab, navigate to the Industry ApplicationsAnalysis category. You
also can search by keyword on the Search tab.
Double-click Temperature System Demo to open this example VI.
Click the Run button on the front panel toolbar to see how the VI runs.
Click the sliders, knobs, and other controls to see how they affect the data.
Stop the program by moving the Acquisition switch to the off position.
Close the example and use the Find Examples dialog box to browse or search for other
example VIs.
6.1. VI Templates
In addition to the example VIs, LabVIEW includes several VI templates you can use to create
common VIs, including state machines, custom dialog boxes and about boxes, and continuous
analog input. Access the VI templates by selecting FileNew and selecting Start from
template.
7. Create a Multiplot Chart
Your objective is to create a chart that can accommodate more than one plot.
7.1. Front Panel
Open the Random Average VI by selecting FileOpen and navigating to
labview\activity\Random Average.vi.
Select WindowShow Tools Palette to display the Tools palette.
If the Automatic Tool Selection LED in the Tools palette is not lit, click the Automatic
Tool Selection button to enable automatic tool selection.
Modify the front panel as shown in the following illustration.
11
o Use the Positioning tool to drag out the plot legend to include two plots. Move the
Positioning tool over the corner of the legend to display resizing handles . Move
the Positioning tool over a resizing handle to change the tool to the resizing cursor,
which you drag out to enlarge the legend.
o Rename Plot 1 to Random Average by double-clicking the label and entering the
new text. You can resize the label area by using the Positioning tool to drag either
of the left corners.
o Change the plot style of the Current Value plot. Right-click the plot and select the
plot style from the Common Plots shortcut menu.
o Change the color of the Current Value plot. Right-click the plot and select the
Color shortcut menu. Select a light blue color from the color picker that appears.
7.2. Block Diagram
Show the block diagram by selecting WindowShow Diagram or pressing <Ctrl-e>.
Right-click the wire between the Divide function and the Random Plot terminal and
select Insert from the shortcut menu. From the temporary Functions palette that
appears, hold down the mouse button and select the FunctionsClusterBundle
function.
Add an additional element to the Bundle function.
o Move the cursor over the node to display the resizing circles at the top and
bottom of the node.
o Move the cursor over one of the circles to change the cursor to a resizing
handle.
o Drag the border of the node vertically or horizontally to add terminals to the
node.
12
The order of the inputs to the Bundle function determines the order of the plots on
the chart. For example, if you wire the raw data to the bottom input of the Bundle
function and the average to the top, the first plot corresponds to the running
average, and the second plot corresponds to the raw data.
Use the Wiring tool to connect the new element of the Bundle function to the wire that
connects the Random Number function and the right-most shift register . The
Bundle function bundles the running average and the current value into a cluster.
Notice that when you wire the second element of the Bundle function, the Random
Plot terminal changes appearance to indicate that its data type is now a cluster of
numbers.
Your block diagram should look similar to the following illustration.
7.3. Running the VI
From the front panel, click the Run button to run the VI. The VI displays two plots
that share the same vertical scale on the chart.
From the block diagram, click the Execution Highlighting button and run the VI.
Notice the data values displayed in the shift registers. Click the Stop button on the
front panel to stop the VI.
Click the Execution Highlighting button again to turn execution highlighting off. From
the front panel, run the VI.
7.4. Optional Steps
Complete the following optional steps to experiment with various options of the waveform
chart.
While the VI is running, experiment with the buttons on the Scale Legend and the
Graph Palette to modify the chart. You can reset the chart, change the scale of the X or
Y axis, and change the display format. Click the Plot Legend to modify the appearance
of the plots.
Format the scales of the waveform chart to represent either absolute or relative time.
To select the x-scale time format, right-click the x-scale and select Formatting from
the shortcut menu.
13
o Choose absolute time by selecting the Time & Date option from the Format
pull-down menu. For the waveform chart to start at a certain time and
increment at certain intervals, you can edit the Xo and dX values respectively.
Format the chart to display the data starting from noon, April 1, 2000, and
increment every 10 minutes, as shown in the following image. Click the OK
button to save your changes.
Select the relative time format and select Decimal from the Format pull-down
menu. Modify the dialog box, as shown in the following illustration, and click
the OK button.
14
Click the Run button to run the VI.
Save the VI as Multiple Random Plot.vi in the labview\activity directory.
8. Save Data to a Spreadsheet File
Your objective is to modify a VI that saves data to a new ASCII file you can access from a
spreadsheet application.
8.1. Front Panel
Open the Graph Waveform Arrays VI by selecting FileOpen and navigating to
labview\activity\Graph Waveforms.vi.
The Graph Waveform Arrays VI generates two arrays of waveform data and plots
them on a graph.
Click the Run button to run the VI. Notice two different waveforms are drawn on
the graph.
8.2. Block Diagram
Open the block diagram by selecting WindowShow Diagram or press <Ctrl-e>.
Add a Write To Spreadsheet File VI, available from the FunctionsFile I/O
palette, to the lower right of the block diagram. The Write to Spreadsheet VI
converts the two-dimensional (2D) array to a spreadsheet string and writes it to a
file. If you do not specify a pathname to the File Path terminal, a file dialog box
appears when you run the VI and prompts the user for a file name.
Use the Wiring tool to wire between the output of the Build Array function and the
Waveform Graph terminal to the 2D data terminal of the Write to Spreadsheet File
VI.
15
For this chapter, transpose the 2D array to have each column of the spreadsheet file
contain a data array. Use the Wiring tool to right-click the Transpose? (no:F)
terminal and select CreateConstant from the shortcut menu. This Boolean
constant controls whether or not LabVIEW transposes the 2D array before writing
the data to file.
Move the cursor over the center of the Boolean constant. LabVIEW selects the
Operating tool. Click the Boolean constant to change the value to TRUE.
Your block diagram should look similar to the following illustration.
Select FileSave As to save a copy of the VI. From the standard File dialog box that
appears, name the new VI Arrays to File.vi and save it in the labview\activity
directory.
8.3. Running the VI
Select WindowShow Panel, click the front panel window, or press <Ctrl-e> to
return to the front panel window.
Click the Run button to run the VI. After the VI generates the data arrays, a standard
File dialog box prompts you for the file name of the new file you are creating. Type in
a file name and click OK.
Use spreadsheet software or a text editor to open and view the file you just created.
You should see two columns of 100 elements.
9. Build Function Generator Using Waveform Data
Your objective is to build a simple function generator that can generate a sine wave, a triangle
wave, a square wave, and a sawtooth wave.
9.1. Front Panel
Open a new front panel by selecting FileNew VI, pressing <Ctrl-n>, or pressing the
New VI button on the LabVIEW dialog box.
Add the following items to the front panel:
o Digital Control located on the ControlsNumeric palette. Label it Amplitude.
o Digital Control located on the ControlsNumeric palette. Label it Frequency.
16
o Digital Control located on the ControlsNumeric palette. Label it Square
Duty Cycle (%).
o Enum Control located on the ControlsRing & Enum palette. Label it Signal
Source.
o Digital Control located on the ControlsNumeric palette. Label it Phase.
o Boolean Push button located on the ControlsBoolean palette. Label it Reset
Phase.
o Waveform Graph located on the ControlsGraph palette. Leave its label as
Waveform Graph.
o Boolean Stop button located on the ControlsBoolean palette.
o (Optional) Use the Coloring tool to color the button red.
Add elements to the Signal Source enum control.
o Click in the text box of the enum.
o Type Sine Wave and press <Shift-Enter> to add another element.
o Type Triangle Wave <Shift-Enter>, Square Wave <Shift-Enter>, and
Sawtooth Wave.
o Click the Enter button on the toolbar or click anywhere on the background of
the front panel to enter the elements.
Arrange the objects on the front panel to appear similar to the following illustration.
The Signal Source control selects the type of waveform that you want to generate.
The square duty cycle control is used only for setting the duty cycle of the square
wave.
9.2. Block Diagram
Open the block diagram by selecting WindowShow Diagram, pressing <Ctrl-e>, or
clicking the block diagram window.
17
Add a While Loop that fills up most of the visible area of the block diagram window.
The While Loop causes the block diagram inside it, the subdiagram, to repeat until a
TRUE or FALSE value is passed to the continuation terminal .
o Select the While Loop from the FunctionsStructures palette and drag it to
one of the corners of the block diagram. Do not release the mouse button.
o While still holding the mouse button, drag out a region to the opposite corner
of the block diagram window.
o When the region fills most of the block diagram window, as indicated by the
dotted rectangle, release the mouse button. LabVIEW creates the While Loop.
Because the Stop button will control the While Loop, wire the Stop terminal to the
continuation terminal.
o Move the Stop terminal next to the continuation terminal of the While Loop.
As you drag the Boolean terminal close to the terminal, press the spacebar to
activate automatic wiring. When LabVIEW draws a wire connecting the two
terminals, release the mouse button. You also can use the Wiring tool to wire
the two terminals together.
o Right-click the continuation terminal of the While Loop and select Stop if True
from the shortcut menu. Notice the continuation terminal changes its
appearance to the Stop if True state . When the user presses the Stop
button, it passes a TRUE value to the continuation terminal, which stops the
While Loop.
Because it is the indicator, move the Waveform Graph terminal to the right side of the
While Loop. Arrange all the other terminals, which are controls, to the left side of the
While Loop.
Between the controls and the Waveform Graph terminal, add a Case structure. The
Case structure contains different subdiagrams, which only execute when the specific
case is selected. The selector terminal of the Case structure determines which case is
selected. The case selector label at the top of the Case structure indicates which case is
currently visible.
o Select the Case structure from the FunctionsStructures palette and drag it
near the middle of the While Loop. Do not release the mouse button.
o While still holding the mouse button, drag out a region between the control
terminals and the Waveform Graph terminal.
o When the region fills up most of the area between the control terminals and the
Waveform Graph terminal, release the mouse button. LabVIEW creates the
Case structure.
Because the Signal Source Enum will control which waveform is displayed on the
graph, wire the Signal Source terminal to the selector terminal of the Case structure.
o Move the Signal Source terminal just to the left of the selector terminal of the
Case structure.
o Use the Wiring tool to wire the Signal Source terminal to the selector terminal
of the Case structure. Notice the case selector label now shows the name of one
of the elements you entered in the Signal Source enum control.
18
By default, the Case structure has two cases. Because the Signal Source enum control
contains four elements, you must add two more cases to the Case structure.
o Right-click the Case structure and select Add Case After from the shortcut
menu. Notice the case selector label indicates the new case is the Square Wave
case.
o Add another case as you did in step 7a. Notice the case selector label indicates
the new case is the Sawtooth Wave case.
Add the waveform generation VIs to their respective cases in the Case structure. Click
the increment or decrement arrow on each side of the case selector label to switch
between cases.
o Add the Sine Waveform VI located on the FunctionsAnalyzeWaveform
Generation palette to the Sine Wave case.
o Add the Triangle Waveform VI located on the
FunctionsAnalyzeWaveform Generation palette to the Triangle Wave
case.
o Add the Square Waveform VI located on the FunctionsAnalyzeWaveform
Generation palette to the Square Wave case.
o Add the Sawtooth Waveform VI located on the
FunctionsAnalyzeWaveform Generation palette to the Sawtooth Wave
case.
Use the Wiring tool to wire the terminals from each waveform generation VI to the
terminals outside the Case structure. Rearrange the position of the terminals as
necessary to maintain an orderly block diagram. The first time you wire a terminal on
the VI to a terminal outside the Case structure, a tunnel appears at the border of the
Case structure. Thereafter, as you increment through the cases, the wire from the
tunnel to the terminal outside the Case structure remains, so you only need wire from
the tunnel to the terminal on the VI to complete the wire connection.
o Wire the reset phase terminal of each VI to the Reset Phase control terminal.
o Wire the frequency terminal of each VI to the Frequency control terminal.
o Wire the amplitude terminal of each VI to the Amplitude control terminal.
o Wire the phase terminal of each VI to the Phase control terminal.
o Wire the signal out terminal of each VI to the Waveform Graph terminal.
o Because it pertains only to the Square Wave VI, move the Square Duty Cycle
(%) control terminal inside the Square Wave case of the Case structure. Wire
the duty cycle (%) terminal of the Square Wave VI to the Square Duty Cycle
(%) control terminal.
The sampling info terminal of each VI allows you to control the sample rate and
number of samples. Add a sampling info cluster to your VI.
o Use the Wiring tool to right-click the sampling info terminal and select Create
Control from the shortcut menu.
o Use the Positioning tool to drag the sampling info terminal outside the Case
structure. When you move the terminal outside the Case structure, the wire
connection is broken.
19
o Select EditRemove Broken Wires or press <Ctrl-b> to remove the broken
wire.
o Use the Wiring tool to wire the sampling info terminal outside the Case
structure to the sampling info terminal on each VI as you did in step 9.
o (Optional) You might need to move the sampling info front panel control.
Select WindowShow Panel, click the front panel window, or press <Ctrl-e>
to display the front panel. Use the Positioning tool to move the sampling info
control.
Arrange the objects on the block diagram. Your block diagram should be similar to the
following illustration. Each case is shown below the While Loop to illustrate the
contents of each case. Do not create separate Case structures.
Save the VI as function generator.vi in the labview\activity directory.
9.3. Running the VI
Set the Amplitude to 1, frequency to 10, reset phase to ON, and signal source to Sine
Wave, Fs (the sampling rate) to 1.00k, and #s (the number of samples) to 100. Because
Fs is 1000 (1.00k) and the frequency is 10 Hz, every 100 samples corresponds to one
cycle.
Run the VI and observe the resulting plot.
20
Change #s to 200, 300, and 400. How many cycles of the waveform do you see? Why?
Reset the #s control to 100 and change frequency to 10.01 Hz. What happens? Why?
Change reset phase to ON. Now what happens? Why?
(Optional) Select different waveforms from the Signal Source enum and repeat steps 1
through 5.
10. Use Property Nodes and Invoke Nodes
Your objective is to create a VI that programmatically modifies the appearance of a Tank
indicator using a property node and programmatically changes the VI icon using an invoke
node.
10.1. Front Panel
Open a new front panel by selecting FileNew VI, pressing <Ctrl-n>, or pressing the
New VI button on the LabVIEW dialog box.
Add a Tank indicator to the front panel.
o Select a Tank indicator located on the ControlsNumeric palette and place it
on the front panel. Leave the default label.
o Double-click the topmost scale marker and change the value to 100.
o Right-click the tank and select Visible ItemsDigital Display to show the
digital display.
Select a digital control located on from the ControlsNumeric palette and place it to
the left of the Tank indicator. Label it Limit Setting. Set the value to 50.
(Optional) Define the current values of the controls as the default values by right-
clicking each control and selecting Data OperationsMake Current Value Default
from the shortcut menu.
Select two Path Controls located on the ControlsString & Path palette and place
each below the Limit Setting control. Label the first Normal Image and the second
High Image.
Enter paths to the image files for each path control.
o Click the browse button next to the Normal Image path control. In the standard
file dialog that appears, navigate to \labview\activity\solution\low_icon.bmp
and click the OK button.
o For the High Image control, navigate to
\labview\activity\solution\high_icon.bmp and click the OK button.
Arrange the objects on the front panel. Your VI should appear similar to following
illustration.
21
10.2. Block Diagram
Open the block diagram by selecting WindowShow Diagram, clicking the block
diagram window, or pressing <Ctrl-e>.
Add a While Loop.
o Select a While Loop from the FunctionsStructures palette and drag it to a
corner of the block diagram window. Do not release the mouse button.
o While holding the mouse button, drag out an area that fills most of the block
diagram window. When the area is large enough to encompass all the
terminals, release the mouse button. LabVIEW draws a While Loop.
Move the stop terminal next to the continuation terminal of the While Loop and wire
them together.
Add a Random Number (0-1) function located on the FunctionsNumeric palette to
the upper left of the While Loop.
Add a Multiply function located on the FunctionsNumeric palette, and wire one of
its inputs to the Random Number (0-1) function. Right-click the other input terminal
and select CreateConstant from the shortcut menu. Type 100 for the value of the
constant and click the Enter button on the toolbar.
Use the Wiring tool to wire the output of the Multiply function to the Tank terminal.
Select a Greater or Equal? function located on the FunctionsComparison palette and
place it near the wire that connects the Multiply function and the Tank terminal. Use
the Wiring tool to connect the input of the Greater or Equal? function to the wire
between the Multiply function and the Tank terminal.
Add a Case structure next to the output of the Greater or Equal? function.
o Select a Case structure from the FunctionsStructures palette and drag it next
to the Greater or Equal? function. Do not release the mouse button.
o While holding the mouse button, drag out an rectangle suitable in size for three
or four functions and their wire connections. Release the mouse button.
LabVIEW draws a Case structure.
Use the Wiring tool to wire the output of the Greater or Equal? function to the selector
terminal of the Case structure. This causes the Case structure to select a case
depending on the result of the Greater or Equal? function.
Create a color box constant in each case of the Case structure.
22
o Select a color box constant from the FunctionsNumericAdditional
Numeric Constants palette and place it in the Case structure.
o Click the color box constant. Select a blue color from the color picker that
appears. You also can use the Coloring tool to right-click the constant to
change the color.
o Click the increment button at the top of the Case structure to switch cases. Add
another color box constant to this case. Place it in the same place as you placed
the constant in the other case.
o Change the color of this constant to red as you did in step 10b.
Create a Property Node for the Tank terminal.
o Right-click the Tank terminal and select CreateProperty Node from the
shortcut menu. A Tank Property Node appears next to the terminal.
o Right-click the Property Node and select PropertiesFill Color from the
shortcut menu.
o Because this Property Node will change the fill color of the Tank, rather than
read its color, right-click the Property Node and select Change to Write from
the shortcut menu.
o Move the Tank Property Node to the right of the Case structure.
Move the Normal Image terminal into the case that has the blue color box constant.
Move the High Image terminal into the case that has the red color box constant.
Add an Invoke Node.
o Select an Invoke Node from the FunctionsApplication Control palette.
Place it to the right of the Case structure and across from the High Image
terminal.
o Right-click the Invoke Node and select Select VI Server ClassVI from the
shortcut menu.
o Right-click the Invoke Node and select MethodsSet VI Icon from the
shortcut menu.
Wire each color box constant to the Fill Color terminal of the Tank property node.
Wire each image terminal to the Image File terminal of the Invoke Node.
Add timing to the VI.
o Select the Wait Until Next ms Multiple function from the FunctionsTime &
Dialog palette and place it in an open area of the While Loop.
o Use the Wiring tool to right-click the input terminal of the Wait Until Next ms
Multiple function and select CreateConstant. Enter 1000. This causes the
While Loop to wait 1 second (1000 milliseconds) between iterations.
Use the Positioning tool to arrange the objects on the block diagram. Your block
diagram should look similar to the following illustration.
23
10.3. Running the VI
Click the Run button to run the VI. The VI compares the level of the tank to the Limit
Setting control. If the tank value is greater than or equal to the Limit Setting value,
LabVIEW turns the tank color to red. If the data falls below the limit, the tank turns
blue.
Notice the VI icon also changes when the level of the tank exceeds the Limit Setting
value. The icon changes to the dimmed lightbulb when level of the tank is below the
Limit Setting value and to the lit lightbulb when the level is greater than or equal to
the Limit Setting value.
Click the stop button to stop the VI.
Save the VI as Tank Limit.vi in the labview\activity directory.
10.4. Optional Steps
Prevent the user from changing the image files that are used for the VI icon.
o Right-click the path controls on the front panel and select AdvancedHide
Control from the shortcut menu.
o You also can hide the control from the block diagram. Right-click the terminal
for the control and select Hide Control from the shortcut menu.
o Change each control to a constant by right-clicking the terminal on the block
diagram and selecting Change to Constant from the shortcut menu.
Experiment with modifying other properties of the Tank indicator.
Experiment with modifying other methods of the Invoke Node.