210 likes | 344 Views
EET 2259 Unit 4 SubVIs. Read Bishop, Chapter 4. Lab #4 and Homework #4 due next week. 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.
E N D
EET 2259 Unit 4SubVIs • Read Bishop,Chapter 4. • Lab #4 and Homework #4 due next week.
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)
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 subVIscan contain subVIs. • And so on…
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 (1806-1871)
Example: E-Mail Notification.vi • In LabVIEW’s Example Finder, browse according to Task. Open Networking folder, then open Internet & Web folder. Then open E-Mail Notification.vi. • In its block diagram, double-click on SMTP Email Send Message.vi. • In its block diagram, double-click on SMTP Email Send Message Charset.vi. • And so on…
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)
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.
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.
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)
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)
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
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)
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)
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)
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)
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)
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)
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.
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)
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.