Presentation is loading. Please wait.

Presentation is loading. Please wait.

Course Learning Map Lesson # Lesson Title Lesson 3 Lesson 2 Lesson 1

Similar presentations


Presentation on theme: "Course Learning Map Lesson # Lesson Title Lesson 3 Lesson 2 Lesson 1"— Presentation transcript:

1 Course Learning Map Lesson # Lesson Title Lesson 3 Lesson 2 Lesson 1
Implementing a VI Lesson 2 Troubleshooting & Debugging VIs Lesson 1 Navigating LabVIEW Lesson 6 Managing File and Hardware Resources Lesson 5 Creating and Leveraging Data Structures Lesson 4 Developing Modular Applications Lesson 8 Solving Dataflow Challenges with Variables Lesson 7 Using Sequential and State Machine Algorithms

2 Lesson 4 Developing Modular Applications
Understanding Modularity Icon Connector Pane Using SubVIs

3 A. Understanding Modularity

4 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 LabVIEW uses subVIs to create modularity.

5 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 a block diagram.

6 Understanding Modularity – SubVIs
Repeated code can become subVIs.

7 Understanding Modularity – SubVIs

8 Understanding Modularity – SubVIs
Function Code Calling Program Code function average (in1, in2, out) { out = (in1 + in2)/2.0; } main average (point1, point2, pointavg) SubVI Block Diagram Calling VI Block Diagram Every VI displays an icon in the upper-right corner of the front panel and block diagram windows. The icon is a graphical representation of a VI and identifies the subVI on the block diagram of the calling VI. The icon and connector pane correspond to the function prototype in text-based programming languages.

9 B. Icon Characteristics of a Good Icon Using the Icon Editor

10 Icon 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.

11 Characteristics of a Good Icon
Good icons convey the functionality of the VI using: Relevant graphics Descriptive text, if necessary

12 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. After you build a VI, customize the icon so you can identify the VI when you use it as a subVI on a block diagram. Create icons using the Icon Editor dialog box. Alternatively, you can drag a graphic file, such as a .bmp or .jpg, from your file system to the icon in the upper-right corner of the VI.

13 Icon Editor Use the editing tools to modify an icon manually.

14 Icon Editor Use the Glyphs tab to display glyphs you can include in the icon.

15 Icon Editor Use the Icon Text tab to specify the text to display in the icon.

16 Icon Editor Use the Templates tab to display icon templates you can use as a background for the icon.

17 C. Connector Pane Patterns Standards

18 Connector Pane The connector pane is displayed next to the icon in the upper right corner of the front panel. 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.

19 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.

20 D. Using SubVIs Using on Block Diagram Terminal Settings
Handling Errors Creating from a Section of Block Diagram

21 Using SubVIs Options to place a subVI on the block diagram:
Drag the VI from the Project Explorer to the block diagram. Click Select a VI on the Functions palette and then navigate to the VI. Drag the icon from an open VI to the block diagram of another VI.

22 Terminal Settings Bold Plain Dimmed Required terminal
Recommended terminal Dimmed Optional terminal You can designate which inputs and outputs are required, recommended, and optional to prevent users from forgetting to wire subVI terminals. Required means that the block diagram on which you place the subVI will be broken if you do not wire those inputs. View the Context Help for the subVI to help identify the terminal settings. To change a terminal requirement, do the following: Right-click a terminal in the connector pane and select This Connection Is. Select Required, Recommended, or Optional. LabVIEW sets inputs and outputs of VIs you create to Recommended by default. Set a terminal setting to required only if the VI must have the input or output to run properly.

23 Handling Errors Use a Case structure to handle errors passed into the subVI.

24 Handling Errors Avoid using LabVIEW error handler VIs inside subVIs.

25 Convert a Section of a VI 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.

26 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.

27 Exercise 4-1 Temperature Warnings VI
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? Do the terminal names in the calling VI need to match the subVI terminal names? No. The names of wires and terminals used to pass data to subVIs do not need to match the subVI names. Do the data types in the calling VI need to match the subVI terminal data types? Yes. For example, a string cannot be wired directly to a numeric and vice versa. However, LabVIEW can coerce the numeric data type to the subVI data type (such as coercing an integer to a double), In addition, you can program the subVI to support polymorphic inputs.

28 Summary—Quiz On a subVI, which terminal setting causes a broken VI if the terminal is not wired? Required Recommended Optional Answer is a.

29 Summary—Quiz Answer On a subVI, which terminal setting causes a broken VI if the terminal is not wired? Required Recommended Optional

30 Summary—Quiz You must create a custom icon to use a VI as a subVI.
True False Answer is 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.

31 Summary—Quiz Answer You must create a custom icon to use a VI as a subVI. True 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. Answer is 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.

32 Lesson 5 Creating and Leveraging Data Structures
Arrays Common Array Functions Polymorphism Auto-Indexing Clusters Type Definitions

33 A. Arrays 1D and 2D Arrays Creating an Array Control and Constant
Initializing Arrays

34 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. Arrays are lists of elements of the same data type. They are analogous to arrays in traditional languages. Arrays can have one or more dimensions. Arrays can have up to 2^31 elements per dimension. Actual array sizes that students can create is limited by memory. Elements are accessed by an index. The index ranges from 0 to N-1 (N = number of elements in the array). Arrays are zero-indexed (first element is zero) in each dimension. A 2D array is analogous to a spreadsheet or table. Example: If your data contains temperature readings and time stamps, one column is time values and the other column is readings. Be careful to specify the element you really want. Example: The first element in an array is array (0), not array(1).

35 Arrays – 1D and 2D Examples
ID array One row of 10-elements 1.2 3.2 8.2 8.0 4.8 5.1 6.0 1.0 2.5 1.7 Index numbers 2D array Five-row by seven-column table of 35 elements 1 2 3 4

36 Why Use Arrays? Use arrays when you work with a collection of similar data and when you perform repetitive computations.

37 Viewing Arrays on the Front Panel
The elements at index 0 are not shown because element 1 is selected in the index display. First element at index 1 Second element at index 2 The element selected in the index display always refers to the element shown in the upper-left corner of the element display. 36

38 Creating an Array Control
For a new array: Select an Array control from the Controls palette on the front panel. Place a data object, such as a numeric control, into the array shell. Add a second dimension, if necessary, by resizing the index. From a block diagram terminal or wire: Right-click the object and select Create»Control or Create»Indicator. Creating array controls in LabVIEW: You can place any data type in an array shell except an array. You cannot have an array of arrays; use a 2D array instead. Emphasize that this is a two-step process. Students often place only empty array shells on the front panel. Remind them they must place a data type inside the array shell. Demonstrate the following on your computer: Create a numeric array. Point out index and data object components. Show how to create a 2D array. Show how to display multiple array elements. Show that index elements always reference the upper-leftmost object in the array display. Show how elements in an array are initially grayed out, indicating that a portion of the array has not been defined.

39 Creating an Array Constant
For a new array: Select Array Constant from the Functions palette on the block diagram. Place a constant, such as a numeric, into the array shell. Add a second dimension, if necessary, by resizing the index. From a block diagram terminal or wire: Right-click and select Create»Constant. Creating array constants uses a two-step process. Select Array Constant from the Functions palette. Place a constant data type inside the empty array shell. Note again that the data types are grayed-out and must be manually defined if the user wants to store values in the array constant.

40 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 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 B. Common Array Functions
Array Size Initialize Array Array Subset Build Array Index Array

43 Common Array Functions
Array Size Initialize Array Array Subset Build Array Index Array LabVIEW has many functions to manipulate arrays. These functions are located on the Array subpalette of the Functions palette. Instructor: Choose one of the following approaches to help students understand how to use these common array functions. Walk through the following slides. Open the associated demo VIs in the <Exercises>\Demonstrations\Arrays and Polymorphism\ folder. Create demos on the fly. Show related shipping examples. For example, Build Array.vi has more combinations than shown in the following slides.

44 Array Size The Array Size function returns the number of elements in the array. 1D array: Output is a numeric. Multidimensional array: Array output has elements signifying size of each dimension. For example: A 2 x 4 array will output an array of two elements. The first element = 2 and second element = 4.

45 Initialize Array The Initialize Array function creates an n-dimensional array in which every element is initialized to the value of element. Initialize array is a resizable node. Use the Positioning tool to resize the function and increase the number of dimensions (element, row, column, page, and so on) of the output array. You must have one dimension size input terminal for each dimension in the array.

46 Array Subset The Array Subset function returns a portion of an array starting at index and containing length number of elements.

47 Build Array The Build Array function concatenates elements together into one array or concatenates multiple arrays together into arrays of higher dimension. Wiring a scalar element into the Build Array function automatically configures the Build Array function to concatenate elements. When wiring in two or more arrays, right click on the output of the Build Array function to enable or disable concatenated inputs. The Build Array function is a resizable node and can be resized to add additional input terminals.

48 Index Array The Index Array function : Returns the element or subarray of n-dimension array at index. When you wire an array to this function, the function resizes automatically to display index inputs for each dimension in the array you wire to n-dimension array. The slide shows examples of the function accessing a single element of a one-dimensional array, a row of a two-dimensional array, and a column of a two-dimensional array. Index Array does not remove the element from the array. Remind students that arrays start their indices at zero. Index 2 in the example actually accesses the third element in the array.

49 C. Polymorphism

50 Polymorphism Polymorphism - The ability of VIs and functions to automatically adapt to accept input data of different data types Functions are polymorphic to varying degrees: None, some, or all of their inputs can be polymorphic. Some accept numeric or Boolean values. Some accept numeric or strings. Some accept scalars, numeric arrays, or clusters of numerics. Functions are polymorphic to varying degrees—none, some, or all of their inputs can be polymorphic. Some function inputs accept numeric values or Boolean values. Some accept numeric values or strings. Some accept not only scalar numeric values but also arrays of numeric values, clusters of numeric values, arrays of clusters of numeric values, and so on. Some accept only one-dimensional arrays although the array elements can be of any type. Some functions accept all types of data, including complex numeric values.

51 Arithmetic Functions Are Polymorphic
Combination Result LabVIEW arithmetic functions are polymorphic. Inputs to arithmetic functions can be of different data types. The function automatically performs the appropriate operation on unlike data types. LabVIEW arithmetic functions greatly simplify array arithmetic. Examples of polymorphism on this slide: Scalar+Scalar: Scalar addition. Scalar+Array: The scalar is added to each element of array. Array+Array: Each element of one array is added to the corresponding element of other array. In case students ask, polymorphism does not perform matrix arithmetic when inputs are 2D arrays. (For example, multiplying two 2D array inputs with the Multiply function performs an element by element multiplication, not matrix multiplication). LabVIEW ships with other examples of arithmetic functions showing polymorphic combinations of inputs.

52 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 Auto-Indexing Auto-Indexing Enabled Wire becomes thicker Allows For Loops and While Loops to accumulate arrays at their boundaries. Is the default behavior for For Loops. Is disabled by default for While Loops. Is enabled/disabled by right-clicking on a tunnel. Produces arrays that are always equal in size to the number of iterations of the loop. 1D Array Auto-Indexing Disabled Wire remains the same size For Loops and While Loops can index and accumulate arrays at their boundaries. This is known as auto-indexing. The indexing point on the boundary is called a tunnel. The For Loop default is auto-indexing enabled. The While Loop default is auto-indexing disabled. Only one value (the last iteration) is passed out of the While Loop by default. Examples: Enable auto-indexing to collect values within the loop and build the array. All values are placed in the array upon exiting the loop. Disable auto-indexing if you are interested only in the final value. Only one value (last iteration) is passed out of the loop

54 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 Charts vs. Graphs – Single-Plot

56 Auto-Indexing with a Conditional Tunnel
Right-click on a tunnel and select Tunnel Mode»Conditional. You can determine what values LabVIEW writes to the loop output tunnel based on a condition you specify by right-clicking the loop output tunnel and selecting Tunnel Mode»Conditional from the shortcut menu. Because of the conditional tunnel, the Values less than 5 array contains only the elements 2, 0, 3, and 1 after this loop completes all iterations.

57 Creating 2D Arrays Inner loop creates column elements.
You can use two nested For Loops to create a 2D array. Auto-indexing must be enabled for both loops. Explain the different line thicknesses in the wire connecting the Random Number function to the 2D Array Indicator. Demonstrate on your computer: How to change indexing and line thickness. When you see Enable indexing in the shortcut menu it means that indexing is currently disabled. The menu choice is the opposite of the current indexing mode. Students get confused about this feature. Inner loop creates column elements. Outer loop stacks column elements into rows.

58 Auto-Indexing Input (EXAM FAVORITE)
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. LabVIEW does not exceed an array size. This helps to protect against programming errors. If you wire a 10-element array and a 5-element array to a For loop, the loop iterates five times. Note: Although the For loop iterates 5 times, the number of iterations is zero-based. Therefore, the final value of the Iterations indicator is 4. 57

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. If you enable auto-indexing on an array wired to a For Loop input terminal, LabVIEW sets the count terminal to the array size so you do not need to wire the count terminal. Normally, if the count terminal of the For Loop is not wired, the Run arrow is broken. In this slide, the For Loop executes a number of times equal to the number of elements in the array. Use auto-indexing on input arrays for calculations to be performed on each element of array. To pass the entire array into a loop, disable auto-indexing. 58

60 Exercise 5-1 Concept: Manipulating Arrays
HOMEWORK Manipulate arrays using various LabVIEW functions.

61 Exercise 5-1 Concept: Manipulating Arrays
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 In the All Data Channel case, how can we verify that the two approaches yield the same results? You can use the comparison and Boolean functions to compare if the All Data Channel array is the same. Comparison functions are also polymorphic. Use the Equal? function followed by the And Array Elements function. Typically, you can’t perform a direct comparison on double-precision values. You would need to compare the values within some acceptable range. However, in this case, the polymorphic Add operation should be an exact equivalent to the Add function in an auto-indexed For loop.

62 Lesson # Lesson Title End of Week 4


Download ppt "Course Learning Map Lesson # Lesson Title Lesson 3 Lesson 2 Lesson 1"

Similar presentations


Ads by Google