Upload
njainitm
View
720
Download
2
Embed Size (px)
Citation preview
1
LabVIEW Basics I: Introduction
11500 North Mopac ExpresswayAustin, Texas 78759
ni.com/training
What You Need To Get Started
• LabVIEW Basics I Course Manual • LabVIEW Basics I Course CD• Multifunction DAQ device
ni.com/training
Computer running LabVIEW 8.6 or later
and Windows 2000 or later
• Multifunction DAQ device• GPIB interface• DAQ Signal Accessory, wires, and cable• NI Instrument Simulator and power supply• Serial and GPIB cables
File Locations
The course installer places the course files in the following location:
Exercises LabVIEW
ni.com/training
Root DirectoryExercises
<or>Solutions
LabVIEW Basics I
Instructional Methods
• Lecture gives a foundation in the topic
• Instructor reinforces foundation through
TopicLecture
Quizzes
Demonstrations
Concept Exercise
Development Exercise
ni.com/training
demonstrations and quizzes• Use concept exercises to further explore a topic− Watch a simulation, experiment with example VIs
• Use development exercises to gain hands-on experience− Demonstration of a finished development exercise further
reinforces the learning process
Getting The Most Out Of This Course
• Experiment with hands-on exercises to understand the methods used
• Implementations explore a possible solution—you may find a better one
ni.com/training
• Do not come to class prepared to develop an outside application; concentrate on the exercises given to build a good foundation
Courses
New User
LabVIEW Basics I
LabVIEW Basics II
Experienced User
LabVIEW Intermediate I
LabVIEW Intermediate II
Advanced User
LabVIEW Advanced I
Skills learned:• LabVIEW environment
navigation• Basics application creation
using LabVIEW• Basics of data acquisition and
Skills learned:• Modular application
development• Structured design and
development practices• Inter-application
Skills learned:• Large application design• Advanced development
techniques• Implementing multideveloper
projects
ni.com/training6
Certifications
Certified LV Associate Developer Exam
Skills tested:• LabVIEW environment
knowledge
Certified LabVIEW Developer Exam
Skills tested:• LabVIEW application
development expertise
Certified LabVIEW Architect Exam
Skills tested:• LabVIEW application
development mastery
• Basics of data acquisition and instrument control
• Inter-application communication and connectivity techniques
projects
2
Course Learning Map
Lesson 2
Lesson 1
Problem Solving
Lesson 5
Lesson 4
Implementing a VILesson 8
Data Acquisition
Lesson 7
Developing Modular Applications
ni.com/training
Lesson 3
Troubleshooting & Debugging VIs
Navigating LabVIEW
Lesson 6
Storing Measurement Data
Relating Data
Lesson 10
Common Design Techniques
Lesson 9
Instrument Control
Course Goals
This course prepares you for the following:• Solve problems using LabVIEW• Use data acquisition and instrument control in LabVIEW
applications
ni.com/training
pp• Use modular programming practices• Develop, debug, and test LabVIEW VIs• Effectively use a state machine architecture
8
TOPICS
Lesson 1Problem Solving
ni.com/training
A. Software Development Method
B. ScenarioC. DesignD. Implementation
E. TestingF. MaintenanceG. Project
A. Software Development Method
• Problem solving skills are essential to creating software solutions
• Computer programmers use a software development method
ni.com/training
• Using the software development method, code is more likely to be successful, readable, scalable, and maintainable
10
Software Development Method
1. Define the problem (Scenario)2. Design an algorithm or flowchart3. Implement the design4. Test and verify the implementation
ni.com/training
4. Test and verify the implementation5. Maintain and update the implementation
11
Software Development Method
• Used in all hands-on development exercises in this course• Scenario and Design are usually given; you implement the
design and test the implementation
ni.com/training12
3
B. Scenario
Define the problem
Furnace Example:Cure a material at a certain temperature for a set amount of
ni.com/training
Cure a material at a certain temperature for a set amount of time in a furnace. You must know:• Cure time• Cure temperature• Method for adjusting the temperature
13
C. Design
Design a solution by analyzing the problem:• Identify the software inputs• Identify the software outputs• Identify additional requirements
ni.com/training
Identify additional requirements• Design an algorithm or flowchart
14
Design—Software Inputs
Raw data you want to process, such as information received from the user, data acquisition, instrument control and so on
Furnace Example:
ni.com/training
pCure Time (seconds) Desired Cure Temperature (degrees Kelvin)Current Furnace Temperature (degrees Kelvin)
15
Design—Software Outputs
Results of calculations, processing, or other implemented conditions such as information displayed to the user, data written to file, signal generation, and so on
ni.com/training
Furnace Example: On/Off switch to control coil voltage
16
Design – Additional Requirements
Factors that influence solving the problem
Furnace Example: Assume the furnace cannot start until the interior
ni.com/training
Assume the furnace cannot start until the interior temperature is the same as the exterior temperature. This requirement adds an additional input: Exterior Temperature (degrees Kelvin).
17
Design – Algorithm
Steps that process your inputs and create outputs
Furnace Example:
ni.com/training
1. Read exterior temp2. Read interior temp3. If interior temp ≠
exterior temp, go to step 1
4. Read interior temp
5. If current temp ≥ desired temp, turn off voltage to coil
6. If current temp < desired temp, turn on voltage to coil
7. If time < cure time, go to step 48. Turn off voltage to coil
18
4
Design –FlowchartVisual design of an algorithmFurnace Example:
ni.com/training19
Design – State Transition Diagram
Type of flowchart that indicates the states of a program and transitions between states• State—part of a program that satisfies a condition,
performs an action or waits for an event
ni.com/training
• Transition—condition, action, or event that causes the program to move to the next state
20
Design – State Transition Diagram
Furnace Example:
ni.com/training21
D. Implementation
• Create code for the algorithm or flowchart• Course goal— to successfully create implementations in
LabVIEW
ni.com/training22
E. Testing
Test implementation with logical and illogical data• Does logical data produce expected result?• Does illogical data produce expected error?• How does illogical data affect the results?
ni.com/training
How does illogical data affect the results?• Is error handling strategy sufficient?
23
F. Maintenance
• Ongoing process of resolving programming errors• Implement changes to the original solution
ni.com/training24
5
Exercise 1-1: Software Development Method
ni.com/training
GOAL
Solve a non-programming problem using the software development method described in this course.
G. Project – Temperature Weather Station
1. Acquires a temperature every half second2. Analyzes each temperature to determine if the
temperature is too high or too low3. Alerts the user if there is a danger of a heat stroke or a
ni.com/training
gfreeze
4. Displays the data to the user5. Logs the data if a warning occurs6. If the user does not stop the program, the entire process
repeats
26
G. Project
ni.com/training27
G. Project
Many possible solutionsExample of an alternate solution:
ni.com/training28
Summary—Matching Quiz
1. Scenario2. Design3. Implementation4. Testing
A. Apply an algorithm or flowchart
B. Verify the codeC. Define the problem
ni.com/training
4. Testing5. Maintenance
pD. Update the codeE. Identify the inputs and
outputs
29
Summary—Matching Quiz Answers
1. Scenario2. Design3. Implementation4. Testing
C. Define the problemE. Identify the inputs and
outputsA. Apply an algorithm or
ni.com/training
4. Testing5. Maintenance
pp y gflowchart
B. Verify the codeD. Update the code
30
1
TOPICS
Lesson 2Navigating LabVIEW
ni.com/training
A. Virtual Instruments B. Parts of a VIC. Starting a VID. Project ExplorerE. Front PanelF. Block Diagram
G. Searching PalettesH. Selecting a ToolI. DataflowJ. Building a Simple VI
1
A. Virtual Instruments (VIs)
• LabVIEW programs are called virtual instruments, or VIs• Appearance and operation imitate physical instruments,
such as oscilloscopes and digital multimeters
ni.com/training2
B. Parts of a VI
LabVIEW VIs contain three main components:1. Front Panel 2. Block Diagram 3. Icon/Connector Pane
ni.com/training3
B. Parts of a VI – Front Panel
• User interface for the VI
• You build the front panel with
ni.com/training
controls (inputs) and indicators (outputs)
4
B. Parts of a VI – Block Diagram
• Contains the graphical source code
• Front panel objects
ni.com/training
appear as terminals on the block diagram
5
B. Parts of a VI – Icon/Connector Pane
• Icon: graphical representation of a VI• Connector Pane: map of the inputs and outputs of a VI• Icons and connector panes are necessary to use a VI as
a subVI
ni.com/training
− A subVI is a VI that is inside of another VI− Similar to a function in a text-based programming
languageIcon Connector Pane
6
2
Demonstration
Starting A VI
ni.com/training
GOAL
Demonstrate using the Getting Started dialog box and the New dialog box to start a VI.
D. Project ExplorerUse LabVIEW Projects to:• group together LabVIEW files and non-LabVIEW files• create build specifications• deploy or download files to targets
ni.com/training8
Demonstration
Project Explorer
ni.com/training
GOAL
Demonstrate creating a project, adding files, and removing files.
E. Front Panel
ni.com/training10
E. Front Panel – Controls Palette
• Contains the controls and indicators you use to create the front panel
• Access from the front panel by selecting View»Controls Palette
ni.com/training11
E. Front Panel – Front Panel Toolbar
ni.com/training12
3
E. Front Panel – Controls & Indicators
• Controls− Knobs, push buttons, dials, and other input devices− Simulate instrument input devices and supply data to the
block diagram of the VI• Indicators
ni.com/training
• Indicators− Graphs, LEDs, and other displays− Simulate instrument output devices and display data the block
diagram acquires or generates
13
E. Front Panel – Numeric Controls/IndicatorsThe numeric data type can represent numbers of various types, such as integer or real
ni.com/training14
Numeric Indicator
Numeric ControlIncrement/Decrement Buttons
E. Front Panel – Boolean Controls/Indicators• The Boolean data type represents data that only has two
parts, such as True and False or On and Off• Use Boolean controls and indicators to enter and display
Boolean (True or False) values
ni.com/training
• Boolean objects simulate switches, push buttons, and LEDs
15
BooleanControl
BooleanIndicator
E. Front Panel – Strings
• The string data type is a sequence of ASCII characters • Use string controls to receive text from the user such as a
password or user name• Use string indicators to display text to the user
ni.com/training
g p y
16
E. Front Panel – Shortcut Menus
• All LabVIEW objects have associated shortcut menus
• As you create a VI, use the shortcut menu items to change the look or behavior of front
ni.com/training
panel and block diagram objects
• To access the shortcut menu, right-click the object
17
E. Front Panel – Property Dialog Box
• Right-click a front panel object and select Properties to display
• The options available on the property dialog box
ni.com/training
p p y gare similar to the options available on the shortcut menu for that object
18
4
F. Block Diagram
Block diagram objects include the following:
• Terminals• SubVIs
ni.com/training
• Functions• Constants• Structures• Wires
19
F. Block Diagram – Functions Palette
Contains the VIs, functions, and constants you use to create the block diagram
ni.com/training20
F. Block Diagram – Block Diagram Toolbar
ni.com/training21
F. Block Diagram – Terminals
• Terminals are:− Block diagram appearance of front panel objects− Entry and exit ports that exchange information between the
front panel and block diagram
ni.com/training
− Analogous to parameters and constants in text-based programming languages
• Change the view type of a terminal by toggling the View as Icon selection from the context menu
22
F. Block Diagram Terminals
ni.com/training23
F. Block Diagram – Nodes
• Objects on the block diagram that have inputs and/or outputs and perform operations when a VI runs
• Analogous to statements, operators, functions, and subroutines in text-based programming languages
ni.com/training
• Nodes can be functions, subVIs, or structures
24
Nodes
5
F. Block Diagram – Function Nodes
• Fundamental operating elements of LabVIEW• Do not have front panels or block diagrams, but do have
connector panes• Double-clicking a function only selects the function – does
ni.com/training
g ynot open it like a VI
• Has a pale yellow background on its icon
25
F. Block Diagram – SubVI Nodes
• SubVI: VIs that you build to use inside of another VI• Any VI has the potential to be used as a subVI• When you double-click a subVI on the block diagram, you
can view the front panel and block diagram of the subVI
ni.com/training
p g− The upper right corner of the front panel and block diagram
displays the icon for the current VI− This is the icon that appears when you place the VI on a block
diagram as a subVI
26
F. Block Diagram – SubVI Nodes
• Express VIs are a special type of subVI− Require minimal wiring because you configure them
with dialog boxes− Save the configuration of an Express VI as a subVI
ni.com/training
• Icons for Express VIs appear on the block diagram as icons surrounded by a blue field
27
F. Block Diagram – Icons/Expandable Nodes
ni.com/training28
F. Block Diagram – Wires
• Transfer data between block diagram objects through wires• Wires are different colors, styles, and thicknesses,
depending on their data types• A broken wire appears as a dashed
ni.com/training
ppblack line with a red X in the middle
29
Scalar1D Array2D Array
DBL Numeric Integer Numeric String
F. Block Diagram – Wiring Tips
• Press <Ctrl>-B to delete all broken wires• Right-click and select Clean Up Wire to reroute the wire
ni.com/training30
6
Exercise 2-1: Exploring a VI
ni.com/training
GOAL
Concept ExerciseIdentify the parts of an existing VI.
G. Searching for Controls, VIs & Functions
Find controls, functions, and VIs using the Search button on the Controls and Functions palette.
ni.com/training32
Exercise 2-2: Navigating Palettes
ni.com/training
GOAL
Concept ExerciseLearn to use the palettes and search for controls, functions and VIs.
H. Selecting A Tool
• Create, modify, and debug VIs using the tools provided by LabVIEW
• A tool is a special operating mode of the mouse cursor
ni.com/training
• The operating mode of the cursor corresponds to the icon of the tool selected
• When using the Automatic Tool Selection, LabVIEW chooses which tool to select based on the current location of the mouse
34
Exercise 2-3: Selecting A Tool
ni.com/training
GOAL
Concept ExerciseGain experience using the Automatic Tool Selection to select which tool to use.
I. Dataflow
LabVIEW follows a dataflow model for running VIs• A node executes only when data are available at all of its
input terminals• A node supplies data to the output terminals only when the
ni.com/training
pp p ynode finishes execution
36
7
I. Dataflow – Quiz
Which node executes first? a) Addb) Subtractc) Random Numberd) Di id
ni.com/training
d) Divide e) Sine
37
I. Dataflow – Quiz Answers
NO CORRECT ANSWER
Which node executes first? a) Add – possiblyb) S bt t d fi it l t
ni.com/training
b) Subtract – definitely notc) Random Number – possiblyd) Divide – possiblye) Sine – definitely not
38
Exercise 2-4: Dataflow
ni.com/training
GOAL
Concept ExerciseUnderstand how dataflow determines the execution order in a VI.
J. Building a Simple VI
ni.com/training40
J. Building a Simple VI – Acquire
Acquire Express VIs:
• DAQ Assistant Express VI
• Instrument I/O Assistant Express VI
ni.com/training
Instrument I/O Assistant Express VI
• Simulate Signal Express VI
• Read from Measurement File Express VI
41
J. Building a Simple VI – Analyze
Analyze Express VIs:
• Amplitude and Level Measurements Express VI
• Statistics Express VI
ni.com/training
• Spectral Measurements Express VI
• Tone Measurements Express VI
• Filter Express VI
42
8
J. Building a Simple VI – Present
• Present tasks are Express VIs that perform a function or indicators that present data on the front panel of the VI
• Indicators include the Waveform Chart, the Waveform Graph, and the XY Graph
ni.com/training
• Express VIs include the Write to Measurement File Express VI, Build Text Express VI, DAQ Assistant Express VI, and the Instrument I/O Assistant Express VI
43
J. Building A Simple VI – Running
1. Place Express VI on the block diagram2. Configure the dialog box that opens3. Wire Express VIs together4. Save and run the VI
ni.com/training
4. Save and run the VI
The Run button appears broken when the VI you are creating or editing contains errors
44
Demonstration
DAQ Signal Accessory
ni.com/training
GOAL
Demonstrate the different aspects of the DAQ Signal Accessory.
Exercise 2-5: Simple Acquire, Analyze, and Present VI
ni.com/training
GOAL
Create a simple VI that acquires data, analyzes data, and presents the results.
Summary—Quiz
1. Which function executes first: Add or Subtract?a) Addb) Subtractc) Unknown
ni.com/training
c) Unknown2. Which function executes first:
Sine or Divide?a) Sineb) Dividec) Unknown
47
Summary—Quiz Answers
1. Which function executes first: Add or Subtract?a) Addb) Subtractc) Unknown
ni.com/training
c) Unknown2. Which function executes first:
Sine or Divide?a) Sineb) Dividec) Unknown
48
9
Summary—Quiz
3. Which of the following functions executes first?a) Random Numberb) Dividec) Add
ni.com/training
c) Addd) Unknown
4. Which of the following functions execute last?a) Random Numberb) Subtractc) Addd) Unknown
49
Summary—Quiz Answers
3. Which of the following functions executes first?a) Random Numberb) Dividec) Add
ni.com/training
c) Addd) Unknown
4. Which of the following functions execute last?a) Random Numberb) Subtractc) Addd) Unknown
50
Summary—Quiz
5. What are the three parts of a VI?a) Front Panelb) Block Diagramc) Project
ni.com/training
c) Projectd) Icon/Connector Pane
51
Summary—Quiz Answer
5. What are the three parts of a VI?a) Front Panelb) Block Diagramc) Project
ni.com/training
c) Projectd) Icon/Connector Pane
52
1
TOPICS
Lesson 3Troubleshooting and Debugging VIs
ni.com/training
A. LabVIEW Help UtilitiesB. Correcting Broken VIsC. Debugging TechniquesD. Undefined or Unexpected DataE. Error Checking and Error Handling
A. LabVIEW Help Utilities – Context Help
• Displays basic information about LabVIEW objects when you move the cursor over each object
• Select Help»Show Context Help, press
ni.com/training
<Ctrl-H> or click the Show Context Help Window button on the toolbar
2
A. LabVIEW Help Utilities – LabVIEW Help
• Detailed descriptions of most palettes, menus, tools, VIs, and functions and instructions for using LabVIEW features
• Accessing the LabVIEW Help: − Select Help»Search the LabVIEW Help
ni.com/training
− Use the Detailed helplink or button in the Context Help window
− Right-click an object and select Help from the shortcut menu
3
A. LabVIEW Help Utilities – NI Example Finder
ni.com/training4
Exercise 3-1: Using Help
ni.com/training
GOAL
Concept ExerciseBecome familiar with using the Context Help window, the LabVIEW Help, and the NI Example Finder.
5
B. Correcting Broken VIs
ni.com/training6
2
B. Correcting Broken VIs
Common Issues• Broken wire − You wired a Boolean control
to a String indicator
ni.com/training
− You wired a Numeric control to a Numeric control
• A required block diagram terminal is unwired• A subVI is broken or you edited its connector pane after
you placed its icon on the block diagram of the VI
7
C. Debugging Techniques
Your VI isn’t broken, but you are getting unexpected data or behavior• Any unwired or hidden subVIs?• Incorrect default data being used?
ni.com/training
g• Undefined data being passed?• Numeric representation correct?• Node execution order correct?
8
C. Debugging Techniques –Execution Highlighting• Use execution highlighting to watch the data flow through
the block diagram• If the VI runs more slowly than expected, confirm that you
turned off execution highlighting in subVIs
ni.com/training9
C. Debugging Techniques – Single Stepping
Single-step through the VI to view each action of the VI on the block diagramSuspend the execution of a subVI to edit values of controls and indicators, to control the number of times it runs, or to go
ni.com/training
back to the beginning of the execution of the subVI• Open subVI and select Operate»Suspend When Called
from the shortcut menu
10
C. Debugging Techniques – Probes
• Use the Probe tool to observe intermediate data values and to check the error output of VIs and functions, especially those performing I/O
• Retain the values in the wires so that you can
ni.com/training
probe wires for data after execution has finished
11
C. Debugging Techniques – Breakpoints
• When you reach a breakpoint during execution, the VI pauses and the Pause button appears red
• You can take the following actions at a breakpoint:− Single-step through execution using the single-stepping
ni.com/training
buttons− Probe wires to check intermediate values− Change values of front panel controls − Click the Pause button to continue running to the next
breakpoint or until the VI finishes running
12
3
D. Undefined or Unexpected Data
• ∞ (Inf)− Infinity− Divided a number by zero?
• NaN
ni.com/training
− Not a number− Produced by invalid operations, such as taking the square
root of a negative number• Check for unexpected Inf values or NaN values in your
mathematical operations
13
E. Error Checking and Error Handling
• No matter how confident you are in the VI you create, you cannot predict every problem a user can encounter
• Without a mechanism to check for errors, you know only that the VI does not work properly
ni.com/training
• Error checking tells you why and where errors occur− Automatic error handling− Manual error handling
14
E. Error Checking and Error Handling –Automatic Error Handling• LabVIEW automatically handles any known error when a VI
runs by: − suspending execution,− highlighting the subVI or function where the error occurred,
ni.com/training
− and displaying the Error dialog box• Select File»VI Properties and select Execution from the
Category pull-down menu to disable automatic error handling for a specific VI
15
E. Error Checking and Error Handling –Manual Error Handling• To disable automatic error handling for a subVI or function,
wire its error out cluster to the error in cluster of another subVI or function or to an error out indicator
• Use the LabVIEW error handling VIs,
ni.com/training
functions, and parameters to manage errors
16
E. Error Checking and Error Handling –Error Clusters• Use the error cluster controls and indicators to create error
inputs and outputs in subVIs• The error in and error out clusters include the following
components of information:
ni.com/training
− Status − Code − Source
17
Exercise 3-2: Debugging
ni.com/training
GOAL
Concept ExerciseUse the debugging tools built into LabVIEW.
18
4
Summary—Quiz
1. How do you disable automatic error handling?a) Select Operate»Disable Error Handlingb) Enable execution highlightingc) Wire the error out cluster of a subVI to the error in
ni.com/training
c) Wire the error out cluster of a subVI to the error in cluster of another subVI
d) Place a checkmark in the Show Warnings checkbox of the Error List dialog box
19
Summary—Quiz Answer
1. How do you disable automatic error handling?a) Select Operate»Disable Error Handlingb) Enable execution highlightingc) Wire the error out cluster of a subVI to the error in
ni.com/training
c) Wire the error out cluster of a subVI to the error in cluster of another subVI
d) Place a checkmark in the Show Warnings checkbox of the Error List dialog box
20
Summary—Quiz
2. Which of the following are the contents of the error cluster? a) Status: Booleanb) Error: String
ni.com/training
) gc) Code: 32-bit integerd) Source: String
21
Summary—Quiz Answer
2. Which of the following are the contents of the error cluster? a) Status: Booleanb) Error: String
ni.com/training
) gc) Code: 32-bit integerd) Source: String
22
1
TOPICS
Lesson 4Implementing a VI
ni.com/training
A. Front Panel DesignB. LabVIEW Data TypesC. Documenting CodeD. While LoopsE. For LoopsF. Timing A VI
G. Iterative Data TransferH. Plotting DataI. Case Structures
A. Front Panel Design
• Inputs and outputs lead to front panel design• Retrieve the inputs by the following methods:− Acquiring from a device− Reading directly from a file
ni.com/training
g y− Manipulating controls
• Output data by the following methods:− Displaying with indicators− Logging to a file− Outputting to a device
A. Front Panel Design – Labels/Captions
• Labels – short descriptions• Captions – long descriptions• Captions do not appear on block diagram
ni.com/training
A. Front Panel Design – Color Tips
Start with a gray scheme• Select one or two shades of gray• Add highlight colors sparingly for important settings—on
plots, abort buttons, and the slider thumbs
ni.com/training
A. Front Panel Design – Spacing
ni.com/training
A. Front Panel Design – Text & Fonts Bad Example
ni.com/training
2
A. Front Panel Design – Tab ControlsUse tab controls to overlap front panel controls and indicators in a smaller area
ni.com/training
A. Front Panel Design – Decorations• Use decorations to visually
group or separate objects on a front panel with boxes, lines, or arrows
ni.com/training
• These objects are for decoration only
B. LabVIEW Data Types – Terminals
Terminals visually communicate information about the data type represented
ni.com/training
B. LabVIEW Data Types – Numerics
• The numeric data type represents numbers of various types
• To change the representation of a numeric, right-click the
ni.com/training
control, indicator, or constant, and select Representationfrom the shortcut menu
B. LabVIEW Data Types – Boolean
• Behavior of Boolean controls is specified by the mechanical action
• In LabVIEW, the Boolean data type is represented
ni.com/training
with the color green
Demonstration
Mechanical Action of Booleans
ni.com/training
GOAL
Use the Mechanical Action of Booleans VI located in the NI Example Finder to learn about the different switch and latch actions.
3
B. Data Types – String
• A sequence of displayable or non-displayable ASCII characters
• On the front panel, strings appear as tables, text entry boxes, and labels
ni.com/training
• Change the display type from the short-cut menu: Normal, ‘\’ Codes, Password and Hex
• Edit and manipulate strings with the String functions on the block diagram
• In LabVIEW, the string data type is represented with the color pink
B. Data Types – Enum
An enum represents a pair of values, a string and a n meric here the
ni.com/training
numeric, where the enum can be one of a defined list of values
B. Data Types – Enum
• Enum: enumerated control, constant, or indicator
• Enums are useful because it is easier
ni.com/training
to manipulate numbers than strings on the block diagram
B. Data Types – Dynamic
• Stores the information generated or acquired by an Express VI
• Non-Express VIs do not accept the dynamic data type− To use a built-in VI or function to analyze or process the
ni.com/training
dynamic data type, you must convert the data type− Numeric, waveform, or Boolean data indicators or inputs
automatically convert the dynamic data type when wired• In LabVIEW, the dynamic data type is represented with the
color dark blue
C. Documenting Code – Front Panels
• Tip Strips• Descriptions• VI Properties• Good Design
ni.com/training
Good Design
C. Documenting Code – Naming
Giving controls and indicators logical and descriptive names adds usability to front panels
ni.com/training
4
C. Documenting Code – Block Diagram
• Use block diagram comments to:− Describe algorithms− Explain the data contents of wires
• Use the Labeling tool or place a
ni.com/training
g pfree label from the Functionspalette
Exercise 4-1: Determine Warnings VI
ni.com/training
GOAL
Create and document a VI.
D. While Loops
Repeat (code);
Until Condition met;
ni.com/training
LabVIEW While Loop Flowchart Pseudo Code
End;
D. While Loops
• Iteration terminal: returns number of times loop has executed; zero indexed
• Conditional terminal: defines when the loop stops
ni.com/training
Iteration Terminal Conditional Terminal
D. While Loops – Tunnels
• Tunnels transfer data into and out of structures• The tunnel adopts the color of the data type wired to the
tunnel• Data pass out of a loop after the loop terminates
ni.com/training
p p p• When a tunnel
passes data into a loop, the loop executes only after data arrive at the tunnel
D. While Loops - Error Checking and Error Handling Use an error cluster in a While Loop to stop the While Loop if an error occurs
ni.com/training
5
Exercise 4-2: Auto Match VI
ni.com/training
GOAL
Use a While Loop and an iteration terminal and pass data through a tunnel.
E. For Loops
N=100;
i=0;
Until i=N:
ni.com/training
LabVIEW For Loop Flowchart Pseudo Code
Repeat (code;i=i+1);
End;
E. For Loops
• Create a For Loop the same way you create a While Loop• If you need to replace an existing While Loop with a For
Loop, right-click the border of the While Loop, and select Replace with For Loop from the shortcut menu
ni.com/training
• The value in the count terminal (an input terminal) indicates how many times to repeat the subdiagram
E. For Loops – Conditional Terminal
You can add a conditional terminal to configure a For Loop to stop when a Boolean condition or an error occurs
ni.com/training
E. For Loops – Conditional Terminal
For Loops configured for a conditional exit have:• Red glyph next to the count terminal • Conditional terminal in the lower right corner
ni.com/training
E. For Loop/While Loop Comparison
For Loop While Loop
ni.com/training
• Executes a set number of times unless a conditional terminal is added
• Can execute zero times• Tunnels automatically output an array
of data
• Stops executing only if the value at the conditional terminal meets the condition
• Must execute at least once• Tunnels automatically output the last
value
6
E. For Loops – Numeric Conversion
• If you wire a double-precision, floating-point numeric value to the count terminal, LabVIEW converts the larger numeric value to a 32-bit signed integer
• A For Loop can only execute an integer number of times
ni.com/training
E. For Loops – Numeric Conversion
• Normally, when you wire different representation types to the inputs of a function, the function returns an output in the larger or wider format Coercion Dot
ni.com/training
• LabVIEW chooses the representation that uses more bits
Exercise 4-3: While Loops vs For Loops
ni.com/training
GOAL
Concept ExerciseUnderstand when to use a While Loop and when to use a For Loop.
F. Timing a VI
Why do you need timing in a VI?• Control the frequency at which a loop executes• Provide the processor with time to complete other tasks,
such as processing the user interface
ni.com/training
g
F. Timing a VI – Wait Functions
• A wait function inside a loop allows the VI to sleep for a set amount of time
• Allows the processor to address other tasks during the wait time
ni.com/training
• Uses the operating system millisecond clock
F. Timing a VI – Elapsed Time Express VI
• Determines how much time elapses after some point in your VI
• Keep track of time while the VI continues to execute• Does not provide the processor with
ni.com/training
p ptime to complete other tasks
7
Demonstration
Wait Chart VI
ni.com/training
GOAL
Compare and contrast using a Wait function and the Elapsed Time Express VI for software timing.
G. Iterative Data Transfer
• When programming with loops, you often need to know the values of data from previous iterations of the loop
• Shift registers transfer values from one loop iteration to the next
ni.com/training
G. Iterative Data Transfer – Shift Registers
• Right-click the border and select Add Shift Register from the shortcut menu
• Right shift register stores data on completion of an iteration• Left shift register provides stored data at beginning of the
ni.com/training
g g gnext iteration
Block Diagram 1st run 2nd runInitializedShiftRegister
Output = 5 Output = 5
G. Iterative Data Transfer – InitializingVI finishes Run againRun once
ni.com/training
g
Not InitializedShiftRegister
Output = 4 Output = 8
G. Iterative Data Transfer –Stacked Shift Registers• Stacked shift registers remember values from multiple
previous iterations and carry those values to the next iterations
• Right-click the left shift register and select Add Element
ni.com/training
from the shortcut menu
Exercise 4-4: Average Temperature VI
ni.com/training
GOAL
Use a For Loop and shift registers to average data.
8
H. Plotting Data – Waveform Chart
• Special type of numeric indicator that displays one or more plots of data, typically acquired at a constant rate
• Displays single or multiple plots
ni.com/training
H. Plotting Data – Chart Update Modes
• Right-click the chart and select Advanced»Update Mode from the shortcut menu
• Strip chart is the default update mode• Scope chart and Sweep chart modes display plots
ni.com/training
p p p y psignificantly faster than the strip chart mode
H. Plotting Data
ni.com/training
H. Plotting Data – Waveform Graphs
Use the Context Help window to determine how to wire multi-plot data to Waveform Graphs and XY Graphs
ni.com/training
Exercise 4-5: Temperature Multiplot VI
ni.com/training
GOAL
Plot multiple data sets on a single waveform chart and customize the chart view.
I. Case Structures• Have two or more subdiagrams or cases• Execute and displays only one case at a time• An input value determines which subdiagram to execute• Similar to case statements or if...then...else
t t t i t t b d i l
ni.com/training
statements in text-based programming languages
9
I. Case Structures
• Case Selector Label: contains the name of the current case and decrement and increment buttons on each side
ni.com/training
• Selector Terminal: Wire an input value, or selector, to determine which case executes
I. Case Structures – Default Case
• You can specify a default case for the Case structure− If you specified cases for 1, 2,
and 3, but you get an input of 4 th C t t t
ni.com/training
4, the Case structure executes the default case
• Right-click the Case structure border to add, duplicate, remove, or rearrange cases and to select a default case
I. Case Structures – Input & Output Tunnels
You can create multiple input and output tunnels• Inputs are available to all cases if needed• You must define each output tunnel for each case
ni.com/training
I. Case Structures – Use Default if Unwired
Default values are: Data Type Default Value
Numeric 0
Boolean FALSE
String Empty
ni.com/training
Avoid using the Use Default If Unwired option on Case structure tunnels• Adds a level of complexity to your code• Complicates debugging your code
String Empty
I. Case Structures – Boolean
Boolean input creates two cases: True and False
ni.com/training
I. Case Structures – Integer
• Add a case for each integer as necessary• Integers without a defined case use the default case
ni.com/training
10
I. Case Structures – String
• Add a case for each string as necessary• Strings without a defined case use the default case
ni.com/training
I. Case Structures – Enum
• Gives users a list of items from which to select• The case selector displays a case for each item in the
enumerated type control
ni.com/training
I. Case Structures - Error Checking and Error Handling Use Case Structures inside VIs to execute the code if there is no error and skip the code if there is an error
ni.com/training
Exercise 4-6: Determine Warnings VI
ni.com/training
GOAL
Modify a VI to use a Case structure to make a software decision.
Summary—Quiz
1.Which identifies the control or indicator on the block diagram?a) Captionb) Location
ni.com/training
)c) Labeld) Value
Summary—Quiz Answer
1.Which identifies the control or indicator on the block diagram?a) Captionb) Location
ni.com/training
)c) Labeld) Value
11
Summary—Quiz
2. Which structure must run at least one time?a) While Loopb) For Loop
ni.com/training
Summary—Quiz Answer
2. Which structure must run at least one time?a) While Loopb) For Loop
ni.com/training
Summary—Quiz
3. Which is only available on the block diagram?a) Controlb) Constantc) Indicator
ni.com/training
)d) Connector Pane
Summary—Quiz Answer
3. Which is only available on the block diagram?a) Controlb) Constantc) Indicator
ni.com/training
)d) Connector Pane
Summary—Quiz
4. Which mechanical action causes a Boolean in the False state to change to True when you click it and stay True until you release it and LabVIEW has read the value?a) Switch Until Released
ni.com/training
b) Switch When Releasedc) Latch Until Releasedd) Latch When Released
Summary—Quiz Answer
4. Which mechanical action causes a Boolean in the False state to change to True when you click it and stay True until you release it and LabVIEW has read the value?a) Switch Until Released
ni.com/training
b) Switch When Releasedc) Latch Until Releasedd) Latch When Released
1
TOPICS
Lesson 5Relating Data
ni.com/training
A. ArraysB. ClustersC. Type Definitions
A. Arrays
• An array consists of elements and dimensions− Elements: data that make up the array− Dimension: the length, height, or depth of an array− An array can have one or more dimensions
ni.com/training
and as many as (231)–1 elements per dimension, memory permitting
• Consider using arrays when you work with a collection of similar data and when you perform repetitive computations
2
A. Arrays
• The first element shown in the array (3.00) is at index 1 and the second element (1.00) is at index 2
• The element at index 0 is not shown in this image, because element 1 is selected in the index display
ni.com/training
• The element selected in the index display always refers to the element shown in the upper left corner of the element display
3
A. Arrays – Creating
1. Place an array shell on the front panel2. Drag a data object or element into the array shell
ni.com/training4
A. Arrays – 2D Array
• Stores elements in a grid• Requires a column index and a row index to locate an
element, both of which are zero-based• To create a multidimensional array on the front panel, right-
ni.com/training
y p gclick the index display and select Add Dimension from the shortcut menu
• You also can resize the index display until you have as many dimensions as you want
5
A. Arrays – Initializing
• 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
ni.com/training
y
6
2
A. Arrays – Creating Constants
• To create an array constant: − Select an array constant on the
Functions palette − Place the array shell on the block diagram
ni.com/training
− Place a constant in the array shell• You can use an array constant to store
constant data or as a basis for comparison with another array
• Array constants also are useful for passing data into a subVI
7
A. Arrays – Auto-indexing
• If you wire an array to or from a For Loop or While Loop, you can link each iteration of the loop to an element in that array by enabling auto-indexing on tunnel
• The tunnel changes from a solid square to the image
ni.com/training
shown above to indicate auto-indexing
8
A. Arrays – Auto-indexing Input
For Loop executes a number of times equal to the number of elements in the array
ni.com/training9
A. Arrays – Auto-indexing Output
• When you auto-index an array output tunnel, the output array receives a new element from every iteration of the loop
• Auto-indexed output arrays are always equal in size to the
ni.com/training
number of iterations
10
A. Arrays – Creating 2D Arrays
You can use two For Loops, one inside the other, to create a 2D array
ni.com/training11
Exercise 5-1: Manipulating Arrays
ni.com/training
GOAL
Concept ExerciseManipulate arrays using various LabVIEW functions.
12
3
B. Clusters
• Clusters group data elements of mixed types• Similar to a record or a struct in text-based programming
languages
ni.com/training13
B. Clusters – Array vs Cluster
• Clusters differ from arrays in that they are a fixed size• Clusters can contain mixed data types; arrays contain only
one data type• Like an array, a cluster is either a control or an indicator
ni.com/training
yand cannot contain a mixture of controls and indicators
14
B. Clusters – Creating
To create a cluster control or indicator on the front panel:• Place a cluster shell on the front panel• Drag a data object or element,
which can be a numeric, Boolean,
ni.com/training
string, path, refnum, array, or cluster control or indicator into the cluster shell
15
B. Clusters – Constants
• To create a cluster constant:1. Select a cluster constant on the Functions palette2. Place the cluster shell on the block diagram3. Place a constant in the cluster shell
ni.com/training
• If you have a cluster control or indicator, right-click the cluster on the block diagram and select Create»Constantfrom the shortcut menu
16
B. Clusters – 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
ni.com/training
the cluster border and selecting Reorder Controls In Cluster from the shortcut menu
17
B. Clusters – Assembling a Cluster
Use the Bundle function to assemble a new cluster
ni.com/training18
4
B. Clusters – Modifying a Cluster
Use the Bundle By Name or the Bundle function to modify an existing cluster
ni.com/training19
B. Clusters – Disassembling a Cluster
Use the Unbundle By Name or Unbundle function to use individual items in a cluster
ni.com/training20
B. Clusters – 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
ni.com/training
g g− source: String that identifies where the error occurred
21
Exercise 5-2: Clusters
ni.com/training
GOAL
Concept ExerciseCreate clusters on the front panel, reorder clusters, and use the cluster functions to assemble and disassemble clusters.
22
C. Type Definitions – Custom Controls
Use custom controls and indicators to extend the available set of front panel objects1. Create and save a
custom control
ni.com/training
or indicator2. Use the custom control
or indicator on other front panels
23
C. Type Definitions – Control Editor
• Use the Control Editor window to customize controls and indicators
• To display the Control Editor window, right-click a control
ni.com/training
or indicator and select Advanced»Customize
24
5
C. Type Definitions
You can save a custom control as: • Control• Type Definition• Strict Type Definition
ni.com/training
Strict Type Definition
25
C. Type Definitions – Control Type
Control• No connection between the custom control or indicator you
saved and the instance of the custom control or indicator in the VI
ni.com/training
• Update the file, but the instances are not updated
26
C. Type Definitions – Type Definition
Type Definition (type def): • Edit the saved file, and have all instances update with the
changes made• Forces the data type of each instance to be identical
ni.com/training
yp• Example:− Add an item to the type definition of an
enum, the instances of the enum update with the new item
− If you resize the enum front panel control type definition, the instances of the enum do not resize
27
C. Type Definitions – Strict Type Definition
Strict Type Definition: • Similar to a type definition, except a strict type definition
forces everything about an instance to be identical to the strict type definition, except:
ni.com/training
− label − description− default value
28
Exercise 5-3: Type Definition
ni.com/training
GOAL
Create a type defined enumerated control and explore the differences between a type definition and a strict type definition.
29
Summary—Quiz
1. You can create an array of arrays. True or False?
ni.com/training30
6
Summary—Quiz Answer
1. You can create an array of arrays. False.
ni.com/training31
Summary—Quiz
2. What is the value of the Iterations indicator after running this VI?
ni.com/training32
Summary—Quiz Answer
2. What is the value of the Iterations indicator after running this VI? Value of Iterations = 4
ni.com/training33
Summary—Quiz
3. You customize a control, select Control from the Type Def. Status pull-down menu, and save the control as a .ctl file. You then use an instance of the custom control on your front panel. If you open the .ctl file and modif the control does the control on the front
ni.com/training
and modify the control, does the control on the front panel change?
34
Summary—Quiz Answer
3. You customize a control, select Control from the Type Def. Status pull-down menu, and save the control as a .ctl file. You then use an instance of the custom control on your front panel. If you open the .ctl file and modif the control does the control on the front
ni.com/training
and modify the control, does the control on the front panel change? No.
35
Summary—Quiz
4. You are inputting data that represents a circle. The circle data includes three double precision numerics: x position, y position and radius. In the future, you might need to expand all instances of the circle data to include the color of the circle, represented as an integer. How should you represent the circle on your front
ni.com/training
panel?a) Three separate controls for the two positions and the radiusb) A cluster containing all of the datac) A custom control containing a clusterd) A type definition containing a clustere) An array with three elements
36
7
Summary—Quiz Answer
4. You are inputting data that represents a circle. The circle data includes three double precision numerics: x position, y position and radius. In the future, you might need to expand all instances of the circle data to include the color of the circle, represented as an integer. How should you represent the circle on your front
ni.com/training
panel?a) Three separate controls for the two positions and the radiusb) A cluster containing all of the datac) A custom control containing a clusterd) A type definition containing a clustere) An array with three elements
37
1
TOPICS
Lesson 6Storing Measurement Data
ni.com/training
A. Understanding File I/OB. Understanding High-level File I/OC. Understanding Low-level File I/O
A. Understanding File I/O
• File I/O writes to or reads from a file• A typical file I/O operation involves the following process:
ni.com/training2
Open/Create/
Replace File
Read and/or
Write to File
Close File
Check forErrors
A. Understanding File I/O – File Formats
LabVIEW can use or create the following file formats:• Binary—Underlying file format of all other file formats• ASCII—Specific type of binary file that is a standard used
by most programs
ni.com/training
y g• LVM— 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—Type of binary file created for NI products consisting of two separate files: a binary file and a binary index file
3
A. Understanding File I/O – File Formats
• In this course, you learn about creating text (ASCII) files• Use text files in the following situations: − You want to access the file from another application− Disk space and file I/O speed are not crucial
ni.com/training
p p− You must not perform random access reads or writes− Numeric precision is not important
4
B. Understanding High-level File I/O
• High-level VIs− Perform all three steps for common
file I/O operations− Might not be as efficient as the
f ti fi d d i d f
ni.com/training
functions configured or designed for individual operations
• Low-level VIs− Individual VI for each step− If you are writing to a file in a loop,
use low-level file I/O functions
5
B. Understanding 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 fileRead From Spreadsheet File
ni.com/training
• 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
6
2
C. Understanding Low-Level File I/O VIs
ni.com/training7
Exercise 6-1: Spreadsheet Example VI
ni.com/training
GOAL
Use a high-level file I/O VI to write to a spreadsheet-readable file.
8
Exercise 6-2: Temperature Log VI
ni.com/training
GOAL
Modify a VI to create an ASCII file using disk streaming.
9
Summary—Quiz
1. Your continuously running test program logs to a single file the results of all tests that occur in one hour as they are calculated. If you are concerned about the execution speed of your program, should you use low-level or high-level File I/O VIs?a) Low-level file I/O VIs
ni.com/training
b) High-level file I/O VIs
10
Summary—Quiz Answer
1. Your continuously running test program logs to a single file the results of all tests that occur in one hour as they are calculated. If you are concerned about the execution speed of your program, should you use low-level or high-level File I/O VIs?a) Low-level file I/O VIs
ni.com/training
b) High-level file I/O VIs
11
Summary—Quiz
2. If you want to view data in a text editor like Notepad, what file format should you use to save the data?a) ASCIIb) TDMS
ni.com/training12
3
Summary—Quiz Answer
2. If you want to view data in a text editor like Notepad, what file format should you use to save the data?a) ASCIIb) TDMS
ni.com/training13
1
TOPICS
Lesson 7Developing Modular Applications
ni.com/training
A. Understanding ModularityB. Icon and Connector PaneC. Using SubVIs
A. Understanding Modularity
• Modularity defines the degree to which a program is composed of discrete modules such that a change to one module has minimal impact on other modules
• Modules in LabVIEW are called subVIs
ni.com/training2
A. Understanding Modularity – SubVIs
• A VI within another VI is a subVI• SubVIs correspond to subroutines in text-based
programming languages• The upper right corner of the front panel and block diagram
ni.com/training
g gdisplays the icon for the VI
• This icon identifies the VI when you place the VI on the block diagram
3
A. Understanding Modularity – SubVIs
ni.com/training4
A. Understanding Modularity – SubVIs
ni.com/training5
A. Understanding Modularity – SubVIs Function Code Calling Program Code
function average (in1, in2, out){out = (in1 + in2)/2.0;}
main{average (point1, point2, pointavg)}
ni.com/training6
SubVI Block Diagram Calling VI Block Diagram
2
B. Icon and Connector Pane
• After you build a VI, build the icon and the connector pane so you can use the VI as a subVI
• The icon and connector pane correspond to the function prototype in text-based programming languages
ni.com/training
• Every VI displays an icon in the upper-right corner of the front panel and block diagram windows
• 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
7
B. Icon and Connector Pane – Create Icon
• Create custom icons by right-clicking the icon in the upper right corner of the front panel or block diagram and selecting Edit Icon or by double-clicking the icon
• You also can drag a graphic from anywhere in your file
ni.com/training
system and drop it on the icon• Refer to the
Icon Art Glossary at ni.com for standard graphics to use in a VI icon
8
B. Icon and Connector Pane – Setting up the Connector Pane• Right-click the icon in the upper
right corner of the front panel and select Show Connector− Each rectangle on the connector
pane represents a terminal
ni.com/training
− 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
9
B. Icon and Connector Pane – Standards
• Use this connector pane layout as a standard
• Top terminals are usually reserved for references, such as a file reference
ni.com/training
• Bottom terminals are usually reserved for error clusters
10
C. Using SubVIs
• To place a subVI on the block diagram− Click Select a VI on the Functions palette − Navigate to the VI you want to use as a subVI− Double-click to place it on the block diagram
ni.com/training
• To place an open VI on the block diagram of another open VI− Click the icon of the VI you want to use as a subVI− Drag the icon to the block diagram of the other VI
11
C. Using SubVIs – Terminal Setting
• Bold: Required terminal• Plain: Recommended
terminals• Dimmed: Optional terminals
ni.com/training12
3
C. Using SubVIs – Section 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
ni.com/training13
Exercise 7-1: Determine Warnings VI
ni.com/training
GOAL
Create the icon and connector pane for a VI so you can use the VI as a subVI.
14
Summary—Quiz
1. On a subVI, which terminal setting causes an error if the terminal is not wired?a) Requiredb) Recommended
ni.com/training
)c) Optional
15
Summary—Quiz Answer
1. On a subVI, which terminal setting causes an error if the terminal is not wired?a) Requiredb) Recommended
ni.com/training
)c) Optional
16
Summary—Quiz
2. True or False? You must create a custom icon to use a VI as a subVI.
ni.com/training17
Summary—Quiz Answer
2. True or False? You must create a custom icon to use a VI as a subVI. False.
ni.com/training18
1
TOPICS
Lesson 8Data Acquisition
ni.com/training
A. Using Hardware B. Using SoftwareC. Simulating a DAQ deviceD. Measuring Analog Input E. Generating Analog Output
F. Using CountersG. Using Digital I/O
A. Using Hardware
1. Signal2. Terminal Block3. Cable4. DAQ Device
ni.com/training
4. DAQ Device5. Computer
2
A. Using Hardware – Terminal Block & Cable
DAQ Signal Accessory—terminal block used in this course
ni.com/training3
A. Using Hardware – DAQ Device
• Most DAQ devices have four standard elements: analog input, analog output, digital I/O, and counters
• You can transfer the signal you measure with the DAQ device to the computer through a variety of different bus
ni.com/training
structures• If you do not have a DAQ device, you can simulate one in
Measurement and Automation Explorer (MAX) to complete your software testing
4
B. Using Software
• Driver Engines: NI-DAQmx and Traditional NI-DAQ• Configuration: MAX• Application Software: LabVIEW, LabWindows™/CVI™,
and DAQ Assistant
ni.com/training5
B. Using Software – Configuration
ni.com/training6
2
C. Simulating a DAQ Device
• Create NI-DAQmx simulated devices in NI-DAQmx 7.4 or later
• Using NI-DAQmx simulated devices, you can try NI products in your application without the hardware
ni.com/training
• With NI-DAQmx simulated devices, you also can export a physical device configuration onto a system that does not have the physical device installed
7
Exercise 8-1: Measurement and Automation Explorer
ni.com/training
GOAL
Concept ExerciseTo use MAX to examine, configure, and test a device.
8
D. Measuring Analog Input
The process of measuring an analog signal and transferring the measurement to a computer for analysis, display, or storage• An analog signal is a signal that varies continuously
ni.com/training
• Analog input most commonly measures voltage or current
9
D. Measuring Analog Input – ADC
Acquiring an analog signal with a computer requires analog-to-digital conversion, a process that transfers an electrical signal into digital data so that a computer can process the data
ni.com/training10
D. Measuring Analog Input – Task Timing
• Acquire 1 Sample− On-demand operation
• Acquire n Samples− Uses hardware timing and a buffer in computer memory to
ni.com/training
g p yacquire data more efficiently at a consistent Δt
• Acquire Continuously− Uses hardware timing and a buffer in computer memory to
acquire data− Each read operation extracts a subset of the buffer− Stopped manually
11
D. Measuring Analog Input –Task Triggering
• When a device controlled by NI-DAQmx does something, it performs an action
• Two very common actions are producing a sample and starting a waveform acquisition
ni.com/training
a sample and starting a waveform acquisition• Every NI-DAQmx action needs a stimulus or cause• Causes for actions are called triggers− The start trigger starts the acquisition− The reference trigger establishes the reference point in a set
of input samples
12
3
Exercise 8-2: Triggered Analog Input VI
ni.com/training
GOAL
Acquire an analog signal using a DAQ device and a digital trigger.
13
E. Generating Analog Output
• The process of generating analog signals from your computer
• Performing digital-to-analog (D/A) conversions generates analog output
ni.com/training
• The available analog output types for a task are voltage and current
• To perform a voltage or current task, a compatible device must be installed that can generate that type of signal
14
E. Generating Analog Output – DAC
• The opposite of analog-to-digital conversion• A digital-to-analog converter (DAC) accepts data and uses
it to vary the voltage on an output pin over time• When used with a high speed clock, the DAC can create a
ni.com/training
gsignal that appears to vary constantly and smoothly
15
E. Generating Analog Output – Task Timing
Generate 1 Sample• Use single updates if the signal level is more important
than the generation rate (constant, DC signal)• Use software timing to control when the device generates a
ni.com/training
g gsignal
16
E. Generating Analog Output – Task Timing
• Generate n Samples− Generate multiple samples for one or more channels by
generating single samples repetitively using hardware timing− Use Generate n Samples if you want to generate a finite
ti i i l
ni.com/training
time-varying signal• Generate Continuously− Similar to Generate n Samples,
except that an event must occur to stop the generation
17
F. Using Counters
• A counter is a digital timing device typically used for event counting, frequency measurement, period measurement, position measurement, and pulse generation
• A counter has a fixed number it can count to as determined
ni.com/training
by the resolution of the counter• For example, a 24-bit counter
can count to:2(Counter Resolution) – 1 = 224 – 1 = 16,777,215
18
4
Exercise 8-3: Count Events VI
ni.com/training
GOAL
Use the DAQ Assistant to input a counter value.
19
G. Using Digital I/O
• Digital signals: − Electrical signals that transfer digital data (on/off, high/low,
1/0) using a wire− Used to control or measure digital or finite state devices, such
it h d LED
ni.com/training
as switches and LEDs− Used to transfer data
• program devices• communicate between devices
− Use digital signals as clocks or triggers to control or synchronize other measurements
20
G. Using Digital I/O
• Digital Lines− Use digital lines in a DAQ device to acquire a digital value− On some devices, you can configure the lines individually to
either measure or generate digital samples
ni.com/training
• Digital Ports− Use the digital port(s) in a DAQ device to acquire a digital
value from a collection of digital lines− You can configure the ports individually to either measure or
generate digital samples
21
Exercise 8-4: Digital Count VI
ni.com/training
GOAL
OPTIONALUse the DAQ Assistant for digital I/O.
22
Summary—Quiz
1. You are reading a signal at 50kHz. You want to acquire the signal until the user clicks a stop button. Which task timing should you use?a) 1 Sampleb) N Samples
ni.com/training
) pc) Continuous
23
Summary—Quiz Answer
1. You are reading a signal at 50kHz. You want to acquire the signal until the user clicks a stop button. Which task timing should you use?a) 1 Sampleb) N Samples
ni.com/training
) pc) Continuous
24
5
Summary—Quiz
2. Your VI monitors a factory floor. Part of the VI controls an LED which alerts users to the status of the system. Which task timing should you use?a) 1 Sampleb) N Samples
ni.com/training
) pc) Continuous
25
Summary—Quiz Answer
2. Your VI monitors a factory floor. Part of the VI controls an LED which alerts users to the status of the system. Which task timing should you use?a) 1 Sampleb) N Samples
ni.com/training
) pc) Continuous
26
1
TOPICS
Lesson 9Instrument Control
ni.com/training
A. IntroductionB. GPIBC. SerialD. Using Other InterfacesE. Software Architecture
F. Instrument I/O AssistantG. VISAH. Instrument Drivers
A. Introduction to Instrument Control
• When you use a PC to automate a test system, you are not limited to the type of instrument you can control
• You can mix and match instruments from various categories
ni.com/training
• The most common categories are GPIB, serial, modular instruments, and PXI modular instruments
• You must understand properties of the instrument, such as the communication protocols to use
2
B. GPIBGPIB (general purpose interface bus) is a standard interface for communication between instruments and controllers from various vendors
ni.com/training3
B. GPIB
• The bus supports one system controller, usually a computer, and up to 14 additional instruments
• Controller: − Defines the communication links
ni.com/training
− Responds to devices that request service− Sends GPIB commands− Passes/receives control of the bus
4
B. GPIB – Data Transfer Termination
• Informs listeners that all data has been transferred
• Terminate the following ways:− Assert the End Or Identify (EOI)
hardware line with the last data
ni.com/training
byte - preferred method− Place a specific end-of-string (EOS)
character at end of data− Allow the listener count the bytes
transferred by handshaking and stop reading when the listener reaches a byte count limit
5
B. GPIB – Data Transfer Rate
• To achieve the high data transfer rate that the GPIB was designed for: − Limit the number of devices on the bus− Limit the physical distance between devices
ni.com/training
• You can obtain faster data rates with HS488 devices and controllers
6
2
C. Serial
Serial communication• Transmits data between a computer and a peripheral
device, such as a programmable instrument or another computer
ni.com/training
• Uses a transmitter to send data one bit at a time over a single communication line to a receiver
• Best method when data transfer rates are low, or you must transfer data over long distances
• Most computers have one or more serial ports, so you do not need any extra hardware other than a cable
7
C. Serial
A character frame packages each transmitted character as a single start bit followed by the data bits
ni.com/training8
C. Serial – RS-232 Standard
• Used historically for connecting a mouse, printer, or modem• Used for industrial instrumentation• Limited to point-to-point connections between PC serial ports
and devices
ni.com/training9
C. Serial – RS-422 Standard
• Uses a differential electrical signal as opposed to the unbalanced (single-ended) signals referenced to ground with RS-232
• Differential transmission, which uses two lines each to
ni.com/training
transmit and receive signals, results in greater noise immunity and longer transmission distances as compared to RS-232
10
C. Serial – RS-485 Standard
• Variation of RS-422 • Allows you to connect up to 32 devices to a single port and
define the necessary electrical characteristics to ensure adequate signal voltages under maximum load
ni.com/training
• Can create networks of devices connected to a single RS-485 serial port
• Good choice in industrial applications that require many distributed devices networked to a controller
11
D. Using Other Interfaces
• Several devices communicate with serial or GPIB instruments through the Ethernet, USB, or IEEE 1394 (FireWire®) ports and bypass the need for a serial port or GPIB board on your computer
ni.com/training
• When using these devices, program them just as you would if they were using the serial port or a GPIB board
12
3
E. Software Architecture
• Interface Drivers: Instrument interfaces such as GPIB include a set of drivers for the interface
• Configuration: Use MAX to configure the interface• Application: VISA is a common API to communicate with
ni.com/training
ppthe interface drivers and is the preferred method used when programming for instrument control in LabVIEW
• Instrument Drivers: An instrument driver is a set of VIs specially written to communicate with an instrument
13
Exercise 9-1: GPIB Configuration with MAX
ni.com/training
GOAL
Concept ExerciseLearn to configure the NI Instrument Simulator and use MAX to examine the GPIB interface settings, detect instruments, and communicate with an instrument.
14
F. Instrument I/O Assistant
ni.com/training15
Demonstration
Instrument I/O Assistant
ni.com/training
GOAL
Configure the Instrument I/O Assistant.
16
Exercise 9-2: Instrument I/O Assistant
ni.com/training
GOAL
Concept ExerciseConfigure a serial or GPIB instrument and communicate with the instrument using the Instrument I/O Assistant.
17
G. VISA
• Virtual Instrument Software Architecture (VISA): − Lower layer of functions in the LabVIEW instrument driver VIs
that communicate with the driver software− High-level API that calls low-level drivers
ni.com/training
− Can control VXI, GPIB, serial, or computer-based instruments and makes the appropriate driver calls depending on the type of instrument used
• If you choose not to use the Instrument I/O Assistant to automatically generate code for you, you can use VISA functions instead to communicate with the instrument
18
4
G. VISA – Programming Terminology
• ResourceAny instrument in the system, including serial and parallel ports
• Session When you open a session to a resource, LabVIEW returns a VISA
ni.com/training
session number, which is a unique refnum to that instrument• Instrument Descriptor
Specifies the interface type (GPIB,VXI, ASRL), the address of the device, and the VISA session type (INSTR or Event)
19
G. VISA – Serial
The VISA Configure Serial Port VI initializes the port identified by VISA resource name to the specified settings
ni.com/training20
Exercise 9-3: VISA Write and Read VI
ni.com/training
GOAL
Concept ExerciseCommunicate with a serial or GPIB interface to an instrument using VISA functions.
21
H. Instrument Drivers
• When you use an instrument driver, the driver contains the code specific to the instrument
• If you change instruments, replace the instrument driver VIs with the instrument driver VIs for the new instrument,
ni.com/training
which greatly reduces your redevelopment time
22
H. Instrument Drivers – What Are They?
• A LabVIEW Plug and Play instrument driver is a set of VIs that control a programmable instrument
• Each VI corresponds to an instrument operation, such as configuring, triggering, and reading measurements from the
ni.com/training
instrument• Instrument drivers help you get started using instruments
from a PC, and save you development time and cost because you need not learn the programming protocol for each instrument
23
H. Instrument Drivers – Where are they?
• You can locate most LabVIEW Plug and Play instrument drivers in the Instrument Driver Finder− Access within LabVIEW by selecting Tools»
Instrumentation»Find Instrument Drivers or Help»Find I t t D i
ni.com/training
Instrument Drivers− Connects you with ni.com to find instrument drivers
• When you install an instrument driver, an example program using the driver is added to the NI Example Finder
24
5
H. Instrument Drivers – Example
ni.com/training25
Exercise 9-4: NI Devsim VI
ni.com/training
GOAL
To install an instrument driver and explore the example programs that are installed with the driver.
26
Summary—Quiz
1. Which instrument interface does not use the VISA API?a) Serialb) DAQc) GPIB
ni.com/training
d) Ethernet
27
Summary—Quiz Answer
1. Which instrument interface does not use the VISA API?a) Serialb) DAQc) GPIB
ni.com/training
d) Ethernet
28
Summary—Quiz
2. What API does the Instrument I/O Assistant use?a) Cb) Visual Basicc) VISA
ni.com/training
d) NI-DAQmx
29
Summary—Quiz Answer
2. What API does the Instrument I/O Assistant use?a) Cb) Visual Basicc) VISA
ni.com/training
d) NI-DAQmx
30
6
Summary—Quiz
3. Which of the following is a way to inform listeners that all data has been transferred?a) Asserting the End or Identify (EOI) line.b) Placing a end-of-string (EOS) character at the beginning
ni.com/training
of the data being transferred.c) Using the VISA Close function.d) Turning off the power to the controller.
31
Summary—Quiz Answer
3. Which of the following is a way to inform listeners that all data has been transferred?a) Asserting the End or Identify (EOI) line.b) Placing a end-of-string (EOS) character at the beginning
ni.com/training
of the data being transferred.c) Using the VISA Close function.d) Turning off the power to the controller.
32
1
TOPICS
Lesson 10Common Design Techniques
ni.com/training
A. Sequential ProgrammingB. State ProgrammingC. State MachinesD. Parallelism
A. Sequential Programming• Many of the VIs you write accomplish sequential tasks• There is nothing in this block diagram to force the
execution order of these tasks - any one of these tasks could happen first
ni.com/training
A. Sequential Programming
Use error clusters to force order of execution
ni.com/training
A. Sequential ProgrammingTo force execution order, use a Sequence structure• A structure with frames, where each frame executes in order• The second frame cannot begin execution until everything in the first
frame completes execution
ni.com/training
A. Sequential Programming
• Avoid overusing Sequence structures • You cannot stop the execution part way through a
sequence
ni.com/training
A. Sequential Programming
The best way to write this VI is to enclose the dialog boxes in Case structures, wiring the error cluster to the case selectors
ni.com/training
2
B. State Programming
Although Sequence structures or sequentially wired subVIs accomplish the purpose, it is not always the best choice:• What if you need to change the order of the sequence? • What if you need to repeat one item in the sequence more
ni.com/training
y p qoften than the other items?
• What if some items in the sequence execute only when certain conditions are met?
• What if you need to stop the program immediately, rather than waiting until the end of the sequence?
C. State Machines
• The state machine design pattern implements a state diagram or flow chart
• When to use state machines?− Commonly used to create user interfaces, where different
ni.com/training
user actions send the user interface into different states − Commonly used for process tests, where a state represents
each segment of the process
C. State Machines – Infrastructure
• A state machine consists of a set of states and a transition function that maps to the next state
• Each state can lead to one or multiple states or end the process flow
ni.com/training
While Loop
Case StructureShift Register
C. State Machines – Default Transition
ni.com/training
C. State Machines –Transition Between Two States
ni.com/training
C. State Machines –Case Structure Transition
ni.com/training
3
C. State Machines –Transition Array Transition
ni.com/training
Demonstration
Course Project
ni.com/training
GOAL
Demonstrate an implementation of a state machine.
C:\Exercises\LabVIEW Basics I\Course Project
Exercise 10-1: State Machine VI
ni.com/training
GOAL
Create a simple state machine using a type-defined enumerated control and practice the skills learned throughout this course.
D. Parallelism
• Often, you need to program multiple tasks so that they execute at the same time
• In LabVIEW, tasks can run in parallel if they do not have a data dependency between them, and if they do not use the
ni.com/training
same shared resource− An example of a shared resource is a file, or an instrument
• You learn about LabVIEW design patterns for executing multiple tasks at the same time in LabVIEW Basics II − These design patterns include parallel loops and
producer/consumer
Summary
The benefits of using a state machine instead of a sequential programming structure include:
• You can change the order of the sequence• You can repeat individual items in the sequence
ni.com/training
p q• You can set conditions to determine when an item in the
sequence should execute• You can stop the program at any point in the sequence
Continuing Your LabVIEW Education
• Instructor Led Training− LabVIEW Basics II: Learn about parallel loops, variables,
property nodes and building an executable− Hardware courses such as Data Acquisition and Signal
P i
ni.com/training
Processing− Online courses such as Machine Vision and LabVIEW Real-
Time• Self-Paced: a variety of instructional packages and tools
designed to educate you at your own pace
4
Continue Your Learning
• ni.com/support− Access product manuals, KnowledgeBase, example code,
tutorials, application notes, and discussion forums− Request technical support
ni.com/training
• Info-LabVIEW: www.info-labview.org• Alliance Program: ni.com/alliance• Publications: ni.com/reference/books/• Practice!
Courses
New User
LabVIEW Basics I
LabVIEW Basics II
Experienced User
LabVIEW Intermediate I
LabVIEW Intermediate II
Advanced User
LabVIEW Advanced I
Skills learned:• LabVIEW environment
navigation• Basics application creation
using LabVIEW• Basics of data acquisition and
Skills learned:• Modular application
development• Structured design and
development practices• Inter-application
Skills learned:• Large application design• Advanced development
techniques• Implementing multideveloper
projects
ni.com/training
Certifications
Certified LV Associate Developer Exam
Skills tested:• LabVIEW environment
knowledge
Certified LabVIEW Developer Exam
Skills tested:• LabVIEW application
development expertise
Certified LabVIEW Architect Exam
Skills tested:• LabVIEW application
development mastery
• Basics of data acquisition and instrument control
• Inter-application communication and connectivity techniques
projects
ni.com/training
THANK YOU!
Please complete the course survey and retrieve your course CD.