Arrays Collection of data elements that are of same type 31 One or more dimensions, up to 2 elements per dimension Elements accessed by their index First element is index 0 index 10-element array 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 2D array 0 1 2 3 4 0 1 2 3 4 5 6 Five-row by seven column array of 35 elements LV Basics I 1
Array Controls and Indicators 1. Select the Array Shell from the Controls palette 2. Place data object inside shell Add Dimension for 2D arrays LV Basics I 2
1. Select Array Constant shell from the Array subpalette Creating Array Constants 2. Place the data object in the array shell LV Basics I 3
Creating and Using Arrays Auto-Indexing loops accumulate arrays at their boundaries For Loops auto index by default; While Loops do not LV Basics I 4
Creating 2D Arrays Inner loop creates column elements Outer loop stacks them into rows LV Basics I 5
Common Array Functions Array Size Initialize Array Array Subset LV Basics I 6
The Build Array Function Appending an element Building a higher dimension array Concatenate Inputs (default) LV Basics I 7
The Index Array Function Extracting an Element Extracting a Row LV Basics I 8
Polymorphism Function inputs can be of different types All LabVIEW arithmetic functions are polymorphic Combination Scalar + Scalar 5 2 7 Result Scalar Array + Scalar 1 4 2 2 3 6 4 Array Array + Array 3 2 5 1 4 2 Array + Array 1 4 2 3 2 5 7 4 6 7 4 6 7 Array Array Run Polymorphism Example.vi LV Basics I 9
Graphs Selected from the Graph subpalette Waveform Graph Plot an array of numbers against their indices XY Graph Plot one array against another Plot Legend (point and line styles) Scale Legend Graph Palette LV Basics I 10
Single-Plot Waveform Graphs Uniform X axis - initial X = 0.0, delta X = 1.0 Uniform X axis - you specify point spacing LV Basics I 11
Multiple-Plot Waveform Graphs Each row is a separate plot (initial X = 0, delta X = 1) LV Basics I 12 Each row is a separate plot (Bundle specifies point spacing of the X axis)
XY Graphs Non-uniform X axis Separate X and Y arrays define data points LV Basics I 13
Chart and Graph Use Summary Use the Context Help window with charts and graphs LV Basics I 14
Clusters Data structure that groups data together Data may be of different types Analogous to record in Pascal or struct in C Elements must be either all controls or all indicators Thought of as wires bundled into a cable LV Basics I 15
Cluster Controls and Indicators 1. Select a Cluster shell from the Array & Cluster subpalette 2. Place objects inside the shell LV Basics I 16
Cluster Constants Select a Cluster Constant shell from the Cluster subpalette Right-click on existing cluster and select Create>>Constant LV Basics I 17
Cluster Order Elements have a logical order (start with 0) To change order, right-click on border and select Reorder Controls in Cluster... LV Basics I 18
Use Clusters to Pass Data to SubVIs Use clusters to pass several values to one terminal Overcomes 28- terminal limit Simplifies wiring LV Basics I 19
Cluster Functions In the Cluster subpalette of the Functions palette Can also be accessed by right-clicking on the cluster terminal Bundle (Terminal labels reflect data type) Bundle By Name LV Basics I 20
Cluster Functions Unbundle Unbundle By Name LV Basics I 21 Unbundled cluster in the diagram
Polymorphism with Clusters Polymorphic functions work with clusters Arithmetic functions can perform computations on clusters of numeric data LV Basics I 22
Summary An array is a collection of elements of same data type numeric, Boolean, string, etc. Creating array or cluster controls/indicators is a two-step process 1. Get array or cluster shell 2. Place desired control/indicator inside the shell Loops can accumulate arrays at boundaries auto-indexing Array functions are in Array subpalette of Functions palette LabVIEW arithmetic functions are polymorphic input different data types Plot data on graphs Many features to manipulate plotted graph Multiple plots can be plotted on one graph Clusters group data that can be different types The Bundle and Unbundle functions are used to create and disassemble clusters LV Basics I 23
Case Structures In the Structures subpalette of Functions palette Enclose nodes or drag them inside the structure Stacked like a deck of cards, only one case visible LV Basics I 24
Boolean and Numeric Cases LV Basics I 25 Note: all possible outputs of the Case structure must be wired
Sequence Structures In the Structures subpalette of Functions palette Executes diagrams sequentially, Frame 0 (0..x), where x is the total number of frames Stacked like a deck of cards, only one frame visible LV Basics I 26
Sequence Locals Pass data from one frame to future frames Created at the border of the Sequence structure Data not available Sequence local created in Frame 1 Data available LV Basics I 27
Formula Node In the Structures subpalette Implement complicated equations Variables created at border Variable names are case sensitive Each statement must terminate with a semicolon (;) Context Help Window shows available functions Note semicolon LV Basics I 28
Conditional Branching in Formula Nodes if (x >= 0) then y = sqrt(x) else y = -99999.0 end if Conditional Operator False Condition LV Basics I 29 Condition True Condition
Summary Two structures to control flow of data Case structure Sequence structure Case structure Boolean or numeric cases selector determines type Subdiagrams placed inside case structure Output from a Case structure must be defined for all cases Sequence structure executes subdiagrams sequentially Sequence locals pass data between frames Created at the border of Sequence structure Data available in subsequent frames Formula Nodes allow direct entry of equations in the block diagram Sequence structures can be replaced with a Case inside of a Loop LV Basics I 30
Strings A string is a sequence of displayable or nondisplayable characters (ASCII) Many uses displaying messages, instrument control, file I/O String control/indicator is in the Controls >> String subpalette LV Basics I 31
String Display Modes Normal display \ code display Password display Hex display LV Basics I 32
String Functions String Length String Length = 20 Strings Concatenate Strings spaces here The quick brown fox jumped over the lazy dog. Concatenated String LV Basics I 33
LV Basics I 34 String Functions
String Functions Converting numbers to strings Converting strings to numbers LV Basics I 35
File Input and Output Three levels of hierarchy High-level utility file VIs Intermediate file I/O VIs Advanced file I/O functions High Level File VIs Intermediate File VIs and Functions Advanced File Functions LV Basics I 36
Intermediate File I/O VIs Open/Create/Replace file opens, creates, or replaces a file Read File reads count bytes from the file Write File writes data to the file Close File closes the file Error handling in file I/O Time & Dialog subpalette Displays a dialog box if an error occurs LV Basics I 37
Saving Data to a File Open/Create/Replace opens the existing file TEST1.DAT and generates refnum and error cluster Write File writes the data Close File closes the file Simple Error Handler checks for errors LV Basics I 38
Reading Data from a File Open/Create/Replace opens the file Read File reads the specified number of bytes from the file Close File closes the file Simple Error Handler checks for errors LV Basics I 39