Lesson 7
Modularity
Recognize the benefits of reusing code and create a subVI
with a properly configured connector pane, meaningful icon,
documentation, and error handling.
A. Understanding Modularity
B. Icon
C. Connector Pane
D. Documentation
E. Using SubVIs
1
LESSON 7 Modularity
A. Understanding
Modularity
Recognize the benefit of using modular code and identify
sections of code that could be reused.
• Modularity
• SubVIs
2
A. Understanding Modularity
Modularity and SubVIs
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.
SubVI—A VI used within another VI.
3
B. Understanding Modularity
SubVIs—Reusing Code
4
B. Understanding Modularity
SubVIs
Function Code Calling Program Code
function average (in1, in2, out) main
{ {
out = (in1 + in2)/2.0; average (point1, point2, pointavg)
} }
SubVI Block Diagram Calling VI Block Diagram
5
LESSON 7 Modularity
B. Icon
Recognize characteristics of a good icon and use the
LabVIEW Icon Editor to create a custom icon.
• Characteristics of a Good Icon
• Using the Icon Editor
6
B. Icon
Purpose of Icon
• Graphical representation of a VI
• Identifies the subVI on the block diagram of the VI
7
B. Icon
Characteristics of a Good Icon
Good icons convey the functionality of the VI.
8
B. Icons
Creating Icons—Icon Editor
9
LESSON 7 Modularity
Demonstration
Creating an Icon
Use the LabVIEW Icon Editor to create a custom icon.
10
LESSON 7 Modularity
C. Connector Pane
Select and configure a connector pane for a subVI.
• Patterns
• Standards
11
C. Connector Pane
Patterns
• Displayed next to icon
• Select from different
patterns
12
C. Connector Pane
Assigning Terminals
Current Temperature Warning?
Max Temperature Warning Text
Min.Temperature
Error In Error Out
13
C. Connector Pane
Standards
14
LESSON 7 Modularity
D. Documentation
Explain how to document code in LabVIEW using
descriptions and tip strips, and describe four methods for
documenting code on the block diagram.
• VI Descriptions and Tip Strips
• Labels
15
D. Documentation
Creating Descriptions and Tip Strips
16
D. Documentation
Documenting Block Diagram Code
Free
label
Owned label
17
LESSON 7 Modularity
E. Using SubVIs
Demonstrate how to place subVIs on the block diagram,
explain terminal settings and error handling, and create
subVIs from a section of existing code.
• Placing SubVIs on the Block Diagram
• Terminal Settings
• Handling Errors
• Creating from a Section of Block Diagram
18
E. Using SubVIs
Placing SubVIs on the Block Diagram
19
E. Using SubVIs
Terminal Settings
• Bold
– Required terminal
• Plain
– Recommended terminal
• Dimmed
– Optional terminal
20
E. Using SubVIs
Handling Errors
Use a Case Structure to handle errors passed into the
subVI.
21
E. Using SubVIs
Handling Errors
Avoid using LabVIEW error handler VIs inside subVIs.
22
E. Using SubVIs
Convert a Section of a VI to SubVI
1. Select the section of the block diagram to reuse.
2. Select Edit»Create SubVI.
23
LESSON 7 Modularity
Exercise 7-1
Temperature Warnings VI – As SubVI
Create the icon and connector pane for a VI so you can use the VI as a
subVI. Call the subVI from a test VI.
24
LESSON 7 Modularity
Exercise 7-1
Temperature Warnings VI – As SubVI
• Do the terminal names in the calling VI need to match the subVI terminal
names?
• Do the data types in the calling VI need to match the subVI terminal data
types?
25
LESSON 7 Modularity
Activity 7-1
Lesson Review
Refer to the participant guide to answer questions about what you have learned
in this lesson and then discuss the answers as a group.
26
Lesson Review
1. On a subVI, which terminal setting causes
a broken VI if the terminal is not wired?
a) Required
b) Recommended
c) Optional
27
Lesson Review
1. On a subVI, which terminal setting causes
a broken VI if the terminal is not wired?
a) Required
b) Recommended
c) Optional
28
Lesson Review
2. You must create a custom icon to use a
VI as a subVI.
a) True
b) False
29
Lesson Review
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.
30