lvb1day2

Upload: jobin-varghese

Post on 14-Apr-2018

214 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/27/2019 Lvb1day2

    1/67

    LV Basics I 1

    Lesson 5Arrays, Graphs, and Clusters

    A. About arrays

    B. About generating arrays with loops

    C. Some basic array functions

    D. What polymorphism is

    E. Using graphs to display dataF. About clusters

    G. Some cluster functions

    You Will Learn:

  • 7/27/2019 Lvb1day2

    2/67

    LV Basics I 2

    Arrays

    Collection of data elements that are of same type

    One or more dimensions, up to 2 elements perdimension

    Elements accessed by their index

    First element is index 0

    31

    index

    10-element array 1.2 3.2 8.2 8.0 4.8 5.1 6.0 1.0 2.5 1.70 1 2 3 4 5 6 7 8 9

    2D array

    Five-row by seven columnarray of 35 elements

    0 1 2 3 4 5 60

    1234

  • 7/27/2019 Lvb1day2

    3/67

    LV Basics I 3

    Array Controls and Indicators

    Add Dimension for 2Darrays

    1. Select the Array Shellfrom the Controls palette

    2. Place data object insideshell

  • 7/27/2019 Lvb1day2

    4/67

    LV Basics I 4

    Creating Array Constants

    1. Select ArrayConstant shellfrom the Arraysubpalette

    2. Place the data object inthe array shell

  • 7/27/2019 Lvb1day2

    5/67

    LV Basics I 5

    Creating and Using Arrays

    Auto- Indexingloops accumulate

    arrays at their

    boundaries

    For Loops auto

    index by default;

    While Loops do

    not

  • 7/27/2019 Lvb1day2

    6/67

    LV Basics I 6

    Creating 2D Arrays

    Inner loop creates column elements

    Outer loop stacks them into rows

  • 7/27/2019 Lvb1day2

    7/67

  • 7/27/2019 Lvb1day2

    8/67

    LV Basics I 8

    The Build Array Function

    Building a higher dimension array

    Concatenate Inputs (default)

    Appending an element

  • 7/27/2019 Lvb1day2

    9/67

    LV Basics I 9

    The Index Array Function

    Extracting an Element

    Extracting a Row

  • 7/27/2019 Lvb1day2

    10/67

    LV Basics I 10

    Polymorphism

    Function inputs can be of different types

    All LabVIEW arithmetic functions are polymorphic

    Run PolymorphismExample.vi

    Scalar + Scalar

    Array + Scalar

    Combination Result

    Scalar

    Array

    Array

    1 4 2

    2

    4 6 7

    5

    27

    Array + Array 3 2 5

    1 4 2

    Array + Array 1 4 2

    3 2 5 7

    Array3 6 4

    4 6 7

  • 7/27/2019 Lvb1day2

    11/67

    LV Basics I 11

    Exercise 5-1 on page 5-11

    Students buildArray Exercise.viTime to complete : 20 min.

  • 7/27/2019 Lvb1day2

    12/67

    LV Basics I 12

    Graphs

    Selected from the Graph subpalette

    Waveform Graph Plot an array of numbersagainst their indices

    XY Graph Plot one array against another

    Plot Legend(point and

    line styles)

    Graph PaletteScale Legend

  • 7/27/2019 Lvb1day2

    13/67

    LV Basics I 13

    Single-Plot Waveform Graphs

    Uniform X axis - initial X = 0.0, delta X = 1.0

    Uniform X axis - you specify point spacing

  • 7/27/2019 Lvb1day2

    14/67

    LV Basics I 14

    Multiple-Plot Waveform Graphs

    Each row is a separate plot (initial X = 0, delta X = 1)

    Each row is a separate plot (Bundle specifies point spacing

    of the X axis)

  • 7/27/2019 Lvb1day2

    15/67

    LV Basics I 15

    XY Graphs

    Non-uniformX axis

    Separate X

    and Y arrays

    define datapoints

  • 7/27/2019 Lvb1day2

    16/67

    LV Basics I 16

    Exercise 5-2 on page 5-16

    Students buildGraph Waveform Array.viTime to complete : 30 min.

  • 7/27/2019 Lvb1day2

    17/67

    LV Basics I 17

    Exercise 5-3 on page 5-22

    Students buildTemperature Analysis.vi*This VI will be used in a later exercise.

    Time to complete: 25-30 min.

  • 7/27/2019 Lvb1day2

    18/67

    LV Basics I 18

    Exercise 5-4 on page 5-26 (Optional)

    Students buildGraph Circle.viTime to complete : 20 min.

  • 7/27/2019 Lvb1day2

    19/67

    LV Basics I 19

    Chart and Graph Use Summary

    Use the Context Help window with charts and graphs

  • 7/27/2019 Lvb1day2

    20/67

  • 7/27/2019 Lvb1day2

    21/67

    LV Basics I 21

    1. Select a Clustershellfrom the Array &Clustersubpalette

    Cluster Controls and Indicators

    2. Place objects inside the shell

  • 7/27/2019 Lvb1day2

    22/67

    LV Basics I 22

    Cluster Constants

    Select a ClusterConstant shell from the Cluster

    subpalette Right-click on existing cluster and select

    Create>>Constant

  • 7/27/2019 Lvb1day2

    23/67

  • 7/27/2019 Lvb1day2

    24/67

    LV Basics I 24

    Use Clusters to Pass Data to SubVIs

    Use clusters topass several

    values to one

    terminal

    Overcomes 28-terminal limit

    Simplifies wiring

  • 7/27/2019 Lvb1day2

    25/67

    LV Basics I 25

    Cluster Functions

    In the Clustersubpalette of the Functions palette

    Can also be accessed by right-clicking on the clusterterminal

    Bundle

    (Terminal labelsreflect data type)

    Bundle By Name

  • 7/27/2019 Lvb1day2

    26/67

    LV Basics I 26

    Cluster Functions

    Unbundle

    Unbundle By Name

    Unbundled clusterin the diagram

  • 7/27/2019 Lvb1day2

    27/67

    LV Basics I 28

    Polymorphism with Clusters

    Polymorphic functions work with clusters

    Arithmetic functions can perform computationson clusters of numeric data

  • 7/27/2019 Lvb1day2

    28/67

    LV Basics I 29

    Exercise 5-5 on Page 5-40

    Students build Cluster Exercise.viApproximate time to complete: 30 min.

  • 7/27/2019 Lvb1day2

    29/67

    LV Basics I 30

    Exercise 5-6 on Page 6-43

    (Optional)

    Students build Cluster Scaling.viApproximate time to complete: 10 min.

  • 7/27/2019 Lvb1day2

    30/67

    LV Basics I 31

    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 shell2. 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 inputdifferent 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 anddisassemble clusters

  • 7/27/2019 Lvb1day2

    31/67

    LV Basics I 32

    Additional Exerciseson page 5-46

    5-7Students buildReverse Random Array.viTime to complete: 20 min.

    5-8Students buildFind Mid Value.viTime to complete: 20 min.

    5-9Students buildExtract 2D Array.viTime to complete: 20 min.

    5-10 (Challenge) Students buildDie Roller.viTime to complete: 35-40 min.

    5-11 (Challenge) Students build Array Pair Multiplier.viTime to complete: 20 min.

  • 7/27/2019 Lvb1day2

    32/67

    LV Basics I 33

    Lesson 6Case and Sequence Structures

    A. About Case structuresB. About Sequence structures

    C. About Formula Nodes

    D. How to replace Sequence structures

    You Will Learn:

  • 7/27/2019 Lvb1day2

    33/67

    LV Basics I 34

    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

  • 7/27/2019 Lvb1day2

    34/67

    LV Basics I 35

    Boolean and Numeric Cases

    Note: all possible outputs of the Case structure must be wired

  • 7/27/2019 Lvb1day2

    35/67

  • 7/27/2019 Lvb1day2

    36/67

  • 7/27/2019 Lvb1day2

    37/67

    LV Basics I 38

    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

  • 7/27/2019 Lvb1day2

    38/67

    LV Basics I 39

    Sequence Locals

    Pass data from one frame to future frames

    Created at the border of the Sequence structure

    Sequence localcreated inFrame 1

    Data notavailable

    Dataavailable

  • 7/27/2019 Lvb1day2

    39/67

    LV Basics I 40

    Exercise 6-3 on page 6-13

    Students buildTime to Match.vi by modifyingAuto Match.vi (Ex. 4-3)Time to complete: 30 min.

  • 7/27/2019 Lvb1day2

    40/67

    LV Basics I 41

    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

  • 7/27/2019 Lvb1day2

    41/67

    LV Basics I 42

    Conditional Branching in Formula Nodes

    if (x >= 0) then

    y = sqrt(x)else

    y = -99999.0end if

    Condition

    Conditional Operator

    True Condition

    False Condition

  • 7/27/2019 Lvb1day2

    42/67

    LV Basics I 43

    Exercise 6-4 on page 6-18

    Students buildFormula Node Exercise.viTime to complete: 20 min.

  • 7/27/2019 Lvb1day2

    43/67

  • 7/27/2019 Lvb1day2

    44/67

    LV Basics I 45

    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 blockdiagram

    Sequence structures can be replaced with a Case inside of a

    Loop

  • 7/27/2019 Lvb1day2

    45/67

    LV Basics I 46

    Additional Exercises on page 6-23

    6-5 Students buildEquations.viTime to complete: 20 min.

    6-6 Students buildCalculator.viTime to complete: 30 min.

    6-7 Students buildSquare Root 2.viTime to complete: 20 min.

    6-8

    (Challenge) Students buildUsing ArrayOver Threshold.vi

    Time to complete: 30 min.

  • 7/27/2019 Lvb1day2

    46/67

    LV Basics I 47

    Lesson 7Strings and File I/O

    A. How to create string controls and

    indicatorsB. Some string functions

    C. How to perform file input and output

    operations

    D. How to format text files for spreadsheets

    E. How to use the high-level File VIs

    You Will Learn:

  • 7/27/2019 Lvb1day2

    47/67

  • 7/27/2019 Lvb1day2

    48/67

    LV Basics I 49

    String Display Modes

    Normal display

    Password display

    \ code display

    Hex display

  • 7/27/2019 Lvb1day2

    49/67

    LV Basics I 50

    String Functions

    Concatenate Strings

    The quick brown fox jumped over the lazy dog.

    Concatenated String

    Strings

    spaces here

    String Length

    = 20Length

    String

  • 7/27/2019 Lvb1day2

    50/67

    LV Basics I 51

    String Functions

  • 7/27/2019 Lvb1day2

    51/67

    LV Basics I 52

    String Functions

    Converting numbers to strings

    Converting strings to numbers

  • 7/27/2019 Lvb1day2

    52/67

    LV Basics I 53

    Edit Format StringFormat Into String & Scan From String Functions

  • 7/27/2019 Lvb1day2

    53/67

  • 7/27/2019 Lvb1day2

    54/67

    LV Basics I 55

    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 FileVIs and Functions

    Advanced FileFunctions

  • 7/27/2019 Lvb1day2

    55/67

    LV Basics I 56

    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

  • 7/27/2019 Lvb1day2

    56/67

    LV Basics I 57

    Saving Data to a File

    Open/Create/Replace opens the existing fileTEST1.DAT and generates refnum and error

    cluster

    Write File writes the data

    Close File closes the file

    Simple Error Handler checks for errors

  • 7/27/2019 Lvb1day2

    57/67

    LV Basics I 58

    Reading Data from a File

    Open/Create/Replace opens the file

    Read File reads the specified number of bytesfrom the file

    Close File closes the file

    Simple Error Handler checks for errors

  • 7/27/2019 Lvb1day2

    58/67

    LV Basics I 59

    Exercise 7-2 on page 7-17

    Students buildFile Writer.viTime to complete: 20 min.

  • 7/27/2019 Lvb1day2

    59/67

    LV Basics I 60

    Exercise 7-3 on page 7-19

    Students buildFile Reader.viTime to complete: 20 min.

  • 7/27/2019 Lvb1day2

    60/67

    LV Basics I 61

    Formatting a Spreadsheet String

    Spreadsheets are popular tools for data handling

    and analysis There are many formats for spreadsheet data.

    One of the most popular is tab-del imited:

    Columns are separated by a tab character

    Rows are separated by an end-of-linecharacter

    Easily created using LabVIEW file I/O VIs

  • 7/27/2019 Lvb1day2

    61/67

  • 7/27/2019 Lvb1day2

    62/67

    LV Basics I 63

    Exercise 7-4 on page 7-23

    Students buildTemperature Logger.vi bymodifying Temperature Control.vi

    *This VI will be used in a later exercise.Time to complete: 25 min.

  • 7/27/2019 Lvb1day2

    63/67

    LV Basics I 64

    High-level File I/O VIs

    Write to Spreadsheet File

    Read from Spreadsheet File Write Characters to File

    Read Characters from File

    Read Lines from File

  • 7/27/2019 Lvb1day2

    64/67

    LV Basics I 65

    Exercise 7-5 on page 7-30

    Students runSpreadsheet Example.viTime to complete: 25 min.

  • 7/27/2019 Lvb1day2

    65/67

    S

  • 7/27/2019 Lvb1day2

    66/67

    LV Basics I 67

    Summary

    String is a collection of ASCII characters many uses

    Display messages

    Instrument control

    File I/O

    Many functions to manipulate strings Strings palette of

    Functions menu

    Three levels of File I/O hierarchy

    High-level VIs

    Intermediate VIs and functions

    Advanced functions

    Writing data in spreadsheet format Tab character separates columns

    End-of-line character separates rows

    Write/Read from spreadsheet high-level File I/O VIs

  • 7/27/2019 Lvb1day2

    67/67

    Additional Exercises on page 7-37

    7-7(Challenge)Students build MoreSpreadsheets.vi

    Time to complete: 25 min.

    7-8

    (Challenge)Students buildSpreadsheetConverter.vi

    Time to complete: 30 min.

    7-9

    Students modifyTemperature Logger.vi(Ex. 7-4) and save the new VI asTemperature Logger 2.vi

    Time to complete: 25 min.