Você está na página 1de 26

Lesson 7

Developing Modular Applications

TOPICS
A. Understanding Modularity
B. Icon and Connector Pane
C. Using SubVIs

ni.com/training
A. Understanding Modularity

Modularity - The degree to which a program is


composed of discrete modules such that a change to
one module has minimal impact on other modules

Modules in LabVIEW are called subVIs

ni.com/training
2
A. Understanding Modularity – SubVIs

SubVI- A VI within another VI

•SubVIs correspond to subroutines in text-based


programming languages
•The upper right corner of the front panel and block diagram
displays the icon for the VI
•This icon identifies the VI when you place the VI on the
block diagram

ni.com/training
3
A. Understanding Modularity – SubVIs

ni.com/training
4
A. Understanding Modularity – SubVIs

ni.com/training
5
A. Understanding Modularity – SubVIs
Function Code Calling Program Code
function average (in1, in2, main
out) {
{ average (point1, point2,
out = (in1 + in2)/2.0; pointavg)
} }

SubVI Block Diagram Calling VI Block Diagram

ni.com/training
6
B. Icon and Connector Pane

• After you build a VI, build the icon and the connector pane
so you can use the VI as a subVI
• The icon and connector pane correspond to the function
prototype in text-based programming languages
• Every VI displays an icon in the upper-right corner of the
front panel and block diagram windows
• An icon is a graphical representation of a VI
• If you use a VI as a subVI, the icon identifies the subVI on
the block diagram of the VI

ni.com/training
7
B. Icon and Connector Pane – Good VI Icon

• Characteristics of a good VI icon


− Conveys the functionality of the VI using:
• Relevant graphics
• Descriptive text

ni.com/training
8
B. Icon and Connector Pane – Create Icon

• Create custom icons by right-clicking the icon in the upper


right corner of the front panel or block diagram and selecting
Edit Icon or by double-clicking the icon
• You also can drag a graphic from anywhere in your file
system and drop it on the icon

ni.com/training
9
B. Icon and Connector Pane – Create Icon

• Use the editing tools to modify an icon manually

ni.com/training
10
B. Icon and Connector Pane – Create Icon

• Use the Glyphs tab to display glyphs you can include in the icon
• Select Tools»Synchronize with ni.com Icon Library to update

ni.com/training
11
B. Icon and Connector Pane – Create Icon

• Use the Icon Text tab to specify the text to display in the icon

ni.com/training
12
B. Icon and Connector Pane – Create Icon

• Use the Templates tab to display icon templates you can use as
a background for the icon

ni.com/training
13
B. Icon and Connector Pane – Setting up the
Connector Pane
• Right-click the icon in the upper
right corner of the front panel
and select Show Connector
− Each rectangle on the connector
pane represents a terminal
− Use the terminals to assign inputs
and outputs
• Select a different pattern by
right-clicking the connector pane
and selecting Patterns from the
shortcut menu

ni.com/training
14
B. Icon and Connector Pane – Standards

• Use this connector pane layout as a standard

• Top terminals are usually reserved for references, such as a


file reference
• Bottom terminals are
usually reserved for
error clusters

ni.com/training
15
C. Using SubVIs

• To place a subVI on the block diagram


− Click Select a VI on the Functions palette
− Navigate to the VI you want to use as a subVI
− Double-click to place it on the block diagram
• To place an open VI on the block diagram of another open
VI
− Click the icon of the VI you want to use as a subVI
− Drag the icon to the block diagram of the other VI

ni.com/training
16
C. Using SubVIs – Terminal Setting
• Bold: Required terminal
• Plain: Recommended
terminals
• Dimmed: Optional terminals

ni.com/training
17
C. Using SubVIs – Handling Errors

• Use a Case structure to handle errors passed into the subVI

ni.com/training
18
C. Using SubVIs – Handling Errors

• Avoid using LabVIEW error handler VIs inside subVIs

ni.com/training
19
C. Using SubVIs – Section to SubVI

To convert a section of a VI into a subVI:


• Use the Positioning tool to select the section of the block
diagram you want to reuse
• Select Edit»Create SubVI

ni.com/training
20
Exercise 7-1
Determine Warnings VI

Create the icon and connector pane for a VI so you can use
the VI as a subVI.
GOAL
21
Exercise 7-1
Determine Warnings VI

• What would you do if this subVI needed 20 inputs and


outputs?

DISCUSSION
Summary—Quiz

1. On a subVI, which terminal setting causes an error if the


terminal is not wired?
a) Required
b) Recommended
c) Optional

ni.com/training
23
Summary—Quiz Answer

1. On a subVI, which terminal setting causes an error if the


terminal is not wired?
a) Required
b) Recommended
c) Optional

ni.com/training
24
Summary—Quiz

2. You must create a custom icon to use a VI as a subVI.


a) True
b) False

ni.com/training
25
Summary—Quiz Answer

2. You must create a custom icon to use a VI as a subVI.


a) True
b) False

You do not need to create a custom icon to use a


VI as a subVI, but it is highly recommended to
increase the readability of your code.

ni.com/training
26

Você também pode gostar