Download presentation
Presentation is loading. Please wait.
Published byAudrey Mitchell Modified over 6 years ago
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 5 Creating and Leveraging Data Structures
Arrays Common Array Functions Polymorphism Auto-Indexing Clusters Type Definitions
3
E. Clusters Reasons To Use Clusters Cluster vs. Arrays
Creating a Cluster Control and Constant Ordering Items and Resizing Clusters Disassembling and Modifying Clusters Plotting Data
4
Clusters Clusters group data elements of mixed types.
Clusters are similar to a record or a struct in text-based programming languages. Additional items to mention: Bundling several data elements into clusters eliminates wire clutter on the block diagram and reduces inputs and outputs for subVIs. Most clusters on the block diagram have a pink wire and data type terminal. Clusters of numeric values, sometimes referred to as points, have a brown wire and data type terminal. You can wire brown numeric clusters to Numeric functions to perform the same operation simultaneously on all elements of the cluster. 3
5
Why Use Clusters? Keep data organized.
Logically group related data values together. Improve diagram readability by eliminating wire clutter. Reduce the number of connector pane terminals.
6
Clusters vs. Arrays Clusters are a fixed size.
Clusters can contain mixed data types. Clusters can be a control, an indicator, or a constant. All elements have to be controls, indicators, or constants. Arrays vary in size. Arrays contain only one data type. Arrays can be a control, an indicator, or a constant. 5
7
Create a Cluster Control
For a new cluster: On the front panel, select Cluster from the Controls palette. Place a data object into the cluster shell. Place additional data objects, if necessary, into the shell. From block diagram terminal or wire: Right-click and select Create»Control or Create»Indicator. 6
8
Create a Cluster Constant
For a new cluster: On the block diagram, select Cluster Constant from the Functions palette. Place a constant into the cluster shell. Place additional data objects, if necessary, into the cluster shell. From block diagram terminal or wire: Right-click and select Create»Constant. 7
9
Cluster Order Cluster elements have a logical order unrelated to their position in the shell. You can view and modify the cluster order by right-clicking the cluster border and selecting Reorder Controls In Cluster. Notes: The first object you place in the cluster is element 0, the second is element 1, and so on. If you delete an element, the order adjusts automatically. The cluster order determines the order in which the elements appear as terminals on the Bundle and Unbundle functions on the block diagram. Use AutoSizing»Arrange Horizontally or AutoSizing»Arrange Vertically from the shortcut menu to arrange the elements in the cluster horizontally or vertically in order.
10
Autosizing Clusters Autosizing helps you arrange elements in clusters.
NI recommends the following: Arrange cluster elements vertically. Arrange elements compactly. Arranges elements in their preferred order.
11
Disassembling a Cluster
Use the Unbundle By Name function whenever possible. Use Unbundle function when some or all cluster elements are unnamed. In this slide, the Polynomial Plot.vi outputs an XY Graph as a cluster of two arrays (X and Y). The Y array is labeled as P(A) so you can access it using the Unbundle By Name function. However, the X array is unlabeled so you cannot access it using the Unbundle By Name function. To access data in the X array, use the Unbundle function.
12
Modifying a Cluster Use Bundle By Name whenever possible to access elements in a cluster. Use Bundle when some or all cluster elements are unnamed. You must wire the input cluster terminal. In this slide, both examples modify the Y array, (P(A), of the Polynomial Plot.vi with a Butterworth filter. In the bottom example, you also increment the X array of the Polynomial Plot.vi output by one.
13
Creating a Cluster on the Diagram
Use the Bundle function to programmatically create a cluster on a block diagram. If the elements that are bundled have labels, you can access them using the Unbundle By Name function. Otherwise use the Unbundle function. This technique is typically used to create multi-plot charts which is discussed in more detail later.
14
Charts vs. Graphs – Multi-plot and XY Graph
The Bundle function is often used to create multi-chart plot charts and XY plots. The Build Array function is used to create multi-plot waveform graphs.
15
Plotting Data Use the Context Help window to determine how to wire multi-plot data to Waveform Graphs, Charts and XY Graphs. Use the Context Help and shipping examples to investigate all the possible ways to assemble data for various graphical displays. LabVIEW examples and help provide extensive information on wiring data to the various graphical displays.
16
Error Clusters LabVIEW uses error clusters to pass error information.
An error cluster contains the following elements: status—Boolean value that reports True if an error occurs. code—32-bit signed integer that identifies the error. source—String that identifies where the error occurred.
17
Exercise 5-2 Temperature Warnings – Clusters
Create clusters, reorder clusters, and use the cluster functions to assemble and disassemble elements.
18
Exercise 5-2 Temperature Warnings – Clusters
What would happen if you reordered cluster elements? What would happen if you added a cluster element to Weather Data Out? What would happen if you reordered cluster elements? Both the subVI and calling VI would continue to work as expected since the only cluster functions used are Unbundle By Name and Bundle By Name. A change to element order in a cluster does not break these functions. What would happen if you added a cluster element to Weather Data Out? Both the subVI and the calling VI would be broken because of mismatching cluster data types.
19
F. Type Definitions Type Definitions and Custom Data Types
Creating and Identifying Type Definitions Controls Strict Type Definitions
20
Type Definitions (Type Def)
A type definition is a master copy of a custom data type (control, indicator, or constant). A custom data type is saved in a .ctl file. Instances of a type def are linked to the .ctl file. Instances can be controls, indicators, or constants. When the type def changes, instances automatically update. Changes include data type changes, elements added, elements removed, and adding items to an enum. You can use type definitions to define custom arrays and clusters. A type definition is a master copy of a custom data type (custom control, indicator, or constant) that multiple VIs can use. When you use type definitions, you can update of all instances or copies of the custom data type in a single edit.
21
Creating Type Definitions (Type Def)
Right-click a control, indicator or constant and select Make Typedef. Right-click the object again and select Open Type Def. Edit control, if needed. Save control as a .ctl file.
22
Identifying Type Definitions (Type Def)
Look for a glyph marking the upper left corner of terminals and constants. Hover cursor over glyph to view tip strip. View Context Help while hovering cursor over terminal or constant.
23
Other Control Options You can save a custom control as: Control
Type Definition Strict Type Definition LabVIEW has three kinds of custom controls (.ctl files): A regular custom control Used to create controls that behave like existing controls but look different. A type def or type definition control Used for changing all instances of a linked control in a single edit. A strict type def control Used for changing instances in a single edit. Used to ensure all instances have same appearance. 22
24
Control Instances are not linked to a.ctl file.
Each instance is an independent copy of the control. Used to create controls that behave like existing controls but look different. Refer to LabVIEW Help for information on how to use the Control Editor to customize controls. Typically, if you create a custom control you want it linked to the .ctl file as a type definition.
25
Strict Type Definition
Strict type definitions are similar to a type definition in that: All instances link to .ctl file. When attributes or data types change, all instances update. Examples: Changing a knob to a dial, a round LED to a square LED, or a double to an integer. Strict type definitions enforce every aspect of a instance except label, description, and default value. Use strict type definitions to ensure all front panel instances have the same appearance. 24
26
Exercise 5-3 Weather Warnings – Type Definition
Create and modify a type-defined cluster control. Use the type definition in a calling VI and a subVI. This exercise explores the differences between a type definition and a strict type definition.
27
Exercise 5-3 Weather Warnings – Type Definition
Now that the Weather Data control is saved as a type definition, how many instances of the cluster would need to be updated to add wind speed data? Now that the Weather Data control is saved as a type definition, how many instances of the cluster would need to be updated to add wind speed data? One. You add elements to the type definition. Apply and save changes. Converting from a cluster to a type definition requires a one-time update to each cluster. However, once you have your data in a type definition, adding or removing elements is a simple update to the type definition control.
28
Summary—Quiz You can create an array of arrays. True False 27
Answer is False. 27
29
Summary—Quiz Answer You can create an array of arrays. True
False You cannot drag an array data type into an array shell. However, you can create two-dimensional arrays. 28
30
Summary—Quiz What is the value of the Iterations indicator after running this VI? Answer is 4. 29
31
Summary—Quiz Answer What is the value of the Iterations indicator after running this VI? 4 LabVIEW does not exceed the array size. This helps to protect against programming error. So the loop runs 5 times. Although the for loop runs 5 times, the iterations are zero-based. Therefore the value of the Iterations indicators is 4. 30
32
Summary—Quiz Which of the following custom control settings defines the data type of all instances of a control but allows for different colors and font styles? Control Type definition Strict type definition Cluster control Answer is b. 31
33
Summary—Quiz Answer Which of the following custom control settings defines the data type of all instances of a control but allows for different colors and font styles? Control Type definition Strict type definition Cluster control A standard type definition ensures that all instances of the control use the same data type but allows for flexibility in colors and font styles. A strict type definition is similar to a type definition but forces everything to be identical except label, description and default value. There is no connection between a custom control and the instance of a custom control. Therefore selecting control does not define the data type of all instances. 32
34
Summary—Quiz You have input data representing a circle: X Position, Y Position, and Radius. In the future, you might need to modify your data to include the color of the circle. What data structure should you use to represent the circle in your application? Three separate controls for the two positions and the radius A cluster containing all of the data A custom control containing a cluster A type definition containing a cluster An array with three elements R (X,Y) Answer is d.
35
Summary—Quiz Answer You have input data representing a circle: X Position, Y Position, and Radius. In the future, you might need to modify your data to include the color of the circle. What data structure should you use to represent the circle in your application? Three separate controls for the two positions and the radius A cluster containing all of the data A custom control containing a cluster A type definition containing a cluster An array with three elements R (X,Y)
36
Lesson 6 Managing File and Hardware Resources
Understanding File and Hardware Resources File I/O Acquiring Measurements with a DAQ System Controlling Instruments
37
A. Understanding File and Hardware Resources
Definition of Resources Accessing Resources in LabVIEW
38
What are Resources? Resources – An addressable file, hardware device, object, or network connection available on your system LabVIEW includes VIs and functions to allow you to access your resources. Resources are known to the system by a path, name, port, or other identifier.
39
Accessing Resources in LabVIEW
A typical resource operation involves the following process: Open, Initialize or Create Read and/or Write Close Check for Errors Specify the path or device name. LabVIEW creates a refnum as a unique identifier to the resource. A refnum is a temporary pointer to the resource. The refnum becomes obsolete.
40
Accessing Resources in LabVIEW
Sample refnum wires: Because a refnum is a temporary pointer to an open object, it is valid only for the period during which the object is open. If you close the object, LabVIEW disassociates the refnum with the object, and the refnum becomes obsolete. If you open the object again, LabVIEW creates a new refnum that is different from the first refnum. LabVIEW allocates memory for an object that is associated with a refnum. Close the refnum to release the object from memory.
41
B. File I/O Understanding File I/O File Formats
High-Level and Low-Level I/O
42
File I/O Understanding File I/O File Formats High-Level File I/O VIs
Low-Level File I/O VIs
43
Understanding File I/O
File I/O writes to or reads from a file. A typical file I/O operation involves the following process: Open/ Create/ Replace File Read and/or Write to File Close File Check for Errors
44
File Formats LabVIEW can use or create the following file formats:
Binary—Efficient, compact, and allows random access reading but not a human-readable file. Commonly used for high-speed and multi-channel DAQ. ASCII—Human-readable text file where data is represented as strings. Commonly used for low-speed DAQ. LVM—Format built on ASCII, the LabVIEW measurement data file (.lvm) is a tab-delimited text file you can open with a spreadsheet application or a text-editing application. TDMS—An NI-specific binary file format that contains data and stores properties about the data. ASCII files are also called text files. Students will learn more about TDMS files in LabVIEW Core 2.
45
ASCII File Format In this course, you learn about creating text (ASCII) files. Use ASCII files in the following situations: You want to access the file from another application. Disk space and file I/O speed are not crucial. You do not need to perform random access reads or writes. Numeric precision is not important.
46
High-Level File I/O High-level File I/O functions:
Perform all three steps (open, read/write, close) for common file I/O operations. Might not be as efficient as the functions configured or designed for individual operations. Low-level File I/O functions: Provide individual functions for each step. Are efficient for writing to a file in a loop. Point out the high-level functions and low-level functions on the palette. High-level and low-level file I/O applies to many areas, such as DAQ and TCP/IP.
47
High-Level File I/O Write to Spreadsheet File
Converts an array of double-precision numbers to a text string and writes the string to an ASCII file. Read From Spreadsheet File Reads a specified number of lines or rows from a numeric text file and outputs a 2D array of double-precision numbers. Write To/Read From Measurement File Express VIs that write data to or read data from an LVM or TDMS file format.
48
Understanding Low-Level File I/O VIs
Explain the concept of disk streaming here. Emphasize opening and closing the file outside of the loop.
49
Exercise 6-1 Concept: Spreadsheet Example VI
HOMEWORK Use a high-level file I/O VI to write to a spreadsheet-readable file.
50
Exercise 6-2 Temperature Monitor VI – Logging Data
Modify a VI to create an ASCII file using disk streaming. Instructor: Encourage your faster students to try the challenge exercises the follow this exercise. Students are challenged to add headers to the file, write multiple values separated by a tab, etc.
51
Exercise 6-2 Temperature Monitor VI – Logging Data
HOMEWORK What would happen if you used the Write to Measurement File Express VI inside the While loop? What would happen if you used the Write to Measurement File Express VI inside the While loop? The VI would run slower and be more inefficient. Because the Write to Measurement File Express VI is a high-level File I/O VI, the While Loop would open, write, and close the file every iteration of the While Loop. Instead, you should use low-level File I/O functions when streaming data to a file in a loop, so that you only open the file once at the beginning of the VI and close the file once at the end of the VI.
52
Lesson # Lesson Title End of Week 5
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.