Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI

Customizing a VI

0 ratings | 0.00 out of 5
Print | PDF

Overview

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 tutorial teaches you how to build and customize a VI without using a template.

You can complete the exercises in this tutorial in approximately 45 minutes.

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 table on the front panel. After you complete the exercises, the front panel of the VI will look similar to the front panel in Figure 1.


[+] Enlarge Image

Figure 1. Front Panel of the Reduce Samples VI

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. 

Note: You also can open a blank VI by selecting File»New VI or by selecting File»New and selecting Blank VI from the Create New list. 

2. 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 select Help»Show Context Help from the front panel window or block diagram window to display the Context Help window, shown in Figure 2. 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.

Figure 2. 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 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 configuration information about the Simulate Signal Express VI. 

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. Move the cursor over the Simulate Signal Express VI and click the Detailed help link in the Context Help window 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. 

You also can access the LabVIEW Help by right-clicking a VI or function on the block diagram or on a pinned palette and selecting Help from the shortcut menu or by selecting Help»Search the LabVIEW Help. 

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. 

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 Place on the block diagram button to place the Express VI on the cursor. 

5. Move the cursor to the block diagram. 

6. Place the Sample Compression Express VI on the block diagram to the right of the Simulate Signal Express VI. 

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 a previous exercise you learned to add inputs and outputs by expanding the Express VI using the down arrows. Using the shortcut menu is a different way of displaying and selecting 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 so they appear similar to Figure 3.

Figure 3. Block Diagram of the Reduce Samples VI

7. Display the front panel. 

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

Note: You might need to scroll or resize the front panel to see all 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, 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 and displays any matches in the search results text box. LabVIEW displays a folder glyph to the left of subpalettes in the search results and displays a light blue glyph to the left of Express VIs in the search results. 

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 to place the top left corner of the While Loop. 

7. Drag the cursor diagonally to enclose all the Express VIs and wires, as shown in Figure 4. 

Figure 4. Placing the While Loop around the Express VIs 

8. Click to create the While Loop around the Express VIs and wires.

The While Loop appears with a STOP button wired to the conditional terminal. This While Loop is configured to stop when the user clicks the STOP button. 

9. 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. 

10. 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. On the front panel, 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 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.

Tip: You also can move the Wiring tool over a broken wire to display a tip strip that describes why the wire is broken. This information also appears in the Context Help window when you move the Wiring tool over a broken wire. 

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. 

Tip: You also can press the <Ctrl-L> keys to display the Error list window. 

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 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 table on the front panel. 

1. On the front panel, search for the Express Table indicator on the Controls palette and place it on the front panel to the right of the waveform graph. 

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

3. 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. 

4. 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. 

When you place an object in a While Loop near the border, the loop resizes to add space for that object. 

5. 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. 

The block diagram should appear similar to Figure 5. 


[+] Enlarge Image

Figure 5. Block Diagram of the Reduce Samples VI 

6. Display the front panel and run the VI. 

7. 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. 

8. Stop the VI. 

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

10. Save and close the VI.

Searching for Examples

To learn more about how you can use a certain VI, you can search for and view an example that uses the VI. 

Complete the following steps to find and open an example that uses the Time Delay Express VI. 

1. Select Help»Search the LabVIEW Help to display the LabVIEW Help

2. Click the Search tab, enter "time delay" in the Type in the word(s) to search for text box, and press the <Enter> key. 

Tip: Before you search, you can narrow the search results by placing a checkmark in the Search titles only checkbox near the bottom of the help window. You also can use operators such as AND, OR, and NEAR in the Type in the word(s) to search for text box to narrow the search results. Refer to the Using Help book on the Contents tab in the LabVIEW Help for more information about searching help. 

3. Click the Location column header to sort the search results by content type. Reference topics contain reference information about LabVIEW objects such as VIs, functions, palettes, menus, and tools. How-To topics contain step-by-step instructions for using LabVIEW. Concept topics contain information about LabVIEW programming concepts. 

4. Double-click the Time Delay search result to display the reference topic that describes the Time Delay Express VI. 

5. After you read the description of the Express VI, click the Open example button in the Example section near the bottom of the topic to open an example that uses the Time Delay Express VI. 

6. Click the Browse related examples button to open the NI Example Finder and display a list of examples similar to the example that uses this VI. The NI Example Finder searches among hundreds of examples, including all installed examples and the examples located on the NI Developer Zone at ni.com/zone. You can modify an example to fit an application, or you can copy and paste from one or more examples into a VI that you create. 

You also can right-click a VI or function on the block diagram or on a pinned palette and select Examples from the shortcut menu to display a help topic with links to examples for that VI or function. To launch the NI Example Finder and browse or search examples, select Help»Find Examples or click the Find Examples link in the Examples section of the Getting Started window. 

7. After you experiment with the NI Example Finder and the example VIs, close the NI Example Finder.

Summary

The following topics are a summary of the main concepts you learned in this chapter.

Using the LabVIEW Help Resources

In this chapter, you learned to use the help resources in the following ways: 

• The Context Help window displays basic information about LabVIEW objects when you move the cursor over each object. Objects with context help information include VIs, functions, structures, palettes, dialog box components, and so on. To access the Context Help window, select Help»Show Context Help or press the <Ctrl-H> keys. (Mac OS) Press the <Command-Shift-H> keys. 

• When you move the cursor over an Express VI on the block diagram, the Context Help window displays a brief description of the Express VI and information about how you configured the Express VI. 

• The LabVIEW Help contains detailed information about LabVIEW objects. To access the LabVIEW Help topic for an object, move the cursor over the object and click the Detailed help link in the Context Help window. You also can right-click an object on the block diagram or on a pinned palette and select Help from the shortcut menu. 

• To navigate the LabVIEW Help, use the Contents, Index, and Search tabs. Use the Contents tab to get an overview of the topics and structure of the help. Use the Index tab to find a topic by keyword. Use the Search tab to search the help for a word or phrase. 

• If you find an object in the LabVIEW Help you want to use, you can click a Place on the block diagram button to place the object on the block diagram.

• On the Search tab of the LabVIEW Help, use operators such as AND, OR, and NEAR to narrow the search results. To search for an exact phrase, place quotation marks around the phrase. Before you search, you also can narrow the search results by placing a checkmark in the Search titles only checkbox near the bottom of the help window. 

• On the Search tab of the LabVIEW Help, you can click the Location column header above the list of search results to sort the results by content type. Reference topics contain reference information about LabVIEW objects such as VIs, functions, palettes, menus, and tools. How-To topics contain step-by-step instructions for using LabVIEW. Concept topics contain information about LabVIEW programming concepts.

Customizing the Block Diagram Code

You can use many controls, indicators, Express VIs, and structures to build a VI. To customize a VI, you can create controls and indicators, set when a VI stops running, and display generated data in a table.

Creating Controls and Indicators

Create controls and indicators on the block diagram by right-clicking the Express VI input, output, or wire, selecting Create from the shortcut menu, and selecting among the available options. LabVIEW wires the control or indicator you created to the input, output, or wire you right-clicked. 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.

Controlling When a VI Stops Running

Use a While Loop to run the code enclosed within the loop continually. A While Loop stops running when a stop condition occurs. When you place or move an object in a While Loop near the border, the loop resizes to add space for that object. The Execution Control palette includes objects you can use to control the number of times a VI runs, as well as the speed at which the VI runs.

Errors and Broken Wires

The Run button appears broken when the VI you are creating or editing contains errors. If the Run button is still broken when you finish wiring the block diagram, the VI is broken and cannot run. 

Click the broken Run button or select View»Error List to find out why a VI is broken. You can use the Error list window to locate errors. Click the Help button for more information about the error. Double-click the error in the errors and warnings field to highlight the problem causing the error. 

A broken wire appears as a dashed black line with a red X in the middle. Broken wires occur for a variety of reasons, such as if you delete wired objects. The VI cannot run if the block diagram contains broken wires. 

Move the Wiring tool over a broken wire to display a tip strip that describes why the wire is broken. This information also appears in the Context Help window when you move the Wiring tool over a broken wire. Right-click the wire and select List Errors from the shortcut menu to display the Error list window. Click the Help button for more information about why the wire is broken.

Displaying Data in a Table

The table indicator displays generated data. Use the Build Table Express VI to build a table of generated data.

Using the NI Example Finder

Use the NI Example Finder to browse or search examples installed on your computer or on the NI Developer Zone at ni.com/zone. These examples demonstrate how to use LabVIEW to perform a wide variety of test, measurement, control, and design tasks. Select Help»Find Examples or click the Find Examples link in the Examples section of the Getting Started window to launch the NI Example Finder. 

Examples can show you how to use specific VIs or functions. You can right-click a VI or function on the block diagram or on a pinned palette and select Examples from the shortcut menu to display a help topic with links to examples for that VI or function. You can modify an example VI to fit an application, or you can copy and paste from one or more examples into a VI that you create.

Shortcuts

This chapter introduced the following keyboard shortcuts. 

Note: The <Ctrl> key in these shortcuts corresponds to the (Mac OS) or <Command> key or (Linux) <Alt> key.

Downloads

customizing_vi.pdf

0 ratings | 0.00 out of 5
Print | PDF

Reader Comments | Submit a comment »

 

Legal
This tutorial (this "tutorial") was developed by National Instruments ("NI"). Although technical support of this tutorial may be made available by National Instruments, the content in this tutorial may not be completely tested and verified, and NI does not guarantee its quality in any way or that NI will continue to support this content with each new revision of related products and drivers. THIS TUTORIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND AND SUBJECT TO CERTAIN RESTRICTIONS AS MORE SPECIFICALLY SET FORTH IN NI.COM'S TERMS OF USE (http://ni.com/legal/termsofuse/unitedstates/us/).