Академический Документы
Профессиональный Документы
Культура Документы
• Run the VI by clicking the Run button in the toolbar. The button changes
appearance to indicate that the VI is running.
• Select Window»Show 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
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 File»Close.
• Do not close the Temperature System Demo VI, because you will use it in the next
chapter.
2
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.
• 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.
3
3. Create a VI
Your objective is to build a simple VI that converts a Celsius temperature reading to
Fahrenheit.
• 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 Items»Label 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
Items»Digital 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 Controls»Numeric 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.
4
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.
• Select a Multiply function from the Functions»Numeric 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.
5
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 Create»Constant. 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
Functions»Numeric 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
Create»Constant, as you did in step 4. Type 32 and click the Enter button or click
anywhere on the block diagram.
• Now that you’ve 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.
6
• 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 File»Close to close the VI.
4. Document a VI
Your objective is to document a VI that you have created.
• 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.
7
• 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 Help»Show 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 File»Open
and navigating to labview\activity\solution\Convert C to F.vi.
Block Diagram
• Select Window»Show Diagram.
• If the Tools palette is not open, select Window»Show Tools Palette.
8
• 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.
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.
9
• 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.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 File»New and selecting Start from
template.
10
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.
11
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.
12
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.
13
• Click the Run button to run the VI.
• Save the VI as Multiple Random Plot.vi in the labview\activity directory.
14
• 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 Create»Constant 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 File»Save 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.
15
o Digital Control located on the Controls»Numeric palette. Label it Square
Duty Cycle (%).
o Enum Control located on the Controls»Ring & Enum palette. Label it Signal
Source.
o Digital Control located on the Controls»Numeric palette. Label it Phase.
o Boolean Push button located on the Controls»Boolean palette. Label it Reset
Phase.
o Waveform Graph located on the Controls»Graph palette. Leave its label as
Waveform Graph.
o Boolean Stop button located on the Controls»Boolean 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.
16
• 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 Functions»Structures 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 Functions»Structures 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.
17
• 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 Functions»Analyze»Waveform
Generation palette to the Sine Wave case.
o Add the Triangle Waveform VI located on the
Functions»Analyze»Waveform Generation palette to the Triangle Wave
case.
o Add the Square Waveform VI located on the Functions»Analyze»Waveform
Generation palette to the Square Wave case.
o Add the Sawtooth Waveform VI located on the
Functions»Analyze»Waveform 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.
18
o Select Edit»Remove 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 Window»Show 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.
19
• 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.
20
10.2. Block Diagram
• Open the block diagram by selecting Window»Show Diagram, clicking the block
diagram window, or pressing <Ctrl-e>.
• Add a While Loop.
o Select a While Loop from the Functions»Structures 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 Functions»Numeric palette to
the upper left of the While Loop.
• Add a Multiply function located on the Functions»Numeric palette, and wire one of
its inputs to the Random Number (0-1) function. Right-click the other input terminal
and select Create»Constant 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 Functions»Comparison 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 Functions»Structures 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.
21
o Select a color box constant from the Functions»Numeric»Additional
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 Create»Property Node from the
shortcut menu. A Tank Property Node appears next to the terminal.
o Right-click the Property Node and select Properties»Fill 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 Functions»Application 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 Class»VI from the
shortcut menu.
o Right-click the Invoke Node and select Methods»Set 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 Functions»Time &
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 Create»Constant. 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.
22
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.
23