Professional Documents
Culture Documents
Developing Modular Applications
Developing Modular Applications
1
ni.com/training
Course Learning Map
Lesson 1 Lesson 4 Lesson 7
Developing Modular Using Sequential and State
Navigating LabVIEW
Applications Machine Algorithms
Lesson 3 Lesson 6
Managing File and Hardware
Implementing a VI
Resources
2 ni.com/training
Lesson 4
Developing Modular Applications
TOPICS
A. Understanding Modularity
B. Icon
C. Connector Pane
D. Using SubVIs
3
ni.com/training
A. Understanding Modularity
4
ni.com/training
Understanding Modularity
5
ni.com/training
Understanding Modularity – SubVIs
6
ni.com/training
Understanding Modularity – SubVIs
7
ni.com/training
Understanding Modularity – SubVIs
8
ni.com/training
Understanding Modularity – SubVIs
Function Code Calling Program Code
function average (in1, in2, main
out) {
{ average (point1, point2,
out = (in1 + in2)/2.0; pointavg)
} }
9
ni.com/training
B. Icon
Characteristics of a Good Icon
Using the Icon Editor
10
ni.com/training
Icon
11
ni.com/training
Characteristics of a Good Icon
Good icons convey the functionality of the VI using:
− Relevant graphics
− Descriptive text, if necessary
12
ni.com/training
Creating Icons - Icon Editor
Open the Icon Editor using one of these methods:
− Right-click the icon in the upper-right corner of the front panel
or block diagram and select Edit Icon.
− Double-click the icon.
13
ni.com/training
Icon Editor
Use the editing tools to modify an icon manually.
14
ni.com/training
Icon Editor
Use the Glyphs tab to display glyphs you can include in the icon.
15
ni.com/training
Icon Editor
Use the Icon Text tab to specify the text to display in the icon.
16
ni.com/training
Icon Editor
Use the Templates tab to display icon templates you can use as a
background for the icon.
17
ni.com/training
C. Connector Pane
Patterns
Standards
18
ni.com/training
Connector Pane
19
ni.com/training
Connector Pane – Standards
20
ni.com/training
D. Using SubVIs
Using on Block Diagram
Terminal Settings
Handling Errors
Creating from a Section of Block Diagram
21
ni.com/training
Using SubVIs
22
ni.com/training
Terminal Settings
• Bold
− Required terminal
• Plain
− Recommended
terminal
• Dimmed
− Optional terminal
23
ni.com/training
Handling Errors
Use a Case structure to handle errors passed into the subVI.
24
ni.com/training
Handling Errors
Avoid using LabVIEW error handler VIs inside subVIs.
25
ni.com/training
Convert a Section of a VI to SubVI
To convert a section of a VI into a subVI:
1. Use the Positioning tool to select the section of the block
diagram you want to reuse.
2. Select Edit»Create SubVI.
26
ni.com/training
Exercise 4-1
Temperature Warnings VI
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.
GOAL
Exercise 4-1
Temperature Warnings VI
DISCUSSION
Summary—Quiz
29
ni.com/training
Summary—Quiz Answer
30
ni.com/training
Summary—Quiz
31
ni.com/training
Summary—Quiz Answer
32
ni.com/training
Lesson 5
Creating and Leveraging Data Structures
TOPICS
A. Arrays
B. Common Array Functions
C. Polymorphism
D. Auto-Indexing
E. Clusters
F. Type Definitions
33
ni.com/training
A. Arrays
1D and 2D Arrays
Creating an Array Control and Constant
Initializing Arrays
34
ni.com/training
Arrays
An array:
• Is a collection of data elements
that are of same type.
• Has one or more dimensions.
• Contains up to (231)–1 elements
per dimension, memory
permitting.
• Accesses elements by its index.
Note: The first element is index 0.
35
ni.com/training
Arrays – 1D and 2D Examples
ID array
One row of 10-elements
0 1 2 3 4 5 6 7 8 9
1.2 3.2 8.2 8.0 4.8 5.1 6.0 1.0 2.5 1.7
Index
2D array
Five-row by seven-column table of 35 numbers
elements
0 1 2 3 4 5 6
0
1
2
3
4
36
ni.com/training
Why Use Arrays?
Use arrays when you work with a collection of similar data and
when you perform repetitive computations.
37
ni.com/training
Viewing Arrays on the Front Panel
The elements at First element
Second
index 0 are not at index 1 element at
shown because index 2
element 1 is selected
in the index display.
38
ni.com/training
Creating an Array Control
For a new array:
1. Select an Array control from the
Controls palette on the front panel.
2. Place a data object, such as a
numeric control, into the array
shell.
3. Add a second dimension, if necessary, by
resizing the index.
From a block diagram terminal or wire:
1. Right-click the object and select Create»Control
or Create»Indicator.
39
ni.com/training
Creating an Array Constant
For a new array:
1. Select Array Constant from the Functions
palette on the block diagram.
2. Place a constant, such as a numeric,
into the array shell.
3. Add a second dimension, if necessary, by
resizing the index.
From a block diagram terminal or wire:
1. Right-click and select Create»Constant.
40
ni.com/training
Initializing Arrays
• You can initialize an array or leave it uninitialized.
• For initialized arrays, you define the number of elements in
each dimension and the contents of each element.
• Uninitialized arrays have dimension but no elements.
41
ni.com/training
2D Arrays
• 2D arrays:
− Store elements in a grid.
− Require a column index and a row index to locate an element,
both of which are zero-based.
• Create a multidimensional array on the front panel by right-
clicking the index display and selecting Add Dimension
from the shortcut menu.
• Resize the index display until you have as many dimensions
as you want.
42
ni.com/training
B. Common Array Functions
Array Size
Initialize Array
Array Subset
Build Array
Index Array
43
ni.com/training
Common Array Functions
• Array Size
• Initialize Array
• Array Subset
• Build Array
• Index Array
44
ni.com/training
Array Size
45
ni.com/training
Initialize Array
46
ni.com/training
Array Subset
47
ni.com/training
Build Array
48
ni.com/training
Index Array
49
ni.com/training
C. Polymorphism
50
ni.com/training
Polymorphism
Polymorphism - The ability of VIs and functions to
automatically adapt to accept input data of different
data types
51
ni.com/training
Arithmetic Functions Are Polymorphic
Combination Result
52
ni.com/training
D. Auto-Indexing
Use in For Loops and While Loops
Waveform Graphs
Auto-Indexing with a Conditional Terminal
Creating 2D Arrays
Auto-Indexing Input to a Loop
53
ni.com/training
Auto-Indexing Auto-Indexing Enabled
54
ni.com/training
Waveform Graph
• Is a graphical display of data.
• Displays one or more plots of
evenly sampled measurements.
• Is used to plot pre-generated
arrays of data.
• Can display plots with any
number of data points.
55
ni.com/training
Charts vs. Graphs – Single-Plot
56
ni.com/training
Auto-Indexing with a Conditional Tunnel
57
ni.com/training
Creating 2D Arrays
1D Array 2D Array
0 1 2 3 4 5
58
ni.com/training
Auto-Indexing Input
If the iteration count terminal is wired and arrays of different
sizes are wired to auto-indexed tunnels, the actual number of
iterations becomes the smallest of the choices.
59
ni.com/training
59
Auto-Indexing Input
Use an auto-indexing input array to perform calculations
on each element in an array.
• Wire an array to an auto-indexing tunnel on a For Loop.
• You do not need to wire the count (N) terminal.
− The For Loop executes
the number of times
equal to the
number of
elements in the array.
− The Run button is not broken.
60
ni.com/training
60
Exercise 5-1
Concept: Manipulating Arrays
HOMEWORK
• In the All Data Channel case, how can you verify that the
two approaches yield the same results?
– Polymorphic Add of array + scalar
– Auto-indexed array elements added to scalar
DISCUSSION
End of Week 4
63 DISCUSSION