Presentation is loading. Please wait.

Presentation is loading. Please wait.

EET 2259 Unit 4 SubVIs Read Bishop, Chapter 4.

Similar presentations


Presentation on theme: "EET 2259 Unit 4 SubVIs Read Bishop, Chapter 4."— Presentation transcript:

1 EET 2259 Unit 4 SubVIs Read Bishop, Chapter 4.
Lab #4 and Homework #4 due next week. -This week and many of the remaining weeks will each be devoted to one big idea in programming. This week’s big idea is subroutines, or what are called subVIs in LabVIEW.

2 Modular Programming When writing a complex program, good programmers divide their programs into separate parts that can be written and tested independently, and that can be re-used in other programs. In text-based programming languages, these parts are called subroutines. In LabVIEW they’re called subVIs. (Bishop, p. 173) Our programs generally won’t get this big or complicated, but it’s important to know how subVI’s work.

3 Hierarchy of VIs Your main VI can contain one or more subVIs.
Each of those subVIs can contain one or more subVIs. Each of those subVIs can contain subVIs. And so on…

4 A Little Poem “Great fleas have little fleas upon their backs to bite 'em, And little fleas have lesser fleas, and so ad infinitum. And the great fleas themselves, in turn, have greater fleas to go on, While these again have greater still, and greater still, and so on.” Augustus DeMorgan ( )

5 Example: E-Mail Notification.vi
In LabVIEW’s Example Finder, browse according to Task. Open Networking folder, then open Internet & Web folder. Then open Notification.vi. In its block diagram, double-click on SMTP Send Message.vi. In its block diagram, double-click on SMTP Send Message Charset.vi. And so on… -Note green background of subVIs. By default, subVIs have a white background, but we’ll see soon how this can be customized. -Also note how rolling over a subVI causes description to appear in Context Help Window.

6 Hierarchy Window LabVIEW’s VI Hierarchy Window shows how all of these VIs are related to each other. Open the window by using View > VI Hierarchy in pull-down menus. (Bishop, p. 196) Demo with Notification.vi

7 Example: E-Mail Notification.vi
-You can right-click a subVI and select Show All SubVIs or Show All Callers. -Benefits of doing it this way: Each subVI is a self-contained unit that can be tested on its own and may be re-used in future projects. -For comparison, also look at hierarchy in Bouncing Cube.vi and Tank Simulation.vi.

8 A Simpler Example Suppose you’re writing a program that lets the user enter values for x, y, and z, and then calculates x3 + y3 + z3. Rather than placing all of the multiply functions to compute x3, y3, and z3 individually, consider building a subVI that will cube any number. Demo doing it the brute-force way, and have them follow along. It’s not too bad, but show that if you now find out that it was supposed to be x^5 + y^5 + z^5, it’s a lot of work to change it.

9 Steps in Creating a SubVI
Create the VI. Create the icon. Create the connector with the correct number of input and output terminals. Assign the connector’s terminals to the VI’s controls and indicators. Add a description. Save the VI. Step 1. Continuing example, create a new blank VI. Place a numeric control called “Input” and a numeric indicator called “Input Cubed,” and wire the multiply functions on the block diagram to cube the input.

10 Icon A subVI is represented by an icon on the block diagram of a VI that uses the subVI. When a VI’s front panel or block diagram is open, the VI’s icon appears in the upper right corner. The default icon is the LabVIEW logo along with a number. (Bishop, p. 177)

11 Icon Editor If you plan to use a VI as a subVI, you should replace the default icon with a more informative icon. Use the icon editor to do this. Right-click on the icon in the front panel and select Edit Icon…. (Bishop, p. 177) -Continuing example, edit icon. Double-clicking the selection tool selects the entire icon, double-clicking the rectangle tool draws a rectangle bordering the entire icon, double-clicking the text tool lets you modify text properties. -Icons are 32x32 pixels.

12 Connector To use a VI as a subVI, you must assign it a connector so that you’ll be able to attach wires to it on the block diagram of a VI that uses it as a subVI. The connector contains one terminal for each of the subVI’s inputs and outputs. (Bishop, p. 180) Input terminals Output terminal Connector

13 Creating the Connector
To create the connector, right-click the icon in the front panel and select Show Connector. You can choose a different connector pattern by right-clicking the connector and selecting Patterns. (Bishop, p. 181)

14 Assigning Terminals to Controls and Indicators
Next, assign terminals on the connector to your front-panel controls and indicators. To do this, click on a terminal with the Wiring tool and then click on the control or indicator that you want to assign to that terminal. Always assign terminals on the left to inputs (controls), and terminals on the right to outputs (indicators). (Bishop, p. 183) -Note that the wiring tool appears when you move over a terminal on the connector. But no wires will be drawn. -Continuing example, edit connector.

15 Required, Recommended, Optional Terminals
You can identify each terminal as being required, recommended, or optional. If required terminals are left unwired, then the VI will not run as a subVI. But it will run when recommended or optional terminals are left unwired. By default, all terminals are recommended. To change a terminal’s status, right-click the terminal and select This Connection Is. (Bishop, p. 185) Continuing example, change input to required, but leave output as recommended.

16 Context Help Window Information about a subVI appears automatically in the Context Help window when you roll the mouse over the subVI’s icon on a block diagram. This information includes the subVI’s name and icon the name of each terminal (in bold text if it’s required, in plain text if it’s recommended, in gray text if it’s optional) The subVI’s description, if you added one (Bishop, p. 184)

17 Adding a Description You should document your VI by adding a description of what it does. To do this, choose File > VI Properties… in the pull-down menus, then select Documentation from the drop-down box, and then type your description. (Bishop, p. 187) -Demo

18 Adding More Detailed Info
In addition to a description for the entire VI, you can also add a description for each control and indicator on the VI’s front panel. To do this, right-click on the control or indicator and choose Description and Tip…. Then type a description and a brief tip. Now when you roll over the object, its description will appear in the Context Help window and its tip will appear next to the object. (Bishop, p. 188)

19 Summary: Creating a SubVI
Create the VI. Create the icon. Create the connector with the correct number of input and output terminals. Assign the connector’s terminals to the VI’s controls and indicators. Add a description. Save the VI. Continuing example, save it as “cube.vi”

20 Using a VI as a SubVI After you’ve created and saved a VI, how do you call it as a subVI inside another program? Choose All Functions on the Functions palette, then choose Select a VI… and then locate your VI. (Bishop, p. 188) -Continuing example, use it in VI that computes x^3 + y^3 + z^3. -Then show how easy it is to change to fifth power. -Also look at VI hierarchy for this simple example.

21 SubVI Is a Separate File
CAUTION: When you save a program that calls a subVI, the subVI is not saved as part of that “caller” VI. The two files are totally distinct. So if you send someone the caller VI, you must also send the separate subVI file, or the person won’t be able to run your program. -Demo by saving caller VI, then deleting cube.vi.


Download ppt "EET 2259 Unit 4 SubVIs Read Bishop, Chapter 4."

Similar presentations


Ads by Google