LabView Pratimai
LabView Pratimai
Course Manual
UŽDUOTYS IR PRATIMAI
Copyright
Copyright © 1993, 2000 by National Instruments Corporation, 11500 North Mopac Expressway, Austin, Texas 78759-3504.
Under the copyright laws, this publication may not be reproduced or transmitted in any form, electronic or mechanical, including
photocopying, recording, storing in an information retrieval system, or translating, in whole or in part, without the prior written
consent of National Instruments Corporation.
Trademarks
LabVIEW™, National Instruments™, ni.com™, and PXI™ are trademarks of National Instruments Corporation.
Product and company names mentioned herein are trademarks or trade names of their respective companies.
Lesson 2 Creating, Editing, and Debugging a VI
Front Panel
Block Diagram
1 1
• You can bend a wire by clicking to tack the wire down and moving
the cursor in a perpendicular direction. Press the spacebar to toggle
the wire direction.
• To identify terminals on the nodes, right-click the Multiply and Add
functions and select Visible Items»Terminals from the shortcut
menu to display the connector pane. Return to the icons after
wiring by right-clicking the functions and selecting Visible
Items»Terminals from the shortcut menu to remove the checkmark.
• When you move the Wiring tool over a terminal, the terminal area
blinks, indicating that clicking will connect the wire to that terminal
and a tip strip appears, listing the name of the terminal.
• To cancel a wire you started, press the <Esc> key, right-click, or
click the source terminal.
10. Display the front panel by clicking it or by selecting Window»Show
Panel.
11. Save the VI, because you will use this VI later in the course.
a. Select File»Save.
b. Navigate to c:\exercises\LV Basics I.
Note Save all the VIs you edit in this course in c:\exercises\LV Basics I.
Front Panel
1. Select File»Open and navigate to c:\exercises\LV Basics I to
open the Convert C to F VI.
(Windows, Sun, and HP-UX) If you closed all open VIs, click the Open VI
button on the LabVIEW dialog box.
The following front panel appears.
2. Right-click the icon in the upper right corner of the front panel and select
Edit Icon from the shortcut menu. The Icon Editor dialog box appears.
3. Double-click the Select tool, shown at left, on the left side of the Icon
Editor dialog box to select the default icon.
4. Press the <Delete> key to remove the default icon.
5. Double-click the Rectangle tool, shown at left, to redraw the border.
6. Create the following icon.
a. Use the Text tool, shown at left, to click the editing area.
b. Type C and F.
c. Double-click the Text tool and change the font to Small Fonts.
d. Use the Pencil tool, shown at left, to create the arrow.
Note To draw horizontal or vertical straight lines, press the <Shift> key while you use
the Pencil tool to drag the cursor.
e. Use the Select tool and the arrow keys to move the text and arrow
you created.
f. Select the B & W icon and select 256 Colors in the Copy from field
to create a black and white icon, which LabVIEW uses for printing
unless you have a color printer.
g. When the icon is complete, click the OK button to close the Icon
Editor dialog box. The icon appears in the icon in the upper right
corner of the front panel and block diagram.
7. Right-click the icon on the front panel and select Show Connector from
the shortcut menu to define the connector pane terminal pattern.
LabVIEW selects a connector pane pattern based on the number of
controls and indicators on the front panel. For example, this front panel
has two terminals, deg C and deg F, so LabVIEW selects a connector
pane pattern with two terminals, shown at left.
8. Assign the terminals to the digital control and digital indicator.
a. Select Help»Show Context Help to display the Context Help
window. View each connection in the Context Help window as you
make it.
b. Click the left terminal in the connector pane. The tool automatically
changes to the Wiring tool, and the terminal turns black.
c. Click the deg C control. The left terminal turns orange and a
marquee highlights the control.
d. Click an open area of the front panel. The marquee disappears and
the terminal changes to the data type color of the control to indicate
that you connected the terminal.
e. Click the right terminal in the connector pane and click the deg F
indicator. The right terminal turns orange.
f. Click an open area on the front panel. Both terminals are orange.
g. Move the cursor over the connector pane. The Context Help
window shows that both terminals are connected to floating-point
values.
9. Select File»Save to save the VI, because you will use this VI later in the
course.
10. Select File»Close to close the Convert C to F VI.
Measure the voltage using the plug-in DAQ device in your computer and
convert the voltage into a temperature reading. The sensor is hard-wired to
Channel 0 of the DAQ device.
Front Panel
1. Select File»New to open a new front panel.
(Windows, Sun, and HP-UX) If you closed all open VIs, click the New VI
button on the LabVIEW dialog box.
2. Create the thermometer indicator, as shown in the following front panel.
Block Diagram
8. Select Window»Show Diagram to display the block diagram.
9. Build the following block diagram.
Note If a DAQ device and/or DAQ Signal Accessory is not available, use the (Demo)
Read Voltage VI located on the Functions»User Libraries»Basics I Course palette
instead of the Read Voltage VI to simulate the Read Voltage VI operation.
Tip To identify terminals on the nodes, right-click the icon and select Visible
Items»Terminal from the shortcut menu to display the connector pane.
a. Right-click the icon in the upper right corner of the front panel and
select Edit Icon from the shortcut menu. The Icon Editor dialog
box appears.
b. Double-click the Select tool, shown at left, on the left side of the
Icon Editor dialog box to select the default icon.
c. Press the <Delete> key to remove the default icon.
d. Double-click the Rectangle tool, shown at left, to redraw the border.
e. Use the Pencil tool, shown at left, to draw an icon that represents the
thermometer.
f. Use the Foreground and Fill tools to color the thermometer red.
Note To draw horizontal or vertical straight lines, press the <Shift> key while you use
the Pencil tool to drag the cursor.
g. Double-click the Text tool, shown at left, and change the font to
Small Fonts.
h. Select the B & W icon and select 256 Colors in the Copy from field
to create a black and white icon, which LabVIEW uses for printing
unless you have a color printer.
i. When the icon is complete, click the OK button. The icon appears
in the upper right corner of the front panel.
15. Right-click the icon and select Show Connector from the shortcut menu
and assign terminals to the switch and the thermometer.
a. Click the left terminal in the connector pane.
b. Click the Temp Scale control. The left terminal turns green.
c. Click the right terminal in the connector pane.
d. Click the Temperature indicator. The right terminal turns orange.
e. Click an open area on the front panel.
16. Save the VI, because you will use this VI later in the course.
a. Select File»Save.
b. Navigate to c:\exercises\LV Basics I.
c. Type Thermometer.vi in the dialog box.
d. Click the Save button.
17. Select File»Close to close the VI.
Front Panel
Block Diagram
12. Save the VI as Temperature Monitor.vi, because you will use this
VI later in the course.
13. Display the front panel by clicking it or by selecting Window»Show
Panel.
14. Use the Operating tool to click the vertical toggle switch and turn it to
the ON position.
15. Run the VI.
The While Loop is an indefinite looping structure. The diagram within
its border executes as long as the specified condition is true. In this
example, as long as the switch is on (TRUE), the Thermometer VI takes
and returns a new measurement and displays it on the waveform chart.
16. Click the vertical toggle switch to stop the acquisition. This changes the
loop condition to FALSE and the loop ends.
17. Format and customize the X and Y scales of the waveform chart to suit
your display preferences and data.
a. Right-click the chart and select Y Scale»Formatting from the
shortcut menu. The following dialog box appears.
b. Click the grid style selector and select different styles for the axes
from the sub-menu that appears to experiment with different x- and
y-axis grid options. You also can experiment with scale styles,
scaling factors, mapping mode, and the format and precision of the
axis displays.
c. Select the values shown in the previous dialog box and click the OK
or Cancel buttons.
18. Right-click the waveform chart and select Data Operations»Clear
Chart from the shortcut menu to clear the display buffer and reset the
waveform chart. If the VI is running, select Clear Chart from the
shortcut menu.
For example, consider the following vertical toggle switch. The default
value of the switch is off (FALSE).
Switch When Pressed—Changes the control value each time you click the
control with the Operating tool. The action is similar to that of a ceiling light
switch. How often the VI reads the control does not affect this action.
Switch When Released—Changes the control value only after you release
the mouse button during a click within the graphical boundary of the
control. How often the VI reads the control does not affect this action.
Switch Until Released—Changes the control value when you click the
control and retains the new value until you release the mouse button, at
which time the control reverts to its original value. The action is similar to
that of a door buzzer. How often the VI reads the control does not affect this
action.
Latch When Pressed—Changes the control value when you click the
control and retains the new value until the VI reads it once, at which time
the control reverts to its default value. This action happens whether or not
you continue to hold down the mouse button. This action is similar to that
of a circuit breaker and is useful for stopping While Loops or having the VI
do something only once each time you set the control.
Latch When Released—Changes the control value only after you release
the mouse button. When the VI reads the value once, the control reverts to
the old value. This action guarantees at least one new value.
Latch Until Released—Changes the control value when you click the
control and retains the value until the VI reads the value once or until you
release the mouse button, whichever occurs last.
19. Modify the vertical toggle switch so temperature is plotted on the graph
each time you run the VI.
a. Stop the VI if it is running.
b. Use the Operating tool to click the vertical toggle switch and turn it
to the ON position.
c. Right-click the switch and select Data Operations»Make Current
Value Default from the shortcut menu. This sets the ON position as
the default value.
d. Right-click the switch and select Mechanical Action»Latch When
Pressed from the shortcut menu.
20. Run the VI.
21. Use the Operating tool to click the vertical switch to stop the acquisition.
The switch changes to the OFF position and changes back to ON after
the While Loop condition terminal reads the value.
Adding Timing
When this VI runs, the While Loop executes as quickly as possible.
However, you might want to take data at certain intervals, such as once per
second or once per minute.
Control loop timing with the Wait Until Next ms Multiple function located
on the Functions»Time & Dialog palette. This function ensures that no
iteration is shorter than the specified number of milliseconds.
Front Panel
1. Open the Temperature Monitor VI, which you built in Exercise 4-1.
Block Diagram
3. Display the block diagram.
4. Right-click the right or left border of the While Loop and select Add
Shift Register from the shortcut menu to create a shift register.
5. Right-click the left terminal of the shift register and select Add Element
from the shortcut menu to add an element to the shift register.
6. Modify the block diagram as shown in the previous block diagram.
7. Select Functions»Select a VI, navigate to c:\exercises\LV
Basics I, double-click the Thermometer VI, which you built in
Exercise 3-2, and place the VI on the block diagram. This VI returns one
temperature measurement from the temperature sensor and is used to
initialize the left shift registers before the loop starts.
The Compound Arithmetic function located on the
Functions»Numeric palette returns the sum of the current temperature
and the two previous temperature readings. Place the Positioning tool at
the corner of the function until the cursor changes to the resizing
handles, shown at left. Click the corner and drag to stretch the function
into a three-input Add function.
The Divide function located on the Functions»Numeric palette returns
the average of the last three temperature readings.
During each iteration of the While Loop, the Thermometer VI takes one
temperature measurement. The VI adds this value to the last two
measurements stored in the left terminals of the shift register. The VI
divides the result by three to find the average of the three measurements,
the current measurement plus the previous two. The VI displays the
average on the waveform chart. Notice that the VI initializes the shift
register with a temperature measurement.
8. Save the VI, because you will use this VI later in the course.
9. Run the VI.
Multiplot Charts
Charts can accommodate more than one plot. You must bundle the data
together in the case of multiple scalar inputs.
10. Modify the block diagram to display both the average and the current
temperature measurement on the same waveform chart.
a. Modify the block diagram as shown in the following block diagram.
Customizing Charts
You can customize waveform charts to match your data display
requirements or to display more information. Features available for
waveform charts include: a plot legend, a scale legend, a graph palette,
a digital display, a scroll bar, and a buffer. By default, a waveform chart
displays the graph legend showing when you place it on a front panel.
Note The waveform chart size has a direct effect on the display of axis scales. Increase
the waveform chart size if you encounter problems customizing the axis.
12. Right-click the waveform chart and select Visible Items»Scale Legend
from the shortcut menu to show the scale legend. You can place the scale
legend anywhere on the front panel. The scale legend contains the
following components.
X Axis
Y Axis
the new text. Change Plot 1 to Current Temp in the same way. If the
text does not fit, resize the plot legend from the left corner of the plot
legend with the Positioning tool. The Positioning tool changes to a
frame corner when you can resize the plot legend.
Right-click the plot in the plot legend to set the plot line style and point
style. You also can color the plot background or traces by right-clicking
the plot legend and selecting Color from the shortcut menu.
15. Right-click the waveform chart and select Visible Items»Graph
Palette from the shortcut menu to show the graph palette. You can place
the graph palette anywhere on the front panel. The graph palette contains
the following options.
Zoom Subpalette
Note Often, modifying the axis text format requires more physical space than was
originally set aside for the axis. If you change the axis, the display might become larger
than the maximum size that the VI can correctly present.
Front Panel
1. Open a new VI and build the front panel shown below.
Block Diagram
You will use this VI later, so be sure to save it as the instructions below
describe.
Front Panel
1. Open a new VI and build the front panel shown below.
Block Diagram
2. Build the block diagram shown below. Refer to the following
instructions.
You can display more than one plot on a graph. This feature not only
saves space on the front panel, it is also an effective means of making
comparisons between plots. XY and waveform graphs automatically
adapt to multiple plots.
Thermometer VI, available on the Functions»User Libraries»Basics 1
Course palette—Returns one temperature measurement.
Wait Until Next ms Multiple function, available on the Functions»Time
& Dialog palette—Causes the For Loop to execute every 0.25 s
(250 ms) in this exercise.
Array Max & Min function, available on the Functions»Array
palette—Returns the maximum and minimum temperature measured
during the acquisition in this exercise.
Mean VI, available on the Functions»Mathematics»Probability and
Statistics palette—Returns the average of the temperature
measurements in this exercise.
Bundle function, available on the Functions»Cluster
palette—Assembles the plot components into a single cluster in this
exercise. The components include the initial X value (0), the delta X
value (0.25), and the Y array (temperature data). Use the Positioning
tool to resize the function by dragging one of the corners.
General Polynomial Fit VI, available on the
Functions»Mathematics»Curve Fitting palette—Returns an array
that is a polynomial fit to the temperature array in this exercise. This
exercise uses five as the polynomial order. The General Polynomial Fit
VI determines the best fit for the points in the temperature array.
b. Right-click the Fitted plot display in the Legend of the Temp Graph
and select the second choice from Bar Plots in the plot legend
shortcut menu.
You will use this VI later, so be sure to save it as the instructions below
describe.
Block Diagram
Note On the Macintosh, you must provide values for the Frequency, Duration, and
Intensity inputs to the Beep VI.
Notice that there are no icons in the False case of the Case structure. If
the temperature that the Thermometer VI returns is greater than the set
limit, the LED turns on, the VI executes the True case, and a beep
sounds. If the temperature is less than the set limit, the LED turns off,
the VI executes the False case, and there is no beep.
5. Save the VI. Return to the front panel and enter 80 in the High Limit
control. Run the VI.
Place your finger on the temperature sensor. When the temperature
exceeds 80°, the LED will turn on and a beep will sound.
6. Close the VI.
End of Exercise 6-2
You will build a VI that uses the Formula Node to evaluate a complex
mathematical expression and graphs the results.
Front Panel
Block Diagram
You will modify the Temperature Control VI to save the time and current
temperature to a data file. You will use this VI later, so be sure to save it as
the instructions below describe.
Front Panel
Block Diagram
Format Into File function (File I/O palette). This function converts the
temperature measurement (a number) to a string and builds and writes
to file the following formatted data string:
Time String (tab) Temperature String (end of line).
Resize the function to have four argument terminals.
Simple Error Handler VI (Time & Dialog palette). This VI checks the
error cluster and displays a dialog box if an error occurred.
Windows
5. Start the WordPad or NotePad application or another word processor or
a spreadsheet. Find and open the file temp.txt.
UNIX
5. Run the Text Editor application. Load the file temp.txt.
Macintosh
5. Switch to the Finder and launch TeachText or another word processor or
a spreadsheet. Find and open the file temp.txt.
6. After you load the file into the word processor or spreadsheet, notice that
the time appears in the first column and the temperature data appears in
the second column. Quit your word processor or spreadsheet and return
to LabVIEW.
In the previous exercise, you formatted the string so that tabs separated the
columns and end of lines separated the rows. In this exercise, you will
examine a VI that saves numeric arrays to a file in a format you can access
with a spreadsheet.
Front Panel
Block Diagram
Sine Array
..
.
Cosine Array
..
.
.. .. ..
. . .
Note This example had only three arrays stored in the file. To include more arrays,
you can increase the number of inputs to the Build Array function.
Windows
3. Open any word processing or spreadsheet application such as Notepad
or WordPad.
4. Find and open the file wave.txt and observe that the sine waveform
data appears in the first column, the random waveform data appears in
the second column, and the cosine waveform data appears in the third
column.
5. Exit the word processor and return to LabVIEW.
UNIX
3. Run the Text Editor application.
4. Find and open the file wave.txt and observe that the sine waveform
data appears in the first column, the random waveform data appears in
the second column, and the cosine waveform data appears in the third
column.
5. Exit the Text Editor and return to LabVIEW.
Macintosh
3. Switch to the Finder and launch TeachText (or any word processor or
spreadsheet) by double-clicking on its icon.
4. Find and open the file wave.txt and observe that the sine waveform
data appears in the first column, the random waveform data appears in
the second column, and the cosine waveform data appears in the third
column.
5. Quit TeachText and return to LabVIEW.
Log your data as shown below in the example spreadsheet. Remember that
in a spreadsheet, tabs separate columns and end of lines separate rows.
Additional Exercises
7-7 Build a VI that generates a 2D array of 3 rows × 100 columns of
Challenge random numbers and writes the data transposed to a spreadsheet file.
The file should contain a header for each column, as shown below.
Use the high-level File VIs from the File I/O subpalette for this
exercise. Save the VI as More Spreadsheets.vi.
Hint: Use the Write Characters To File VI to write the header and
then the Write To Spreadsheet File VI to write the numerical data to
the same file.
Header
.
.
.
7-9 Modify the Temperature Logger VI from Exercise 7-4 so that the VI
does not create a new file each time you run the VI. The VI should
append the data to the end of the existing file, temp.dat, that the
Temperature Logger VI created earlier. Run the VI several times
and then use a word processor to confirm that the VI appended new
temperature readings. Save the VI as Temperature Logger
2.vi.
Hint: Delete the Format Into File function and replace it with the
Format Into String and Write File functions. Use the pos mode and
pos offset parameters of the Write File function to move the current
file mark.