Skip to main content

CHAPTER 2 ( CUSTOMIZING A VI)

You can choose one of many LabVIEW template VIs to use as a starting
point when building VIs. However, sometimes you need to build a VI for
which a template is not available. This chapter teaches you how to build
and customize a VI without using a template.


  • Building a VI from a Blank VI

In the following exercises, you will open a blank VI and add structures and
Express VIs to the block diagram to build a new VI. You will build a VI
that generates a signal, reduces the number of samples in the signal, and
displays the resulting data in a front panel table.
  • Opening a Blank VI
If no template is available for the VI you want to build, you can start with
a blank VI and add Express VIs to accomplish a specific task.
Complete the following steps to open a blank VI.

1. In the Getting Started window, click the Blank VI link in the New
section or press the <Ctrl-N> keys to open a blank VI.
A blank front panel window and block diagram window appear.

2. Display the block diagram.

3. If the Functions palette is not visible, right-click any blank space on
the block diagram to display a temporary version of the Functions
palette. Click the thumbtack, shown at left, in the upper left corner of
the Functions palette to pin the palette so it is no longer temporary.

  • Adding an Express VI That Simulates a Signal
Complete the following steps to find the Express VI you want to use and
add it to the block diagram.

1. Select Help»Show Context Help from the front panel or the block
diagram to display the Context Help window.
You also can click the Show Context Help Window button, shown at
left, on the front panel or block diagram toolbar to display the Context
Help window.

2. On the Functions palette, select the Express»Input palette and move
the cursor over one of the Express VIs on the Input palette.
When you move the cursor over a VI, the Context Help window
displays information about that VI.

3. Use the information that appears in the Context Help window to find
the Express VI that can simulate a sine wave signal.
Keep the Context Help window open. The context help provides
useful information as you complete the rest of this exercise.

4. Select the Express VI that can simulate a sine wave signal and place it
on the block diagram. The Configure Simulate Signal dialog box
appears.

5. Move the cursor over the various options in the Configure Simulate
Signal dialog box, such as Frequency (Hz) and Amplitude. Read the
information that appears in the Context Help window.

6. Configure the Simulate Signal Express VI to generate a sine wave with
a frequency of 10.7 and amplitude of 2.
The signal in the Result Preview window changes to reflect the
configured sine wave.

7. Click the OK button to save the current configuration and close the
Configure Simulate Signal dialog box.

8. Move the cursor over the Simulate Signal Express VI and read the
information that appears in the Context Help window.
The Context Help window displays information about how you
configured the Simulate Signal Express VI in addition to the standard
context help description.

9. Save the VI as Reduce Samples.vi in an easily accessible location.

  • Searching the Help and Modifying a Signal
Complete the following steps to use the LabVIEW Help to search for the
Express VI that reduces the number of samples in a signal.

1. On the block diagram, move the cursor over the Simulate Signal
Express VI to display the Context Help window and click the
Detailed help link to display the Simulate Signal topic in the LabVIEW
Help. You might have to enlarge or scroll down in the Context Help
window to see the Detailed help link.

2. Click the Search tab, enter sample compression in the Type in the
word(s) to search for text box, and press the <Enter> key. You can
place quotation marks around the phrase to search for the exact phrase.
For example, you can enter "sample compression" to narrow the
search results.
This word choice reflects what you want this Express VI to
do—compress, or reduce, the number of samples in a signal.
You also can click the Index tab to search keywords and concepts.

3. Double-click the Sample Compression topic in the search results to
display the topic that describes the Sample Compression Express VI.

4. After you read the description of the Express VI, click the Add to the
block diagram button to place the Express VI on the cursor.

5. Move the cursor to the block diagram.

6. Add the Sample Compression Express VI to the block diagram to the
right of the Simulate Signal Express VI.
When you know which item you want to add to the block diagram or
front panel, you can use the Quick Drop dialog box to quickly find the
item and add it to the block diagram or front panel. Select Quick Drop
from the View menu to display this dialog box. You also can press the
<Ctrl-Space> keys. (Mac OS X) Press the <Command-Shift-Space>
keys.

7. Configure the Sample Compression Express VI to reduce the signal by
a factor of 25 using the mean of these values.

8. Click the OK button to save the current configuration and close the
Configure Sample Compression dialog box.

9. Use the Wiring tool to wire the Sine output of the Simulate Signal
Express VI to the Signals input of the Sample Compression
Express VI.

  • Customizing a User Interface from the Block Diagram
In the previous exercises, you added controls and indicators to the front
panel using the Controls palette. You also can create controls and
indicators from the block diagram.
Complete the following steps to create controls and indicators from the
block diagram.

1. On the block diagram, right-click the Mean output of the Sample
Compression Express VI and select Create»Numeric Indicator from
the shortcut menu to create a numeric indicator. A Mean indicator,
shown at left, appears on the block diagram.

2. Right-click the Mean output of the Sample Compression Express VI
and select Insert Input/Output from the shortcut menu to insert the
Enable input.
In previous exercises, you learned to add inputs and outputs by
expanding the Express VI using the down arrows. Using the shortcut
menu is a different way to display and select the inputs and outputs of
an Express VI.

3. Right-click the Enable input and select Create»Control from the
shortcut menu to create a switch. A Boolean control, shown at left,
appears on the block diagram.
Control terminals have a thicker border than indicator terminals. Also,
an arrow appears on the right of the terminal if the terminal is a control,
and an arrow appears on the left of the terminal if the terminal is an
indicator.

4. Right-click the wire that connects the Sine output of the Simulate
Signal Express VI to the Signals input of the Sample Compression
Express VI and select Create»Graph Indicator from the shortcut
menu.

5. Use the Wiring tool to wire the Mean output of the Sample
Compression Express VI to the Sine graph indicator.
The Merge Signals function appears.

6. Arrange the objects on the block diagram.

7. Display the front panel.
The controls and indicators you added appear in the front panel with
labels that correspond to the inputs and outputs from which you
created the controls and indicators.

8. Save the VI.

  • Configuring a VI to Run Continuously until the User Stops It
In the current state, the VI runs once, generates one signal, and then stops
running. To run the VI until a condition occurs, you can use a While Loop.
Complete the following steps to add a While Loop to the block diagram.

1. Display the front panel and run the VI.
The VI runs once and then stops. The front panel does not have a stop
button.

2. Display the block diagram.

3. Click the Search button, shown at left, on the Functions palette, and
enter While in the text box. LabVIEW searches as you type the first
few letters and displays any matches in the search results text box.

4. Double-click While Loop <<Execution Control>> to display the
Execution Control subpalette and temporarily highlight the While
Loop on the subpalette.

5. Select the While Loop on the Execution Control palette.

6. Move the cursor to the upper left corner of the block diagram. Click
and drag the cursor diagonally to enclose all the Express VIs and
wires.

7. Release the mouse to place the While Loop around the Express VIs and
wires.
The While Loop, shown at left, appears with a STOP button wired to
the conditional terminal. This While Loop is configured to stop when
the user clicks the STOP button.

8. Display the front panel and run the VI.
The VI now runs until you click the STOP button. A While Loop
executes the VIs and functions inside the loop until the user clicks the
STOP button.

9. Click the STOP button and save the VI.

  • Using the Error List Window
If a VI contains an indicator you do not want to use, you can delete it.
Complete the following steps to remove the Mean indicator from the front
panel.

1. Display the front panel and move the cursor over the Mean indicator
until the Positioning tool appears.

2. Click the Mean indicator, shown at left, to select it and press the
<Delete> key.

3. Display the block diagram.
A wire appears as a dashed black line with a red X in the middle, shown
at left. The dashed black line is a broken wire. The Run button, shown
at left, appears broken to indicate the VI cannot run.

4. Click the broken Run button to display the Error list window.
The Error list window lists all errors in the VI and provides details
about each error. You can use the Error list window to locate errors.

5. In the errors and warnings list, select the Wire: has loose ends
error and click the Help button to display more information about the
error.

6. In the errors and warnings list, double-click the Wire: has loose
ends error to highlight the broken wire.

7. Press the <Ctrl-B> keys to delete the broken wire.
Pressing the <Ctrl-B> keys deletes all broken wires on the block diagram.
You can press the <Delete> key to delete only the selected wire.

8. Select View»Error List to display the Error list window. No errors
appear in the errors and warnings field.

9. Click the Close button to close the Error list window.
The Run button no longer appears broken.


  • Controlling the Speed of Execution

To plot the points on the waveform graph more slowly, you can add a time
delay to the block diagram.
Complete the following steps to control the speed at which the VI runs.

1. On the block diagram, search for the Time Delay Express VI, shown at
left, on the Functions palette and place it inside the While Loop.
You can use the Time Delay Express VI to control the execution rate
of the VI.

2. Enter 0.25 in the Time delay (seconds) text box.
This time delay specifies how fast the loop runs. With a 0.25 second
time delay, the loop iterates once every quarter of a second.

3. Click the OK button to save the current configuration and close the
Configure Time Delay dialog box.

4. Display the front panel and run the VI.

5. Click the Enable switch and examine the change on the graph.
If the Enable switch is on, the graph displays the reduced signal. If the
Enable switch is off, the graph does not display the reduced signal.

6. Click the STOP button to stop the VI.

  • Using a Table to Display Data
Complete the following steps to display a collection of mean values in a
front panel table.

1. Display the front panel.

2. On the Controls palette search for the Express Table indicator and
add it to the right of the waveform graph.

3. Display the block diagram.
LabVIEW wired the Table terminal to the Build Table Express VI.

4. If the Build Table Express VI and the Table terminal are not selected
already, click an open area on the block diagram to the left of the Build
Table Express VI and the Table terminal. Drag the cursor diagonally
until the selection rectangle encloses the Build Table Express VI and
the Table terminal, shown at left.
A moving dashed outline, called a marquee, highlights the Build Table
Express VI, the Table terminal, and the wire joining the two.

5. Drag the objects into the While Loop to the right of the Sample
Compression Express VI.
If you drag objects near the border of the While Loop, the loop resizes
to enclose the Build Table Express VI and the Table terminal after you
add the object to the block diagram.

6. Use the Wiring tool to wire the Mean output of the Sample
Compression Express VI to the Signals input of the Build Table
Express VI.

7. The block diagram should appear.

8. Display the front panel and arrange the controls and indicators.

9. Run the VI.

10. Click the Enable switch.
If the Enable switch is on, the table displays the mean values of every
25 samples of the sine wave. If the Enable switch is off, the table does
not record the mean values.

11. Stop the VI.

12. Experiment with properties of the table by using the Table Properties
dialog box. For example, try changing the number of columns to one.

13. Save and close the VI.


Comments

Popular posts from this blog

CHAPTER 3 (Analyzing and Saving a Signal)

In the following exercises, you will build a VI that generates a signal, filters the signal, indicates if the signal exceeds a certain limit, and records the data. Modifying a VI Created from a Template Complete the following steps to create a VI that generates, analyzes, and displays a signal. 1. In the Getting Started window, click New to display the New dialog box. 2. From the Create New list, select VI»From Template»Tutorial (Getting Started)»Generate, Analyze, and Display. This template VI simulates a signal and analyzes it for its root mean square (RMS) value. 3. Click the OK button or double-click the name of the template to create a VI from the template. 4. If the Context Help window is not visible, press the <Ctrl-H> keys to display the window. (Mac OS X) Press the <Command-Shift-H> keys. 5. Display the block diagram by pressing the <Ctrl-E> keys. 6. Move the cursor over the Amplitude and Level Measurements E...

CHAPTER 1

LabVIEW programs are called virtual instruments, or VIs, because their appearance and operation imitate physical instruments, such as oscilloscopes and multimeters. LabVIEW contains a comprehensive set of tools for acquiring, analyzing, displaying, and storing data, as well as tools to help you troubleshoot code you write. In LabVIEW, you build a user interface, or front panel, with controls and indicators. Controls are knobs, push buttons, dials, and other input mechanisms. Indicators are graphs, LEDs, and other output displays. After you build the front panel, you add code using VIs and structures to control the front panel objects. The block diagram contains this code. You can use LabVIEW to communicate with hardware such as data acquisition, vision, and motion control devices, as well as GPIB, PXI, VXI, RS232, and RS485 instruments. BUIDING A VIRTUAL INSTRUMENT In the following exercises, you will build a VI that generates a signal and displays that signal in a graph...