Title: Introduction to LabVIEW for Scientists and Engineers
1Introduction to LabVIEWfor Scientistsand
Engineers
- UTSI Short Course
- Tullahoma, TN
- November 18 - 20, 2002
- Brad Winkleman, Ph.D.
2Course Goals
- Be able to construct simple LabVIEW programs
- Acquire data with a LabVIEW program
- Know how to continue after the course.
3Not Course Goals
- To become an expert LabVIEW programmer
- To become a large project programmer
- Computer science fundamentals
4What is LabVIEW?
- National Instruments Software Product
- Software or Program Development Environment
- Differences
- Graphical or Icon Based
- Dataflow
5Why LabVIEW?
- Things are easier
- Development time is shorter (4 - 10)
- Modifications are easier
- Debugging done interactively
- Things are better
- Professional attributes
- High performance functions
- Lower Costs
- A Standard
6LabVIEW History
- LabVIEW 1 - 1985 Macintosh only
- LabVIEW 2 - Compiled still Macintosh only
- LabVIEW 3 - The Leap - forward and backward
- LabVIEW 4 - Undoable
- LabVIEW 5 Network
- LabVIEW 6i Internet and Events
7LabVIEW Uses
- Data Acquisition
- Experiment Control
- Process Control
- Data Reduction
- Data Presentation
- Modeling
- Calculation
- Simulation
- Internet and Intranet Communications
- General Tasks (file manipulations, data
translation, plotting, etc)
8Examples
9Crucial LabVIEW Philosophy
- LabVIEW is the tool to solve your problems (not a
LabVIEW standalone application).
10Some Preliminaries
- A LabVIEW Program is called a Virtual Instrument
or VI - A VI is composed of two main parts
- The Front Panel
- The Block Diagram
- Viewing, Editing, and Running from same
environment - Final VI can be separated from LabVIEW, if
necessary.
11The Beginning - The Front Panel
- The Front Panel is the User Interface to
operating the LabVIEW Virtual Instrument - The Front Panel contains Control and Indicator
icons - Program Inputs are via the Controls on the Front
Panel - Results appear in Front Panel Indicators
- VI is controlled from the Toolbar
12A Simple Front Panel
13Exercise - Create A Simple Front Panel
- Open LabVIEW
- New VI
- Controls Palette
- Add Digital Control
- Save as Simple Front Panel.vi
14Exercise - More Complex Front Panel
- Experiment with Controls Palette
- Add more controls
- Save as Complex Front Panel.vi
15A Simple Block Diagram
- Example of the G Language
Control Survey Continued
16Terminals
- Terminals come in many different types
- Shape, Color, Text tell type of terminal, I/O
- Common types
- Numeric - SGL, DBL, EXT
- Text
- Boolean
- Type determined by Front Panel Object
17Wires
- Wires also come in many different types
- Shape, Color, Text tell type of terminal
- Common types
- Numeric - SGL, DBL, EXT
- Text
- Boolean
- Type determined by connections
18Making Connections
- Wires go from output to input
- No Loops
- Bad Wire shows as dotted
- Wires can follow any path that is convenient
19Exercise Create A Simple Block Diagram
- First must have an appropriate Front Panel
20Exercise Create A Simple Block Diagram
- Open Diagram
- Use Function Palette - Add Node
- Connect with Wiring Tool
- Save as Adder.vi
21Exercise - Running the Adder
- Change input values with Operate tool
- Click Run Arrow
- Result Indicator is Updated
- Continuous Run
- Generally not used
- Useful for special situations
22Dataflow in Action
23Data Dependencies Determine Execution Order
- No Dependency - No Defined Execution Order
- Light Bulb in Tool Bar of Block Diagram Shows the
Data Flow
24Dependency Determined by Connections
- Path of wire irrelevant
- Can take many complicated routes
25Editing in LabVIEW
Text
Operate
Scroll Window
Position/Size/Select
Shortcut
Wire
Get Color
Breakpoint
Probe
Set Color
26Exercise - Editing
- Change Position, Size, etc. of Front Panel
Objects - Change Position of Block Diagram Objects
27Relation Between Front Panel and Block Diagram
- Front - User Interface
- Block Diagram - Relationships
- Essentially Independent With Following Exceptions
- All Controls/Indicators on Front Panel are on
Block Diagram as Terminals - Only Controls/Indicators on Front Panel are on
Block Diagram as Terminals - Initial Placement of Terminals is related to
location of Front Panel Object
28Review of Survey
- Virtual Instruments
- Front Panels
- Block Diagrams
29Modifying Front Panel Objects
- Easy
- No Change required in Block Diagram
- Enhances Interface
- Requires LabVIEW not Application
30Exercise - Modifying Front Panel Objects
- Replace controls and indicator as desired
- Block diagram unchanged
- Program has more functionality
31Control Survey
- Controls Indicators
- Numeric
- Important category
- Numerical Information
- Digital Displays, Thermometers, Sliders, Meters,
Etc. - Boolean
- True / False data
- Toggles, Pushbuttons, LED, On/Off Indicators
32Control Survey Continued
- String Path
- Text controls
- Filename controls
- Array Cluster
- Not really controls but modifiers
- Array - identical controls
- Clusters - disparate collections
33Control Survey Continued
- List Table
- Fairly Specialized
- Allow selection or displays lists
- Graph
- Very important
- Charts - accumulate like strip charts
- Graphs - waveform data
- Specialized Graphs
34Control Survey Continued
- Ring Enum
- Special Category
- Useful for selecting Options
- I/O
- New Category
- Used to identify I/O channels by logical name
- RefNum
- Rarely Needed
- Intra - VI communication control
35Control Survey Continued
- Dialog
- Dialog Boxes
- Classic
- LabVIEW 5.0 Controls
- Similar Functionality
- Different Appearance
- ActiveX
- Stuff for ActiveX Components
36Control Survey Continued
- Decorations
- Aesthetics
- Boxes, Arrows, Lines
- No Functionality
- Select a Control and User Control
- Customized Control Interface
- Browse the disk
- Include on the controls palette
37Exercise - Familiarization With Controls Palette
38How to Use Controls
- Most controls are not necessary
- Controls are used to make Front Panel intuitive
39Intuitive Front Panel
40Non-Intuitive Front Panel
41LabVIEW Conventional
- At the User / Program level LabVIEW is a high
level graphical language with dataflow
programming - Underneath LabVIEW is built conventionally as the
previous panel highlights - C, C are its underpinnings
- LabVIEW does use various techniques such as
multithreading to improve performance
42Block Diagram Control Structures
- Continuous Run of Adder
- Gave live updates
- Controlled by Toolbar
- Clumsy
- Like other languages G has Control Structures
to simplify programming - While
- For - Next
- Case
- Sequence (Special Control Structure)
43While Loops
- Diagram inside repetitively executed
- Loop Index terminal begins at zero and increments
once each execution - By default Loop terminates when control terminal
receives a False - If needed loop can be made to stop on True
44Exercise - Looping AdderFront Panel
- Add Toggle Switch to Front Panel
45Exercise - Looping AdderBlock Diagram
- Surround everything with a Loop structure
- Connect Run switch to loop terminal
- Run from Front Panel by flipping toggle switch
and clicking the Run arrow. - No need for Continuous Run arrow
46Waveform Charts
- Chart Display in Looping Adder acts oddly
- Display updates very fast
- Control changes not easily seen
- Display is updating asynchronously
- Not all results displayed
- Default mode of displays
- Display attributes can be modified to force
synchronous update
47For Loops
- Diagram inside repetitively executed
- Loop Index terminal begins at zero and increments
once each execution - Executes the number of times wired to the Count
terminal
48Exercise - For Loop AdderFront Panel
- Add Digital Control to Front Panel
49Exercise - For Loop AdderBlock Diagram
- Replace While with a For structure
- Connect Digital Control to Count terminal
- Run from Front Panel by setting iterations and
clicking the Run arrow.
50The Nature of Loops
- Terminals can be inside or outside loop
- Only terminals inside loop are dynamic
- Outside terminals read once or written once
- Loop has no memory of intermediate results
- Inputs are the same each time through loop
- Output is the last value calculated
51Case Structure
- Standard Case Structure found in C
- Case Structure has multiple subdiagrams
- The selector terminal determines which subdiagram
is executed
52Exercise - CalculatorBlock Diagram
- Add Case Structure around Add Node
- Create multiple cases and subdiagrams
53Exercise - CalculatorFront Panel
- Create a selector for the operation
- Ring and Enumerated Controls are excellent for
this - Save as Looping Calculator.vi
54Sequence Structure - A Special Need
- Control structure unique to LabVIEW dataflow
programming - In dataflow programs data dependencies determine
execution order - Some operations have no data dependency but
require a defined order - Sequence structures provide a forced order to a
series of operations
55Sequence Structure
- Has multiple subdiagrams
- Subdiagrams are executed in sequence - first to
last - Structure has no operational controls
56Sequence Structure Uses
- File I/O
- Data Acquisition
- Initialization
- Termination
57Exercise - Calculator with Save
- Create Sequence
- Add File I/O operations
- Create Local Variables
- Connect Frames
- Connect Data to write
58Exercise - Calculator with Save - Name
59Exercise - Calculator with Save - Create
60Exercise - Calculator with Save - Write
61Exercise - Calculator with Save - Close
62Sequences are BAD
- Hide program elements
- Prevent optimal scheduling
- Can lower performance
- Prevent Parallelism
- Sequence local variables difficult to use
- Dont Use Sequences
63Exercise - Calc with Save (No-Sequence)
- Use data dependencies to determine order
- Create dependencies if they do not exist
- Single frame Sequence structure is useful
64Exercise - Calc with Save (No-Sequence - Another
Way)
- Use data dependencies to determine order
- Create dependencies if they do not exist
65Event Programming
- Similar to Case structure
- Event Structure has multiple subdiagrams
- Execution determined by events
- Waits for an event to occur
- Event programming is different than dataflow
programming
66Events
- Front Panel Activity
- Key Down
- Key Up
- Key Repeat
- Mouse Down
- Mouse Up
- Value Changed
- Timeout event
- Application and VI
- Menu Selection
- Exiting
- Panel Closing
- Events must be configured
67Event Cautions
- Programmatic actions do not generate events
- More than one Event structure in a loop can cause
problems - Latched Boolean controls are delayed
- Event structure waits for an event (possibly
forever)
68Exercise Looping Calculator with Event
Controlled Save
- Previous Calculator only saved the last result
- Need a Calculator that saves intermediate results
- Add Save Control
- Add Event Structure
- Configure Events
69Exercise Looping Calculator with Controlled
Save without Events
?
- Events are not necessary for previous example
- How else can a controlled save be implemented?
70Tunnels
- Tunnels are the nodes at the border of control
structures - Data passes into and out of a structure through
the Tunnel - A white Tunnel on a case structure means not all
cases are wired to tunnel
71Recycling Data in Loops
- Cannot connect a loop output to a loop input
- Violation of no cycle
- Frequently needed
- Averaging
- Accumulation
- Finite Differencing
- Control
- Creating Series
72Shift Registers
- Shift Registers allow recycling of data in loops
- Created by popping - up on the border
- Single or Multi-element
- Uninitialized or initialized
73Exercise - Differencing Calculator
74LabVIEW Arrays
- Basically the same as in other languages
- Normally LabVIEW and Arrays mix well
- Complicated indexing schemes can be tedious
75Front Panel Creation of Arrays
- Front panel array control is like a container
- Putting a control in an array control creates an
array of controls - Pop-menu adds dimensions
- Array index order - row, column, and so forth
76Exercise - Array Creation
- Digital Inputs
- Change to Outputs
- Expand View
- Add Dimension
- Expand View
- Other Arrays
- Try to make an array of arrays
77Polymorphism
- LabVIEW VIs are generally polymorphic - they
accept various types of inputs - Very powerful for array manipulation
- Also handle different numeric types (integer,
single, double) - Concept extendable to non-numeric data types
78Autoindexing
- Loop structures can autoindex at a tunnel
- Input
- New element is used for each execution of loop
- Array size sets Count terminal on For Loop
- Output
- Elements are collected into an array
- Arrays become one higher dimension
- Autoindexing can be disabled
- Very useful feature
79Exercise - Autoindexing
- Create Front Panel
- Array Inputs
- Array Output
80Exercise - Autoindexing
- Place Add Node
- Surround with For Loop
- Connect terminals
- No need to wire Count terminal
81Formula Node
- Not a Control Structure
- Easy formula calculations
- C-like syntax
82Exercise Calc with Formula Node
- Create a calculating VI that uses the Formula Node
83Clusters
- Agglomerations of data
- Minimize wiring
- Useful for connections to SubVIs
- Polymorphism adds to functionality
- Like structures in C
- LabVIEW has some predefined Clusters
84Global and Local Variables
- Dataflow constructs can be a nuisance at times
- Data must flow for point to point
- Wires must be connected to define the flow
- Unwieldy and complicated diagrams can result
- Global and Local Variables allow the
communication of data between points without
wires. - Overall it is best to avoid their use.
85SubVI
- Any VI can be come a SubVI in another VI
- VIs and SubVIs are essentially the same
- Any collection of VIs in a diagram can be grouped
into a SubVI - Use SubVIs to
- Make diagrams more readable
- Produce modular code
- Simplify programming chores
86Exercise - Creating a SubVI
- Open Looping Calculator
- Edit VI options
- Set Connection Pane
- Create Icon
- Embed SubVI in a main VI
87Survey of Functions Palette
- VIs are found on the Function Palette
- VIs are grouped logically (more or less)
- The Function Palette changes
- Installed Options
- New versions (way too often)
- Due to the numerous functions a complete review
is not possible in this course but should be
undertaken by the student.
88Function Survey Using Help Utilities
- Contextual Help
- LabVIEW Help
- VI and Function Reference
- LabVIEW VIs and Functions
89The End
- Basic Concepts have been presented
- Controls and Functions have been reviewed
- Rest of LabVIEW is
- Gaining familiarity with VIs
- Developing dataflow skill (NI offers courses)
- Details, Details, Details