0% found this document useful (0 votes)
274 views

Lab View Manual

The LabVIEW Core 1 course teaches programming concepts and techniques for creating test, measurement, and instrumentation applications using LabVIEW. It assumes familiarity with Windows and experience writing algorithms. The course covers navigating the LabVIEW environment, understanding VIs, programming structures, and debugging techniques. Students will learn to create and save reusable VIs, display and log data, and interface with DAQ devices and instruments. Completing the course prepares students to become NI Certified LabVIEW Associate Developers.

Uploaded by

Swopnil Parida
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
274 views

Lab View Manual

The LabVIEW Core 1 course teaches programming concepts and techniques for creating test, measurement, and instrumentation applications using LabVIEW. It assumes familiarity with Windows and experience writing algorithms. The course covers navigating the LabVIEW environment, understanding VIs, programming structures, and debugging techniques. Students will learn to create and save reusable VIs, display and log data, and interface with DAQ devices and instruments. Completing the course prepares students to become NI Certified LabVIEW Associate Developers.

Uploaded by

Swopnil Parida
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 106

A.

NI Certification
The LabVIEW Core 1 course is part of a series of courses designed to build your proficiency
with LabVIEW and help you prepare for the NI Certified LabVIEW Associate Developer
exam. The following illustration shows the courses that are part of the LabVIEW training
series.

LabVIEW Learning Path

Certified LabVIEW Certified LabVIEW Certified LabVIEW


Associate Developer Developer Architect

LabVIEW
LabVIEW LabVIEW LabVIEW Core 3
Getting Started Core 1 Core 2 Advanced
Architectures
LabVIEW
Connectivity in LabVIEW

LabVIEW
Performance Managing
Software
Engineering
Object-Oriented
in LabVIEW
Design &
Programming
in LabVIEW

B. Course Description
The LabVIEW Core 1 course teaches you programming concepts, techniques, features,
VIs, and functions you can use to create test and measurement, data acquisition,
instrument control, datalogging, measurement analysis, and report generation
applications. This course assumes that you are familiar with Windows and that you have
experience writing algorithms in the form of flowcharts or block diagrams.

The Participant Guide is divided into lessons. Each lesson contains the following:
• An introduction with the lesson objective and a list of topics and exercises.
• Slide images with additional descriptions of topics, activities, demonstrations, and
multimedia segments.
• A set of exercises to reinforce topics. Some lessons include optional and challenge
exercises.
• A lesson review that tests and reinforces important concepts and skills taught in the
lesson.
C. What You Need to Get Started
Before you use this course manual, make sure you have all of the following items:

 Computer running Windows 7/Vista/XP

 Multifunction DAQ device configured as Dev1 using Measurement & Automation


Explorer ( MAX )

 DAQ Signal Accessory or BNC-2120, wires, and cable

 LabVIEW Professional Development System 2014 or later

 DAQmx 14 or later

 A GPIB cable

 NI-488.2 14 or later

 NI-VISA 14.0.1 or later

 NI Instrument Simulator and power supply

 NI Instrument Simulator Wizard installed from the NI Instrument Simulator software


CD

 LabVIEW Core 1 course CD, from which you install the following folders:

Directory Table Head

Exercises Contains VIs used in the course

Solutions Contains completed course exercises

D.Installing the Course Software


Complete the following steps to install the course software.
1. Insert the course CD in your computer. The LabVIEW Core 1 Course Setup dialog box
appears.
2. Click Install the course materials.
3. Follow the onscreen instructions to complete installation and setup.

E. Course Goals
This course prepares you to do the following:
• Understand front panels, block diagrams, icons, and connector panes
• Use the programming structures and data types that exist in LabVIEW
• Use various editing and debugging techniques
• Create and save VIs so you can use them as subVIs
• Display and log data
• Create applications that use plug-in DAQ devices
• Create applications that use serial port and GPIB instruments

1 Navigating LabVIEW
1 Navigating
LabVIEW
In this lesson you will learn to recognize the main components of the LabVIEW environment and be able
to create a new project and VI.

Topics
+ What is LabVIEW?
+ Project Explorer
+ Parts of a VI
+ Front Panel
+ Block Diagram
+ Searching for Controls, VIs, and Functions

Exercises
Exercise 1-1 Concept: Exploring a VI
Exercise 1-2 Concept: Locating Controls, Functions, and Vis
A. What is LabVIEW?
Objective: Recognize benefits of LabVIEW.

LabVIEW is a graphical programming environment you can used to develop sophisticated measurement,
test, and control systems.

Benefits of LabVIEW
• A platform-based approach for measurement and control
• Interfaces with wide variety of hardware
• Scales across different targets and operating systems • Provides built-in analysis libraries
LabVIEW Language Characteristics

LabVIEW Core 1 Topics LabVIEW Core 2 and Later Topics


Graphical Multi-threaded
Uses icons and wires instead of with text. Enables your code to have automatic parallelism.

Dataflow-oriented Object-oriented
Data-driven, or data-dependent. The flow of data between Allows a variety of similar, yet different items, to be
nodes in the G code determines the execution order. represented as a class of objects in software.

Compiled Multi-target
Compiles G code directly to machine code. Targets multicore processors and other parallel hardware
such as field-programmable gate arrays (FPGAs).

LabVIEW Core 1 Topics LabVIEW Core 2 and Later Topics

Multi-platform Memory-managed
Is portable between LabVIEW on different operating Provides you with options for improving performance.
systems.

Synchronous

Event-driven
Allows the user's direct interaction with the program
without the need for polling.

B. Project Explorer
Objective: Recognize the main components of the Project Explorer.
Project Explorer Projects in LabVIEW consist of VIs, files necessary for those VIs to run properly, and
supplemental files such as documentation or related links. Use the Project
Explorer window to manage projects in
LabVIEW. A LabVIEW project is denoted by a project file (.lvproj)

LabVIEW Files
Listed below are some of the characteristics of a LabVIEW project.
• Manages project files
• Deploys programs to remote embedded targets such as NI CompactRIO
• Creates stand-alone executables and installers for distribution
• Makes it possible to distribute code to developers and create shared libraries
• Can integrate LabVIEW programs with source code control software such as Perforce

Common LabVIEW File Extensions

LabVIEW Project — .lvproj

Virtual Instrument (VI) — .vi

Custom Control — .ctl

Demonstration: Using the Project Explorer and Starting a VI


The Project Explorer window includes the following items by default:
• Project root—Contain all other items in the Project Explorer window. The label on the project root
includes the filename for the project.
• My Computer—Represents the local computer as a target in the project.
• Dependencies—Includes VIs and items that VIs under a target require.
• Build Specifications—Includes build configurations for source distributions and other types of builds
available in LabVIEW toolkits and modules. If you have the LabVIEW Professional Development
System or Application Builder installed, you can use Build Specifications to configure stand-alone
applications, shared libraries, installers, and zip files.

When you add another target to the project, LabVIEW creates an additional item in the Project
Explorer window to represent the target. Each target also includes Dependencies and Build
Specifications sections. You can add files under each target.

1 2 3 4

8 7 6 5

1 Standard Toolbar Project Root


2 Project Toolbar 6 Target
3 Build Toolbar 7 Dependencies
4 Source Control Toolbar 8 Build
Specifications
Adding Folders to a Project
Add folders to a project to create an organizational structure for project items.

Auto-Populated Folders Virtual Folders

Adds a directory on disk to the project Organizes project items and does not represent files on
disk

LabVIEW continuously monitors and updates the folder Can convert a virtual folder to an auto-populated
according to changes made in the project and on disk folder.

B. Parts of a VI

1 Auto-populating folder 2 Virtual folder


C. Demonstration: Components of a VI
D. LabVIEW VIs contain three main components—the front panel window, the block diagram, and
the icon/connector pane.

Front Panel Block Diagram Icon/Connector Pane

Is the user interface. Contains the graphical source Represents the VI and makes it
code. possible to use the VI as a subVI.

Has controls (inputs) and Contains terminals for front Maps the inputs and outputs to
indicators (outputs). panel controls and indicators. the VI.

E. D.Front Panel
F. Objective: Recognize the components and functionality of the Front Panel window and
select appropriate controls and indicators
G. Front Panel User interface for the VI. Contains controls and indicators, which are the
interactive input and output terminals of the VI, respectively.
H. Front Panel Window Toolbar
I. Use the front panel window toolbar buttons to run and edit the VI.
Controls and Indicators

Controls Indicators

Interactive input Interactive output

Knobs, push buttons, dials, and other inputs Graphs, LEDs, and other displays

Simulate instrument input devices and supply data to Simulate instrument output devices and display data
the block diagram the block diagram acquires or generates

String, Boolean, and Numeric Data Types


The following table shows controls and indicators of the string, Boolean, and numeric data types.
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.

The Boolean data type represents


data that only has two possible
states, such as TRUE and FALSE or
ON and OFF.
Use Boolean controls and
indicators to enter and display
Boolean values.

The numeric data type can


represent numbers of various
types, such as integer or real.
The two common numeric objects
are the numeric control and the
numeric indicator.

Goal
For each scenario, determine the appropriate data type and whether the front panel object should be a control or indicator.

Scenario Data Type Control/Indicator

Display the temperature of a room Numeric Indicator

An Emergency stop button to stop a


process

Username and password to login to


your bank account

An LED to display error status


Front Panel Object Styles
LabVIEW has different control palettes with objects for building user interfaces. These palettes include
the Modern, Silver, Classic, and Systems palettes.

E. Block Diagram
Objective: Recognize features of the Block Diagram and be able to select functions.

Block Diagram Block diagram objects include terminals, subVIs, functions, constants, structures, and
wires, which transfer data among other block diagram objects.
Block Diagram Toolbar
When you run a VI, buttons appear on the block diagram toolbar that you can use to debug the VI.

Demonstration: Components of a Block Diagram

Component Description

Terminals Terminals are the entry and exit ports that exchange information between the front
panel and block diagram. You can view terminals as icon conserve space.

Nodes Nodes are objects on the block diagram that have inputs and/or outputs and perform
operations when a VI runs. Nodes are analogous to statements, operators, functions, and
subroutines in text-based programming languages. Nodes can be functions, subVIs, or
structures.

Function Nodes Functions are fundamental operating elements of LabVIEW and do not have front panels
(Functions) or block diagrams. Function icons have pale yellow backgrounds.
SubVIs SubVIs are VIs that run on the block diagram of another VI. They have front panels
and block diagrams. Any VI has the potential to be used as a subVI. When you
double-click a subVI, the front panel and block diagram open.

Icon Icons are the graphical representations of VIs.

Use the icon from the upper-right corner of the front panel as the icon that
appears when you place the subVI on a block diagram.

Connector Pane The connector pane is the map of inputs and outputs of a VI

The connector pane terminals correspond to the controls and indicators on the
front panel of the VI. You cannot access the connector pane from the block diagram
window.

Express VIs
Express VIs are a type of subVI that you configure with dialog boxes. Icons for Express VIs appear on the
block diagram as icons surrounded by a blue field.

Wires
1 1
Wires transfer data between block diagram objects. A broken wire appears as a dashed black line with a
red X in the middle. You cannot run a VI that contains a broken wire.

Broken wires occur for a variety of reasons, such as when you try to wire two objects with incompatible
data types.
Common Wire Types

Wire Type Scalar 1 D Array 2 D Array Color

Numeric Orange (floating-point),


Blue (integer)

Boolean Green

String Pink

To toggle display of the Context Help window select Help»Show Context Help, press the <Ctrl-H> keys,
or click the Show Context Help Window button on the toolbar.

Functions Palette
The Functions palette contains the VIs, functions and constants you use to create the block diagram. Select View»
Functions Palette to display it.

Navigate the sub palettes or use the Search button to search the Functions palette.
Figure 1-4. Functions Palette

2 Creating your
First
application

A.Dataflow
Objective: Recognize characteristics of dataflow on the block diagram.

Dataflow Dataflow is the movement of data through the nodes of a block diagram.

Key Points of Dataflow


LabVIEW follows a dataflow model for running VIs.

Description: Work through this exercise on your own first, and then as a class, we will discuss
how data flow determines execution order. You can find answers to these questions following
this section.
Figure 2-1. Dataflow: Example A

1. which Express VI executes last?


Figure 2-2. Dataflow: Example B

2. an error wire connects the Express VIs. Which Express VI executes last?
Figure 2-3. Dataflow: Example C

3. In Figure 2-4, which Tone Measurements Express VI executes last?


Figure 2-4. Dataflow: Example D

B. LabVIEW Data Types


Objective: Recognize the different data types and how they relate to front panel objects.
Terminals and LabVIEW Data Types
Block diagram terminals visually communicate information about the data type represented.
Terminal colors, text, arrow direction, and border thickness all provide visual information about
the terminal.

Demonstration: Accessing Object Properties


Shortcut Menus
• Use shortcut menu items to change the appearance or behavior of objects.
• To access the shortcut menu, right-click the object.

Property Dialog Boxes


• To access properties, right-click the object and select Properties.
• Select multiple objects to simultaneously configure shared properties.
Boolean Data
Use Boolean controls and indicators to enter and display Boolean (TRUE/FALSE) values. LabVIEW stores
Boolean data as 8-bit values. If the 8-bit value is zero, the Boolean value is FALSE. Any nonzero value
represents TRUE.

Controls
Boolean controls have six types of mechanical action that allow you to customize Boolean
objects to create front panel windows that more closely resemble the behavior of physical
instruments.

Complete the multimedia module, Mechanical Actions of Boolean Controls, available in the
<Exercises>\LabVIEW Core 1\Multimedia\ folder.

Multimedia: Numeric Data Representations


LabVIEW represents numeric data types as floating-point numbers, fixed-point numbers,
integers, unsigned integers, and complex numbers. The difference among the numeric data
types is the number of bits they use to store data and the data values they represent.

Complete the multimedia module, Numeric Data Representations, available in the


<Exercises>\LabVIEW Core 1\Multimedia\ folder.

Strings
A string is a sequence of displayable or non-displayable ASCII characters. Strings provide a
platform-independent format for information and data. Some of the more common applications
of strings include the following:
• Creating simple text messages.
• Controlling instruments with text commands
• Storing numeric data to disk. To store numeric data in an ASCII file, first convert data to
strings.
Instructing or prompting with dialog boxes

• Right-click a string control or indicator on the fr ont panel to select from the display type.
Navigating
Demonstration: Enums
Enums give users a list of items from which to select. Enums are useful because they make
strings equivalent to numbers, which are easy to manipulate on the block diagram. Each item
represents a pair of values: a string value and a 16-bit integer.
W Other Data Types

Type Terminal Description

Dynamic Stores the information generated or acquired by an


Express VI

Path Stores the location of a file or directory using the standard


syntax for the platform you are using

Waveform Carries the data, start time, and dt of a waveform

Demonstration: Programming Tools


You can create, modify and debug VIs using the tools provided by LabVIEW. LabVIEW chooses which tool
to select based on the current location of the mouse. If you need more control, use the Tools palette to
select a specific tool.

Tool Icon Description


Operating Use the Operating tool to change the values of a
control.

Positioning Use the Positioning tool to select or resize objects.

Labeling Use the Labeling tool to enter text in a control, to


edit text, and to create free labels.

Wiring Use the Wiring tool to wire objects together on the


block diagram.

Automatic Tool When this is selected, LabVIEW automatically


Selection chooses a tool based on the location of your cursor.
You can turn off automatic tool selection by
deselecting the item, or by selecting another item in
the palette.

Object Shortcut Use the Object Shortcut Menu tool to access an


Menu object shortcut menu with the left mouse button.

Scrolling
Use the Scrolling tool to scroll through windows
without using scrollbars.

Breakpoint Use the Breakpoint tool to set breakpoints on VIs,


functions, nodes, wires, and structures to pause
execution at that location.

Tool Icon Description

Probe Use the Probe tool to create probes on wires on the


block diagram. Use the Probe tool to check
intermediate values in a VI that produces
questionable or unexpected results.

Color Copy
Use the Color Copy tool to copy colors for pasting
with the Coloring tool.

Coloring Use the Coloring tool and the color picker to color
an object. The Coloring tool displays the current
foreground and background color settings. Select
the Coloring tool and right-click an object or
workspace to display the color picker.

Demonstration: Making Code Readable


Block diagram comments can describe the function or operation of algorithms and explain the purpose
of data that passes through wires.
D. Building a Basic VI
Objective: Recognize Express VIs and be able to apply them appropriately.

Building a Basic VI
Express VIs are designed specifically for completing common, frequently used operations.

On the Functions palette, the Express VIs are grouped together in the Express category. Express VIs use
the dynamic data type to pass data between Express VIs.

Acquire DAQ Assistant Acquires data through a data acquisition


device.You must use this Express VI frequently
throughout this course.

Instrument I/O Acquires instrument control data, usually from a


Assistant GPIB or serial interface.

Simulate Signal
Generates simulated data such as a sine wave.

Read from Reads a file that was created using the Write To
Measurement Measurement File Express VI. It specifically reads
File LVM or TDM file formats.
This Express VI does not read ASCII files.

VI Icon Description

Analyze Amplitude and Performs voltage measurements on a signal. These


Level include DC, rms, maximum peak, minimum peak,
Measurements peak to peak, cycle average, and cycle rms
measurements.

Statistics Calculates statistical data from a waveform. This


includes mean, sum, standard deviation, and
extreme values.
Tone Searches for a single tone with the highest
Measurements frequency or highest amplitude. It also finds the
frequency and amplitude of a single tone.

Spectral Performs spectral measurement on a waveform,


Measurements such as magnitude and power spectral density.

Filter Processes a signal through filters and windows.


Filters used include the following: Highpass,
Lowpass, Bandpass, Bandstop, and Smoothing.
Windows used include Butterworth, Chebyshev,
Inverse Chebyshev, Elliptical, and Bessel.

Visualize Write to Writes a file in LVM or TDMS file format.


Measurement
File

Build Text Creates text, usually for displaying on the front


panel window or exporting to a file or instrument.

Front panel — Examples include Waveform Chart, Waveform


indicators Graph, and XY Graph.

Activity 2-2: Program Architecture for Simple AAV VI


1. Acquire: Circle the Express VI that is best suited to acquire a sine wave from a data acquisition device.

DAQ Assistant The DAQ Assistant acquires data through a data


acquisition device.

Instrument I/O Assistant The Instrument I/O Assistant acquires instrument


control data, usually from a GPIB or serial
interface.

Simulate Signal The Simulate Signal Express VI generates simulated


data, such as a sine wave.

2. Analyze: Circle the Express VI that is best suited to determining the average value of the acquired data.

Tone Measurements The Tone Measurements Express VI finds


the frequency and amplitude of a single
tone.

Statistics The Statistics Express VI calculates


statistical data from a waveform.
Amplitude and Level Measurements The Amplitude and Level
Measurements Express VI performs
voltage measurements on a signal.

Filter The Filter Express VI processes a signal


through filters and windows.

3. Visualize: Circle the Express VIs and/or indicators that are best suited to displaying the data on a graph and
logging the data to file.

DAQ Assistant The DAQ Assistant acquires data through a data


acquisition device.

Write to Measurement File The Write to Measurement File Express VI writes a


file in LVM or TDM file format.

Build Text The Build Text Express VI creates text, usually for
displaying on the front panel window or exporting to a
file or instrument.

Waveform Graph
The waveform graph displays one or more plots of
evenly sampled measurements.
3 Troubleshooting and
Debugging VIs

A.Correcting Broken VIs


Objective: Recognize an unexecutable VI and restate common problems.

If the Run button appears broken when you finish wiring the block diagram, the VI is broken and cannot
run.

Example Cause

Broken wire due to


mismatch of data types.
Required terminal is
unwired.

Control wired to another


control.

Broken subVI due to


unwired required
terminal.

Identify Problems and Fix Broken VIs


Use the Error list dialog box to locate the source of errors and warnings, and get more detailed
information about the problem.
B. Debugging Techniques
Objective: Identify the LabVIEW tools for debugging and select the tool appropriate to the situation.

Debugging Tips
The following table includes a few common problems to look for when debugging your VIs.

Is the numeric representation correct for your


application?

Do nodes execute in the correct order?

Does the VI pass undefined data?


Are there any hidden or unwired subVIs?

Activity 3-1: Review Debugging Tools


Goal
Select the LabVIEW debugging tool you would use for each of the following situations.

Execution Highlighting Single Stepping Probe

Situation Debugging Tool

Your VI is returning unexpected data and you want Probe


to see intermediate values on the wires to find out
where the problem initiates.

You want to see how data moves from one node to


the next on the block diagram.

You want to view each action of the VI on the block


diagram.

Breakpoints
Use the Breakpoint tool to place a breakpoint on a VI, node, or wire and pause execution at that location.

When you reach a breakpoint during execution, the VI pauses and the Pause button appears red. You can
take the following actions:
• Single-step through execution using the single-stepping buttons
• Probe wires to check intermediate values
• Change the values of front panel controls.
• Click the Pause button to continue running to the next breakpoint or until the VI finishes running.

Retain Wire Values


Retain Wire Values enables you to probe wire values after execution completes. This option uses
more memory because LabVIEW is storing data for each wire as it runs.

Undefined or Unexpected Data


Floating-point operations return the following two symbolic values that indicate faulty computations or
meaningless results.

NaN (not a number) a floating-point value that


invalid operations produce,
such as taking the square root
of a negative number

Inf (infinity) a floating-point value that valid


operations produce, such as
dividing a number by zero

C. Error Handling
Objective: Describe the difference between automatic and manual error handling.
Error Handling Review

Error Handling Anticipation, detection, and resolution of warnings and errors


Automatic At run time, LabVIEW suspends execution, highlights node where
Error Handling error occurred, and displays Error dialog box
Manual You control when dialog boxes appear, propagate errors through
Error Handling error in/error out clusters, terminate error chain with Simple Error
Handler
Demonstration: Automatic vs. Manual Error Handling
• Manual error handling—Use Simple Error Handler to display errors
• Automatic error handling—Highlights the node that caused the error

Enabling automatic error handling does not override manual error handling. If the error cluster is wired
and the VI uses the Simple Error Handler, then LabVIEW defaults to manual error handling.

Disable Automatic Error Handling


To ensure that LabVIEW doesn’t implement automatic error handling by default, disable it for all new VIs.
Change the configuration settings in the Tools»Options dialog box.

Error Clusters
VIs and functions return errors in one of two ways—with numeric error codes or with an error cluster.
Typically, functions use numeric error codes, and VIs use an error cluster, usually with error inputs and
outputs. Use the error cluster controls and indicators to create error inputs and outputs in subVIs.

#
4 using loop
A. Loops Review
Objective: Recognize loop structures and explain how to use them.

While Loops—Review
• Similar to Do Loop or a Repeat-Until Loop
• Repeats code segment until a condition is met
• Always execute at least once
• Iteration terminal—output that contains the number of complete iterations

• Iteration terminal always starts at zero


• Conditional terminal sets the condition for stopping the loop

Code

No Repeat (code);
Condition Until Condition met;
Code
met?
End;
Yes

End

C.For Loops
Objective: Demonstrate how to add a conditional terminal to a For Loop and describe how numeric
conversion occurs on the For Loop count terminal.

Conditional Terminal
You can add a conditional terminal to configure a For Loop to stop when a Boolean
condition or an error occurs. A For Loop with a conditional terminal executes until the
condition occurs or until all iterations are complete, whichever happens first.

The following For Loop generates a random number every second until 100 seconds has
passed or until the user clicks the stop button.
2

1 Right-click the loop border and select Condi tional Terminal from the shortcut menu.
2 Red glyph appears in the count terminal and a conditional terminal in the lower right corner.

Count Terminal Numeric Conversion


If you wire a double-precision, floating-point numeric value to the count terminal, LabVIEW
converts the numeric value to a 32-bit signed integer.

C.For Loops
Objective: Demonstrate how to add a conditional terminal to a For Loop and describe how numeric conversion occurs
on the For Loop count terminal.

Conditional Terminal
You can add a conditional terminal to configure a For Loop to stop when a Boolean condition or an error
occurs. A For Loop with a conditional terminal executes until the condition occurs or until all iterations are
complete, whichever happens first.

The following For Loop generates a random number every second until 100 seconds has passed or until the
user clicks the stop button.

1 Right-click the loop border and select Condi tional Terminal from the shortcut menu.
2 Red glyph appears in the count terminal and a conditional terminal in the lower right corner.
Count Terminal Numeric Conversion
If you wire a double-precision, floating-point numeric value to the count terminal, LabVIEW converts the numeric
value to a 32-bit signed integer.

D.Timing a VI
Objective: Identify scenarios that require loop timing and apply the appropriate function

Why Do You Need Timing in a VI?


When a loop finishes executing an iteration, it immediately begins executing the next iteration, unless it
reaches a stop condition. If you are acquiring data, and you want to acquire the data once every 10
seconds, you need a way to time the loop iterations so they occur once every 10 seconds. You also want
to time a loop to provide the processor with time to complete other tasks, such as processing the user
interface.

Wait Functions Inside a Loop


Use a wait function inside a loop to accomplish the following actions:

Wait Function Behavior

Wait Until Next ms Multiple Monitors a millisecond counter and waits until the millisecond counter
reaches a multiple of the amount you specify. This function is synced to
the system clock.
Waits until the millisecond counter counts to an amount equal to the
Wait (ms)
input you specify

Wait Function Timing


The following illustration compares the differences between two common timing
functions: Wait Until Next ms Multiple and Wait (ms). This timing diagram assumes that
the wait functions begin running immediately for each loop iteration and that the loop is
ready to iterate as soon as the wait function finishes.

Elapsed Time Express VI


Determines how much time elapses after some point in your VI and keeps track of time while the VI continues
to execute.

Demonstration: Wait Chart VI


Compare and contrast using a Wait function and the Elapsed Time Express VI for software timing.

E. Data Feedback in Loops


Objective: Apply shift registers when appropriate and predict the correct value at different
iterations of the loop.
Introduction to Shift Registers
Shift registers store data values from previous iterations of a loop in LabVIEW.

Shift registers are similar to static variables in text-based programming languages.

Demonstration: Creating Shift Registers


Replace tunnels with shift registers when you need to transfer values from one loop iteration to the next.
If you convert a tunnel with auto-indexing enabled to a shift register on a While Loop, the wire to any
node outside the loop breaks because shift registers cannot auto-index.
F. Plotting Data
Objective: Use data feedback in a loop to plot waveform charts.

Waveform Chart
The waveform chart is a special type of numeric indicator that displays one or more plots of data typically
acquired at a constant rate. Waveform charts can display single or multiple plots.

A.Arrays
Objective: Identify when to use arrays and learn how to create and initialize arrays.

Arrays
Array Collection of data elements that are of the same type.
Elements The data that make up the array. Elements can be numeric, Boolean, path,
string, waveform, and cluster data types.
Dimension Length, height, or depth of the array. Arrays can have one or more dimensions
and
as many as (231)-1 dimensions.
5 Creating and
Leveraging data
structures
1 D and 2D
Arrays can have multiple dimensions.
• 1D array:

For example, LabVIEW represents a text array that lists the twelve months of the year as a 1D array
of strings with twelve elements. Index is zero-based, which means the range is 0 to n- 1, where n is
the number of elements in the array. For example, n = 12 for the twelve months of the year, so the
index ranges from 0 to 11. March is the third month, so it has an index of 2.
• 2 D array :

Column Index
0 1 2 3 4 5 6 7
0
1
2
3
4
5
6
7
2 D Arrays
A 2D array stores elements in a grid. It requires a column index and a row index to locate an element,
both of which are zero-based.

Initializing Arrays
An uninitialized array contains a fixed number of dimensions but no elements. An initialized defines the
number of elements in each dimension and the contents of each element.

B. Common Array Functions


Objective: Create and manipulate arrays using built-in array functions.

Multimedia: Common Array Functions


Functions you can use to manipulate arrays are located on the Array palette.

Complete the multimedia module, Common Array Functions, available in the <Exercises>\LabVIEW
Core 1\Multimedia\ folder.

Initialize Array
Creates an n-dimensional array in which every element is initialized to the value of element.

Insert Into Array


Inserts an element or subarray at the point you specify in index.
Delete From Array
Deletes an element or subarray from n-dim array of length elements starting at index. Returns the
edited array in array w/ subset deleted and the deleted element or subarray in deleted portion.

Array Max & Min


Returns the maximum and minimum values in array, along with the indexes for each value.
Search 1D Array
Searches for an element in a 1D array starting at start index. Because the search is linear, you need not
sort the array before calling this function. LabVIEW stops searching as soon as the element is found.

D.Auto-Indexing
Objective: Use auto-indexed inputs and outputs to create graphs and arrays.

Auto-indexing The ability to automatically process every element in an array.

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. The tunnel image changes from a solid square to the image to indicate auto-
indexing.
2

1 3

1 Right-click the tunnel and select Enable Indexing or Disable Indexing to toggle the state of
the tunnel.
2 Auto-indexed output arrays are always equal in size to the number of iterations.
3 Only one value (the last iteration) is passed out of the loop when auto-indexing is disabled.

Waveform Graphs
A waveform graph collects the data in an array and then plots the data to the graph.

Charts vs. Graphs—Single-Plot


Charts are generally used inside the While Loop and graphs are generally outside the While Loop.
Creating Two-Dimensional Arrays
Use two For Loops, nested one inside the other, to create a 2D array.

1 The inner loop creates the column elements and the outer loop creates the row elements.
Auto-Indexing Input
Use an auto-indexing input array to perform calculations on each element in an array. If you wire an array
to an auto-indexing tunnel on a For Loop, you do not need to wire the count (N) terminal.
I

1 2

1 The For Loop executes the number of times e qual to the number of elements in the array.
2 If the iteration count terminal is wired and arrays of different sizes are wired to auto-indexed tunnels, the actual number of
iterations becomes the smallest of the choices.

Auto-Indexing Input—Different Array Sizes


If the iteration count terminal is wired and arrays of different sizes are wired to auto-indexed tunnels,
the actual number of iterations becomes the smallest of the choices.
I

1 The For Loop iterates 5 times and because the iterations ar e zero-based, the output is 4.

E. Clusters
Objective: Identify when to use clusters and be able to create them.

Clusters

Clusters Clusters group data elements of mixed types

A cluster is similar to a record or a struct in text-based programming languages.An example of a cluster


is the LabVIEW error cluster, which combines a Boolean value, a numeric value, and a string.

Clusters vs. Arrays


Cluster Array

• Mixed data types • Vary in size


• Fixed size • Contain only one data type

Demonstration: Create a Cluster Control


Create a cluster control or indicator on the front panel by adding a cluster shell to the front panel and
dragging a data object or element into the shell. The element can be a numeric, Boolean, string, path,
refnum, array, or cluster control or indicator.
LabVIEW Core 1 Participant Guide

Cluster Order
Cluster elements have a logical order unrelated to their position in the shell. The cluster order
determines the order in which the elements appear as terminals on the Bundle and Unbundle
functions on the block diagram.

You can view and modify the cluster order by right-clicking the cluster border and selecting
Reorder Controls In Cluster from the shortcut menu.
Autosizing Clusters
Autosizing helps you arrange elements in clusters.NI recommends the following:
• Arrange cluster elements vertically.
• Arrange elements compactly.
• Arrange elements in their preferred order.
Disassembling Clusters
Use the Unbundle and Unbundle By Name functions to return individual cluster elements.

12

Modifying a Cluster
Use Bundle By Name whenever possible to access elements in a cluster. Use Bundle when some
or all cluster elements are unnamed.
I
Multi-plot Graphs/Charts and XY Graph
The Bundle function is often used to create multi-chart plot charts and XY plots. The Build
Array function is used to create multi-plot waveform graphs.

Plotting Data
Use the Context Help window to determine how to wire multi-plot data to Waveform Graphs,
Charts and XY Graphs.
Error Clusters
LabVIEW contains a custom cluster called the error cluster. LabVIEW uses error clusters to pass error
information.

F. Type Definitions
Objective: Identify and determine when to use a type definition, strict type definition, or control.

Control Options
Use custom controls and indicators to extend the available set of front panel objects and to make them available
on other front panels.

Three types of custom controls—Control, Type Definition, Strict Type Definition.


Demonstration: Difference between Control, Type Def and Strict Type
Def
• Custom controls are templates and used as starting points for other similar controls.
Changes made to one control does not reflect in other controls.
Demonstration: Creating and Identifying Type Definitions

Additional Resources

Learn More About LabVIEW Help Topic

Arrays Adding Elements to Arrays


Changing Array Default Values
Creating Array Controls and Indicators Default Sizes
and Values of Arrays

Determining the Size of Arrays


Clusters Creating Cluster Controls and Indicators Modifying Cluster
Element Order

Moving Arrays and Clusters


Setting Cluster Default Values
Tabbing through Elements of an Array or Cluster

Type Definitions Creating Type Definitions and Strict Type Definitions

6 Using Decision and


Making-structure
A. Case Structures
Objective: Recognize and use the basic features and functionality of Case Structures.

Case Structures Review


Figure 6-1. Case Structures Review

Demonstration: Case Structures


Right-click the Case structure to display the shortcut menu. The shortcut menu gives you options
for configuring a Case structure.
Selector Terminal Data Types
You can wire a variety of data types to the Selector Terminal. The Case structure configuration
changes based on the type of data that you connect.

Data Type Example

Boolean
A newly-created Case structure defaults to a
Boolean input.
The Case Structure includes a True case and a False
Case.
Integer
Case Structure has any number of cases.
Specify a Default case.
The numeric representation of the integer input
will determine the range of possible values for the
Case Selector Label.
You can specify ranges of values for the Case
Selector Label.
Use Radix option in shortcut menu to specify
whether the Case Selector Label displays values in
decimal, hexadecimal, octal, or binary.

String
Case Structure has any number of cases.
Specify a Default case.
By default, string values are case sensitive.
Shortcut menu includes option for Case
Insensitive Match for the string text.

Data Type Example

Enum
Possible to ensure that the Case Structure
includes a case for every item in the enum.
Right-click the border of the Case Structure and
select Add Case for Every Value to create a case
for every item.
Error Cluster
Case Structure includes an Error Case and a No
Error Case.
Wire an error cluster to the terminal to execute
code if there is no error and skip code if there is
an error.

Input and Output Tunnels


As with other types of structures, you can create multiple input and output tunnels.
• Input tunnels are available to all cases if needed.
• Output tunnels require that you define a value for each case.
• Be cautious using the Use Default If Unwired option.
– Adds a level of complexity to the code.
– Can complicate debugging your code.
– The default value may not be the value that you expect.

Data Type Wired to Tunnel Default Value

Numeric 0

Boolean FALSE
String
empty ( "" )

Demonstration: Selector Terminal Types and Tunnels


• Create Case structures using different data type selectors.
• Create different types of output tunnels.

Event-Driven Programming
Objective: Recognize basic features and functionality of event structures.

Demonstration: Event-Driven Scenario


Multimedia: Event-Driven Programming
Configuring the Event Structure
You can select which events the Event structure implements by right-clicking the border
and selecting Edit Events Handled by This Case from the shortcut menu

Edit Events Dialog Box


1 2 3

1 Configured events 2 Event sources 3 Events

Notify and Filter Events


LabVIEW categorizes user interface events into two different types of events:
• Notify—(Green arrow) Notify events inform you that a user action occurred. LabVIEW has
already performed the default action associated with that event.
• Filter—(Red arrow) Filter events allow you to validate or change the event data before
LabVIEW performs the default action associated with that event. You also can discard the
event entirely to prevent the change from affecting the VI.

Demonstration: Configure and Use Events


Configure and use an Event structure to create a VI that responds to user interface events
using event-driven programming.

Caveats and Recommendations


The following list describes some of the caveats and recommendations to consider when
incorporating events into LabVIEW applications.
• Place only one Event structure in a loop.
• Use a Value Change event to detect value changes.
• Keep event handling code short and quick.
• Place Boolean control terminals inside an event case for latched operations to work properly.
• Avoid using an Event structure outside of a loop.
• Avoid configuring two Event structures for the same event.

Think about the VIs that you will need to develop at your job.
Will you use event-based programming to implement any of your VIs? Why or why not?
Additional Resources

Learn More About LabVIEW Help Topic or ni.com

Event-driven programming Locking Front Panels


Choosing How the Event Structure Monitors For Events
Viewing Enqueued Events at Run Time Event-Driven
Programming

Events in LabVIEW

Deciding whether to use events Caveats and Recommendations when Using Events in
LabVIEW

Part of the Event structure Event Structure


Configuring Events Handled by the Event Structure
7 Modularity
A. Understanding Modularity
Objective: Recognize the benefit of using modular code and identify sections of code that
could be reused.

Modularity and SubVIs

Modularity The degree to which a program is composed of discrete modules such that a change
tonne module has minimal impact on other modules. Modules in LabVIEW are
called subVIs.
Sub VI A VI used within another VI.The degree to which a program is composed of discrete
modules such that a change tonne module has minimal impact on other modules.
Modules in LabVIEW are called subVIs.

SubVIs—Reusing Code
SubVIs are similar to a subroutine in text-based programming languages. Use subVIs when you
have code that performs identical operations on different parts of your block diagram or in
another VI.
SubVIs
The following pseudo-code and block diagrams demonstrate the analogy between subVIs and
subroutines.

Function Code Calling Program Code

function average (in1, in2, out)


main { average (point1, point2,
{ out = (in1 + pointavg)
in2)/2.0;
}
}

SubVI Block Diagram Calling VI Block Diagram

B. Icon
Objective: Recognize characteristics of a good icon and use the LabVIEW Icon Editor to create
a custom icon.

Icon A VI icon is a graphical representation of a VI. It can contain text, images, or a


combination of both. If you use a VI as a subVI, the icon identifies the subVI on the
block diagram of the VI.

Purpose of Icon
This icon displayed in the upper right corner of the front panel is the same as the icon that
appears when you place the VI on the block diagram.

Characteristics of a Good Icon


A good icon conveys the functionality of the VI by using relevant graphics and text. You can also
uses banners to identify related VIs.
Creating Icons—Icon Editor
Use the Icon Editor dialog box to edit a VI icon. You can customize your icon with text, graphics
from the glyphs library, and banners. Additionally, you can create and save custom templates.
B. Connector Pane
Objective: Select and configure a connector pane for a subVI.

Connector Pane A set of terminals that correspond to the controls and indicators of that VI, similar
to the parameter list of a function call in text-based programming languages.
The connector pane defines the inputs and outputs you can wire to the VI so
you can use it as a subVI.

Patterns
A connector pane receives data at its input terminals and passes the data to the block diagram
code through the front panel controls and receives the results at its output terminals from the
front panel indicators. The connector pane is displayed next to the icon on the front panel
window. You can select from many different patterns depending on how many inputs and
outputs are required.
Assigning Terminals
Click the connector pane terminal and then click the front panel control or indicator to assign
the terminal.

1 5

2
6
3

4 7

Standards
The standard connector pane, shown in the following figure is 4 x 2 x 2 x 4.
Use the following guidelines when assigning connector pane terminals:
• References on the top
• Error clusters on the bottom
• Inputs on the left
• Outputs on the right
• Unused terminals can be assigned later if you modify the VI
D. Documentation
Objective: Explain how to document code in LabVIEW using descriptions and tip strips, and describe
four methods for documenting code on the block diagram.

Creating Descriptions and Tip Strips


Create descriptions and tip strips for front panel objects in the properties dialog box for the
object. Create descriptions for VIs on the Documentation page of the in the VI Properties dialog
box.

2
1

E. Using SubVIs
Objective: Demonstratehow to place subVIs on the block diagram, explain terminal settings and
error handling, and create subVIs from a section of existing code.

Placing SubVIs on the Block Diagram


Place a Sub VI on the block diagram in one of the following ways:
• Click Select a VI on the Functions palette.
• Drag the VI from the Project Explorer Window.
• Drag the Icon from an open VI.
• Use Quick Drop to search for the VI by name.
Terminal Settings
You can designate which inputs and outputs are required, recommended, and optional to
prevent users from forgetting to wire subVI terminals. LabVIEW sets inputs and outputs of VIs
you create to Recommended by default. Set a terminal to required only if the VI must have the
input to run properly.

In the Context Help window, terminal labels appear differently depending on their setting.
Appearance Meaning Description

Bold Required The block diagram containing the subVI will be broken if you do
not wire the required inputs.

Plain Recommended
The block diagram containing the subVI can execute if you do
not wire the recommended or optional
Dimmed Optional terminals. If you do not wire the terminals, the VI does not
generate any warnings.

Handling Errors
Use a Case structure to handle errors passed into the subVI.
Convert a Section of a VI to a SubVI
Simplify your block diagram by converting sections of the block diagram into subVIs.
1. Select the section of the block diagram to convert.
2. Select Edit»Create SubVI.
3. Double-click the icon to open the subVI and edit the icon and connector pane.

Additional Resources

Learn More About LabVIEW Help Topic or ni.com


SubVIs Creating SubVIs
Customizing VIs
Placing SubVIs on Block Diagrams

Icons Using Icons


Creating Icons

Documentation Creating Object Descriptions and Tip Strips


Creating Documentation
Creating and Editing VI Descriptions

8 Acquiring
measurements
from hardware
A. Measurement Fundamentals with NI DAQ Hardware
Objective: Recognize the components of a DAQ system and practice connecting to hardware.

DAQ—Measuring Physical Phenomenon with a Computer


By using NI DAQ systems and LabVIEW, you can customize all aspects of data collection.

Data acquisition The process of measuring an electrical or physical phenomenon with a


computer. A DAQ system consist of a sensor, NI DAQ device, and a computer
running LabVIEW.
The following table lists common sensors and the phenomenon they measure.

Sensor Phenomenon

Thermocouple, RTD, thermistor Temperature

Photo sensor Light

Microphone Sound

Strain gage, piezoelectric transducer Force and Pressure

Potentiometer, LVDT, optical encoder Position and Displacement

Accelerometer Acceleration

pH probe pH

You can group real-world signals as analog, digital or counters.

Signal Type Description Examples

Analog Signals that vary continuously Temperature, current


Digital Electrical signals that transfer binary data, such as LEDs, switches
on/off or true/false.

Using NI MAX to Examine a DAQ


Device
Goal
Use MAX to examine, configure, and test a device.

Implementation
Complete the following steps to examine the configuration for the DAQ device in the computer
using MAX. Use the test routines in MAX to confirm operation of the device. If you do not have
a DAQ device, you can simulate a device using the instructions in step 3.
1. Launch MAX by selecting Start»Programs»NI MAX or by double-clicking the NI MAX icon on
your desktop. MAX searches the computer for installed National Instruments hardware and
displays the information.

2. If you have a DAQ device installed, skip step 3 and go to the Examining the DAQ Device
Settings section.

3. Create an NI-DAQmx simulated device to allow you to complete the exercises without
hardware.

 Right-click Devices and Interfaces and select Create New from the shortcut menu.
 In the Create New dialog box, select Simulated NI-DAQmx Device or Modular
Instrument.

 Click the Finish button.


 In the Create Simulated NI-DAQmx Device dialog box, select M Series DAQ» NI PCI 6225.
4. BNC-2120 Terminal Block

A terminal block consists of screw or spring terminals for connecting signals or other sensors.
A cable transports the signal from the terminal block to the DAQ device.

Examining the DAQ Device Settings


1. Expand the Devices and Interfaces section.
2. Select the device that is connected to your machine. Green icons represent real devices and
yellow icons represent simulated devices. You might have a different device installed, and
some of the options shown might be different.

MAX displays National Instruments hardware and software in the computer. The device alias
appears in quotes following the device type. The Data Acquisition VIs use this device alias to
determine which device performs DAQ operations. MAX also displays the attributes of the
device such as the system resources that the device uses. Figure 8-2 shows the simulated
PCI-6225 device.

3. Select the Device Routes tab at the bottom of MAX to see detailed information about the
internal signals that can be routed to other destinations on the device, as shown in Figure 8-
3. This is a powerful resource that gives you a visual representation of the signals
that are available to provide timing and synchronization with components that are on the
device and other external devices.
Device Routes

4. Select the Settings tab, as shown in Figure 8-4, to see information about the last time the
device was calibrated both internally and externally. Not all devices contain calibration
information.
Calibration

5. If you are using a physical device, right-click the NI-DAQmx device in the configuration tree
and select Self-Calibrate to update the built-in calibration constants and calibrate the DAQ
device using a precision voltage reference source. When the device has been calibrated,
information in the Self-Calibration section updates. Skip this step if you are using a simulated
device.

Testing the DAQ Device Components


1. Click the Self-Test button in MAX to test the device. The device should pass the test because
it is already configured.

2. Click the Test Panels button to test the individual functions of the DAQ device, such as analog
input and output. The Test Panels dialog box appears.

 Use the Analog Input tab to test the various analog input channels on the DAQ device.
Click the Analog Input tab. Click the Start button to acquire data from analog input
channel 0 and click the Stop button when you finish.

– If you are using the BNC-2120, make sure the switch over the AI 0 connector is in the
Temp. Ref. position to connect the temperature sensor to ai0. Place your finger on
the sensor to see the voltage rise.

– If you are using a simulated device, a sine wave is shown on all input channels.
 Use the Analog Output tab to set up a single voltage or sine wave on one of the DAQ
device analog output channels. Click the Analog Output tab.

– Select Sinewave Generation in the Mode drop-down menu and click the Start
button. MAX generates a continuous sine wave on analog output channel 0.

– If you have hardware installed, you can read the sine wave that channel 0 outputs.
On the BNC-2120, wire Analog Out Ch0 to Analog In Ch1. Click the Analog Input tab
in the Test Panels dialog box and select Dev1/ai1 from the Channel Name drop-down
menu. Click the Start button to acquire data from analog input channel 1 . MAX
displays the sine wave from analog output channel 0.

 Use the Digital I/O tab to test the digital lines on the DAQ device. Click the Digital I/O
tab.

– In the Select Direction section, set lines 0 through 3 as output as shown in Figure 8-
5.
Digital I/O Line Direction

– Click Start to begin the digital output test, then toggle the switches in the Select State
section shown in Figure 8-6. If you have a BNC-2120, toggling the switches turns the
LEDs on or off. Notice that the LEDs use negative logic.
Digital I/O Switches

– Click Stop to stop the digital output test.

 Use the Counter I/O tab to determine if the DAQ device counter/timers are functioning
properly. Click the Counter I/O tab.

– If you have hardware installed, you can verify counter/timer operations by selecting
Edge Counting from the Mode drop-down menu and clicking the Start button. The
Counter Value indicator increments rapidly. Click Stop to stop the counter test.
 Click the Close button to close the Test Panel dialog box and return to MAX.

Three Ways to Connect with a DAQ Device

NI MAX DAQ Assistant DAQmx API

Connecting to a DAQ Device Using MAX


MAX lets you quickly test the connection to your DAQ device and configure the hardware, if
necessary. With it you can also create simulated DAQ devices to create and test your
application even if you don't have hardware available.

Access MAX by double-clicking the NI MAX desktop icon or selecting Tools»Measurement &
Automation Explorer in LabVIEW.
Connecting Using LabVIEW DAQmx VIs
The LabVIEW DAQmx VIs let you control your hardware with finer options then the DAQ
Assistant Express VI. The DAQmx VIs also let you make the measurement or generation you
want to perform globally accessible from any application.

A basic DAQmx application involves the following process.


• Create task
• Configure task
• Start task
• Acquire or generate data
• Clear task

B. Automating Non-NI Instruments


Objective: Recognize the components of an instrument control system and practice connecting
to hardware.

LabVIEW controls instruments through different buses.


LabVIEW can control stand-alone instruments, such as third-party oscilloscopes or analyzers, so
you can automate instrument-based processes and consolidate multiple instrument tasks into
one development environment.

Hardware connectivity The physical cable connecting the instrument. Also, the
communication protocol, or bus.

A basic instrument control system consists of an instrument, hardware


connectivity, and a computer running LabVIEW.
Multimedia: Automating Non-NI Instruments
Common bus types include GPIB, serial, USB, and Ethernet. Different buses have different
capabilities when it comes to latency and bandwidth. Instruments often have multiple ports for
hardware connectivity.

Configuring Instrument Control in NI MAX


Before creating your instrument control application, you should test communication with the
instrument using NI MAX.
Simplify Instrument Control
Controlling your benchtop instrument using LabVIEW helps you save time by automating
processes using the instrument such as testing and data logging. Instrument control in LabVIEW
also lets you consolidate multiple instrument tasks into one development environment.

LabVIEW instrument drivers, available on the Instrument Driver Network at ni.com/idnet,


provide the following additional benefits:
• Provide a high-level API, meaning that VIs perform multiple instructions, thereby simplifying
the code.
• Do not require knowledge of different bus protocols, such as GPIB or serial, that you might
use to connect with the instrument.
• Do not require learning low-level programming commands for each instrument.

Instrument Driver VIs for an Agilent Digital Multimeter


Every application that uses an instrument driver has a similar sequence of events: Initialize,
Configure, Read Data, and Close.The block diagram initializes the Agilent 34401 digital
multimeter (DMM), uses a configuration VI to choose the resolution and range, select the
function, and enable or disable auto range, uses a data VI to read a single measurement, closes
the instrument, and checks the error status.
Category Description

Initialize The Initialize VI establishes communication with the instrument and is the first
instrument driver VI called.

Configure Configure VIs are software routines that configure the instrument to perform specific
operations. After calling these VIs, the instrument is ready to take measurements or
stimulate a system.

Action/Status Action/Status VIs command the instrument to carry out an action (for example,
arming a trigger) or obtain the current status of the instrument or pending operations.

Data The data VIs transfer data to or from the instrument.

Utility Utility VIs perform a variety of auxiliary operations, such as reset and self-test.

Close The close VI terminates the software connection to the instrument. This is the last
instrument driver VI called.
9 Accessing Files in
labview
A.Accessing Files from LabVIEW
Objective: Identify the steps for writing and reading files from a LabVIEW application.

Typical File I/O Operations


File I/O operations pass data to and from files.

1 2 3 4

1 Open File 3 Close File


2 Read/Write File 4 Check for Errors

File I/O Palette for File Operation Functions


The File I/O palette includes functions to create or open a file, read data from or write data to
the file, and close the file. You can also use the functions to create directories; move, copy, or
delete files; list directory contents; change file characteristics; or manipulate paths.
B. High-Level and Low-Level File I/O Functions
Objective: Identify when to use high-level and low-level File I/O functions.

High-Level File I/O Functions Low-Level File I/O Functions

Perform three steps of the file I/O process. Perform one step of the file I/O process.
( open/write/close )

Simplify block diagram. Provide finer control of file access.

Create unnecessary resource overhead when used in loops. Save memory resources when used in loops.

Are good to use when writing to a file in a single operation. Are good to use when streaming data to disk.

High-Level File I/O


High-level File I/O functions combine three steps (open, read/write, close) for common file I/O
operations. High-level file I/O functions simplify the block diagram but might not provide the
control or configuration you need for your application.
The following table compares the high-level file I/O functions.

Function Type of Data File Formats

Write To Spreadsheet File 1D or 2D arrays Text


Read From Spreadsheet File

Write To Measurement File .lvm (text)


Read From Measurement File Signals (dynamic data types) .tdms (binary)

Write Waveforms to File Waveform data Text


Read Waveforms from File

Low-Level File I/O


Low-level File I/O functions provide individual functions for each step in file I/O operations. For
example, one function opens an ASCII file, one function reads an ASCII file, and one function
closes an ASCII file.

1 2 3 4
File Refnums
File refnums identify unique file I/O sessions.

Streaming Data to Disk


Disk streaming is a technique for keeping files open while you perform multiple write operations.
Use low-level functions when file I/O is occurring within a loop to save memory resources .

String Functions
To write data to a text file, you must first convert the data into a string data type. Use the items
from the String palette to convert numerics and other data types to text.
C.Comparing File Formats
Objective: Recognize different options for logging data to disk.

Common Log File Formats


LabVIEW can use or create the following file formats: Binary, ASCII, LVM, and TDMS.
• ASCII—An ASCII file is a specific type of binary file that is a standard used by most programs.
It consists of a series of ASCII codes. ASCII files are also called text files.
• 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. The .lvm file includes
information about the data, such as the date and time the data was generated. This file
format is a specific type of ASCII file created for LabVIEW.
• Binary—Binary files are the underlying file format of all other file formats.
• TDMS—This file format is a specific type of binary file created for National Instruments
products. It actually consists of two separate files—a binary file that contains data and stores
• properties about the data, and a binary index file that provides consolidated information on
all the attributes and pointers in the binary file.

• Comparing File Formats


• Use text files when you want to access the file from another application, if disk space
and file I/O speed are not crucial, if you do not need to perform random access read or
writes, and if numeric precision is not important.

ASCII Binary TDMS LVM

Easily Exchangeable X X X

Small disk footprint X X

Random read/write access X X X

Inherent attributes X X

High-speed streaming X

Learn More About LabVIEW Help Topic

File I/O File I/O

Streaming data to disk Saving Memory using Disk Streaming

Streaming External Data to a TDMS File (Windows)

File Formats for file I/O Determining Which File Format to Use

Converting Numbers into Strings


10 using sequential and
state machine
programming
A.Using Sequential Programming
Objective: Use dataflow to ensure sequential execution of nodes.

Why Use Sequential Programming?


Sequential programming ensures the execution order of tasks. In the following block diagram
there is no mechanism to force the execution order of these events. Any one of these events
could happen first.

Flow-Through Parameters
To enforce sequential programming in LabVIEW, you can complete sequential tasks by placing
each task in a separate subVI, and wiring the subVIs in the order you want them to execute using
the error cluster wires.

However, in this example, only two of the tasks have a error cluster. Using the error clusters,
you can force the execution order of the two DAQ Assistants, but not the One Button Dialog
functions, as shown in the following figure.
Sequence Structures
A Sequence structure contains one or more subdiagrams, or frames, that execute in sequential
order; a frame cannot begin execution until everything in the previous frame has completed
execution.

Avoid Overuse of Sequence Structures


To take advantage of the inherent parallelism in LabVIEW, avoid overusing Sequence structures.
Below are some caveats while using Sequence structures:
• Sequence structures guarantee the order of execution, but prohibit parallel operations.
• You cannot stop the execution part way through the sequence.
• Use Sequence structures sparingly because they do not enforce error checking and will
continue to go through a sequence even after errors are detected.
B. Using State Programming
Objective: Describe the functionality represented by a state transition diagram.

Why Use State Programming?


• Change the order of a sequence
• Repeat an item in sequence more often than others
• Execute only if certain conditions are met
• Stop the program immediately

State Transition Diagram


A state transition diagram is a 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.

C. State Machines
Objective: Determine when to use a state machine.

What is a State Machine?


A state machine is a common and useful design pattern in LabVIEW that usually has a start-up
and shut-down state, but also contains other states. State machines can implement any
algorithm that can be explicitly described by a state diagram or flowchart.
When to Use a State Machine
Use a state machine for the following applications:
• Sequential process
• UI-Driven process

Sequential Process
• A state represents each segment of the process.
• Depending on the result of each state’s test, a different state might be called.
• Can happen continually, resulting in an in-depth analysis of the process you are testing

UI-Driven Process
• Different user actions process different code and act as a state in the state machine.
• Each segment can lead to another segment for further processing or wait for another user action.
• The state machine constantly monitors the user for the next action to take.
Multimedia: Building State Machines
Complete the multimedia module, Building State Machines, available in the
folder to learn about the following topics.
• State Machine Infrastructure
• State Machine Transitions
– Single Default
– Select Function
– Case Structure
– Transition Array

Course Project Transition Diagram


Consider the following example. An application acquires a temperature every half second,
analyzes each temperature to determine if the temperature is too high or too low, and alerts the
user if there is a danger of heatstroke or freeze. The application logs the data if a warning occurs.
If the user has not clicked the stop button, the entire process repeats. The following figure shows
the state transition diagram for this temperature warning application.
A Additional
information and
resources

You might also like