LABVIEW CORE 1

58
LabVIEW TM Core 1 Participant Guide Course Software Version 2014 November 2014 Edition Part Number 326292A-01 LabVIEW Core 1 Participant Guide Copyright © 1993–2014 National Instruments. All rights reserved. Under the copyright laws, this publication may not be reproduced or transmitted in any form, electronic or mechanical, including photocopying, recording, storing in an information retrieval system, or translating, in whole or in part, without the prior written consent of National Instruments Corporation. National Instruments respects the intellectual property of others, and we ask our users to do the same. NI software is protected by copyright and other intellectual property laws. Where NI software may be used to reproduce software or other materials belonging to others, you may use NI software only to reproduce materials that you may reproduce in accordance with the terms of any applicable license or other legal restriction. End-User License Agreements and Third-Party Legal Notices You can find end-user license agreements (EULAs) and third-party legal notices in the following locations: Notices are located in the <National Instruments>\_Legal Information and <National Instruments> directories. EULAs are located in the <National Instruments>\Shared\MDF\Legal\License directory. Review <National Instruments>\_Legal Information.txt for more information on including legal information in installers built with NI products.

description

GUIA DE EJERCICIOS DEL MODULO DE LABVIEW PARA DESARROLLAR EL MODULO DE LABVIEW CORE 1

Transcript of LABVIEW CORE 1

Page 1: LABVIEW CORE 1

LabVIEWTM Core 1 Participant Guide

Course Software Version 2014November 2014 EditionPart Number 326292A-01

LabVIEW Core 1 Participant Guide

Copyright© 1993–2014 National Instruments. All rights reserved. Under the copyright laws, this publication may not be reproduced or transmitted in any form, electronic or mechanical, including photocopying, recording, storing in an information retrieval system, or translating, in whole or in part, without the prior written consent of National Instruments Corporation.

National Instruments respects the intellectual property of others, and we ask our users to do the same. NI software is protected by copyright and other intellectual property laws. Where NI software may be used to reproduce software or other materials belonging to others, you may use NI software only to reproduce materials that you may reproduce in accordance with the terms of any applicable license or other legal restriction.

End-User License Agreements and Third-Party Legal NoticesYou can find end-user license agreements (EULAs) and third-party legal notices in the following locations:

• Notices are located in the <National Instruments>\_Legal Information and <National Instruments> directories.

• EULAs are located in the <National Instruments>\Shared\MDF\Legal\License directory.

• Review <National Instruments>\_Legal Information.txt for more information on including legal information in installers built with NI products.

Page 2: LABVIEW CORE 1

TrademarksRefer to the NI Trademarks and Logo Guidelines at ni.com/trademarks for more information on National Instruments trademarks.

ARM, Keil, and µVision are trademarks or registered of ARM Ltd or its subsidiaries.

LEGO, the LEGO logo, WEDO, and MINDSTORMS are trademarks of the LEGO Group.

TETRIX by Pitsco is a trademark of Pitsco, Inc.

FIELDBUS FOUNDATION™ and FOUNDATION™ are trademarks of the Fieldbus Foundation.

EtherCAT® is a registered trademark of and licensed by Beckhoff Automation GmbH.

CANopen® is a registered Community Trademark of CAN in Automation e.V.

DeviceNet™ and EtherNet/IP™ are trademarks of ODVA.

Go!, SensorDAQ, and Vernier are registered trademarks of Vernier Software & Technology. Vernier Software & Technology and vernier.com are trademarks or trade dress.

Xilinx is the registered trademark of Xilinx, Inc.

Taptite and Trilobular are registered trademarks of Research Engineering & Manufacturing Inc.

FireWire® is the registered trademark of Apple Inc.

Linux® is the registered trademark of Linus Torvalds in the U.S. and other countries.

Handle Graphics®, MATLAB®, Real-Time Workshop®, Simulink®, Stateflow®, and xPC TargetBox® are registered trademarks, and TargetBox™ and Target Language Compiler™ are trademarks of The MathWorks, Inc.

Tektronix®, Tek, and Tektronix, Enabling Technology are registered trademarks of Tektronix, Inc.

The Bluetooth® word mark is a registered trademark owned by the Bluetooth SIG, Inc.

The ExpressCard™ word mark and logos are owned by PCMCIA and any use of such marks by National Instruments is under license.

The mark LabWindows is used under a license from Microsoft Corporation. Windows is a registered trademark of Microsoft Corporation in the United States and other countries.

Other product and company names mentioned herein are trademarks or trade names of their respective companies.

Members of the National Instruments Alliance Partner Program are business entities independent from National Instruments and have no agency, partnership, or joint-venture relationship with National Instruments.

PatentsFor patents covering National Instruments products/technology, refer to the appropriate location: Help»Patents in your software, the patents.txt file on your media, or the National Instruments Patent Notice at ni.com/patents.

Support

Worldwide Technical Support and Product Informationni.com

Worldwide OfficesVisit ni.com/niglobal to access the branch office websites, which provide up-to-date contact information, support phone numbers, email addresses, and current events.

National Instruments Corporate Headquarters11500 North Mopac Expressway Austin, Texas 78759-3504 USA Tel: 512 683 0100For further support information, refer to the Additional Information and Resources appendix. To comment on National Instruments documentation, refer to the National Instruments website at ni.com/info and enter the Info Code feedback.

Page 3: LABVIEW CORE 1

Table of Contents

© National Instruments | iii

Student GuideA. NI Certification ....................................................................................ixB. Course Description ...............................................................................ixC. What You Need to Get Started ..............................................................xD. Installing the Course Software ...............................................................xE. Course Goals.......................................................................................x

Lesson 1Navigating LabVIEW

A. What is LabVIEW? ...............................................................................1-3B. Project Explorer ...................................................................................1-4C. Parts of a VI........................................................................................1-6D. Front Panel .........................................................................................1-7E. Block Diagram ....................................................................................1-10Exercise 1-1 Concept: Exploring a VI ......................................................1-15F. Searching for Controls, VIs, and Functions ..............................................1-20Exercise 1-2 Concept: Locating Controls, Functions, and VIs .....................1-22

Lesson 2Creating Your First Application

A. Dataflow.............................................................................................2-3B. LabVIEW Data Types............................................................................2-7C. Tools for Programming, Cleaning and Organizing Your VI ..........................2-11Exercise 2-1 Selecting a Tool .................................................................2-13D. Building a Basic VI ...............................................................................2-19Exercise 2-2 Simple AAV VI ..................................................................2-23

Lesson 3Troubleshooting and Debugging VIs

A. Correcting Broken VIs...........................................................................3-3B. Debugging Techniques..........................................................................3-4Exercise 3-1 Debugging ........................................................................3-9C. Error Handling......................................................................................3-17

Lesson 4Using Loops

A. Loops Review......................................................................................4-3B. While Loops ........................................................................................4-7Exercise 4-1 Pass Data Through Tunnels .................................................4-8C. For Loops............................................................................................4-17D. Timing a VI .........................................................................................4-18

Page 4: LABVIEW CORE 1

Table of Contents

iv | ni.com

E. Data Feedback in Loops ....................................................................... 4-19Exercise 4-2 Calculating Average Temperature........................................ 4-21F. Plotting Data ...................................................................................... 4-24Exercise 4-3 Temperature Monitor VI—Plot Multiple Temperatures ............ 4-26

Lesson 5Creating and Leveraging Data Structures

A. Arrays ............................................................................................... 5-3B. Common Array Functions..................................................................... 5-5C. Polymorphism..................................................................................... 5-8D. Auto-Indexing..................................................................................... 5-9Exercise 5-1 Manipulating Arrays .......................................................... 5-12E. Clusters ............................................................................................. 5-20Exercise 5-2 Temperature Warnings VI—Clusters .................................... 5-25F. Type Definitions.................................................................................. 5-33Exercise 5-3 Temperature Warnings VI—Type Definition .......................... 5-35

Lesson 6Using Decision-Making Structures

A. Case Structures .................................................................................. 6-3Exercise 6-1 Temperature Warnings With Error Handling .......................... 6-8B. Event-Driven Programming ................................................................... 6-14Exercise 6-2 Converting a Polling Design to an Event Structure Design....... 6-18

Lesson 7Modularity

A. Understanding Modularity .................................................................... 7-3B. Icon................................................................................................... 7-4C. Connector Pane .................................................................................. 7-6D. Documentation ................................................................................... 7-8E. Using SubVIs...................................................................................... 7-9Exercise 7-1 Temperature Warnings VI—As SubVI................................... 7-12

Lesson 8Acquiring Measurements from Hardware

A. Measurement Fundamentals with NI DAQ Hardware................................ 8-3Exercise 8-1 Using NI MAX to Examine a DAQ Device ............................. 8-5Exercise 8-2 Programming with the DAQmx API...................................... 8-14B. Automating Non-NI Instruments ............................................................ 8-18Exercise 8-3 Instrument Configuration with NI MAX ................................ 8-20Exercise 8-4 Exploring Instrument Drivers............................................... 8-25

Lesson 9Accessing Files in LabVIEW

A. Accessing Files from LabVIEW.............................................................. 9-3B. High-Level and Low-Level File I/O Functions ........................................... 9-3Exercise 9-1 Exploring High-Level File I/O ............................................... 9-5Exercise 9-2 Temperature Monitor VI—Logging Data ............................... 9-10C. Comparing File Formats ....................................................................... 9-15

Lesson 10Using Sequential and State Machine Programming

A. Using Sequential Programming.............................................................. 10-3B. Using State Programming..................................................................... 10-5C. State Machines................................................................................... 10-6Exercise 10-1 Weather Station Project ..................................................... 10-9

Page 5: LABVIEW CORE 1

LabVIEW Core 1 Participant Guide

© National Instruments | v

Appendix AAdditional Information and Resources

Page 6: LABVIEW CORE 1
Page 7: LABVIEW CORE 1

Student Guide

In this student guide, you will learn about the LabVIEW Learning Path, the course description, and the items you need to get started in the LabVIEW Core 1 course.

Topics+ NI Certification

+ Course Description

+ What You Need to Get Started

+ Installing the Course Software

+ Course Goals

Page 8: LABVIEW CORE 1
Page 9: LABVIEW CORE 1

LabVIEW Core 1 Participant Guide

© National Instruments | ix

A.NI CertificationThe 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. Refer to ni.com/training for more information about NI Certification.

B. Course DescriptionThe 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.

Note For Participant Guide updates and corrections, refer to ni.com/info and enter the Info Code core1.

Several exercises use a plug-in multifunction data acquisition (DAQ) device connected to a DAQ Signal Accessory or BNC-2120 containing a temperature sensor, function generator, and LEDs.

If you do not have this hardware, you still can complete the exercises. Alternate instructions are provided for completing the exercises without hardware. You also can substitute other hardware for those previously mentioned. For example, you can use another National Instruments DAQ device connected to a signal source, such as a function generator.

Certified LabVIEWAssociate Developer

Certified LabVIEWDeveloper

Certified LabVIEWArchitect

LabVIEWConnectivity

LabVIEWPerformance

AdvancedArchitecturesin LabVIEW

ManagingSoftware

Engineeringin LabVIEW

Object-OrientedDesign &

Programmingin LabVIEW

LabVIEW Learning Path

LabVIEWCore 1

LabVIEWGetting Started

LabVIEWCore 3LabVIEW

Core 2

Page 10: LABVIEW CORE 1

Student Guide

x | ni.com

C.What You Need to Get StartedBefore 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:

D. Installing the Course SoftwareComplete 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.

Exercise files are located in the <Exercises>\LabVIEW Core 1\ folder.

Note Folder names in angle brackets, such as <Exercises>, refer to folders on the root directory of your computer.

E. Course GoalsThis 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

Directory Table Head

Exercises Contains VIs used in the course

Solutions Contains completed course exercises

Page 11: LABVIEW CORE 1

LabVIEW Core 1 Participant Guide

© National Instruments | xi

This course does not describe the following:

• Every built-in VI, function, or object; refer to the LabVIEW Help for more information about LabVIEW features not described in this course

• Analog-to-digital (A/D) theory

• Operation of the GPIB bus

• Developing an instrument driver

• Developing a complete application for any student in the class; refer to the NI Example Finder, available by selecting Help»Find Examples, for example VIs you can use and incorporate into VIs you create

Page 12: LABVIEW CORE 1
Page 13: LABVIEW CORE 1

5 Creating and Leveraging Data Structures

In this lesson you will learn about arrays, clusters, and type definitions and be able to identify applications where using these data structures can be beneficial.

Topics+ Arrays

+ Common Array Functions

+ Polymorphism

+ Auto-Indexing

+ Clusters

+ Type Definitions

ExercisesExercise 5-1 Manipulating Arrays

Exercise 5-2 Temperature Warnings VI—Clusters

Exercise 5-3 Temperature Warnings VI—Type Definition

Page 14: LABVIEW CORE 1
Page 15: LABVIEW CORE 1

LabVIEW Core 1 Participant Guide

© National Instruments | 5-3

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

Arrays

Note Array indexes in LabVIEW are zero-based. The index of the first element in the array, regardless of its dimension, is zero.

1D and 2D ExamplesArrays 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.

• 2D array:

For example, LabVIEW represents a table of data with rows and columns as a 2D array.

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.

0 1 2 3 4 5 6 7

0

1

2

3

4

5

6

7

Column Index

Row

Inde

x

Page 16: LABVIEW CORE 1

Lesson 5 Creating and Leveraging Data Structures

5-4 | ni.com

2D ArraysA 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 ArraysAn 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.

Demonstration: Viewing Arrays

Create an array control or indicator on the front panel by adding an array shell to the front panel, as shown in the following front panel, and dragging a data object or element, which can be a numeric, Boolean, string, path, refnum, or cluster control or indicator, into the array shell.

To create an array constant on the block diagram, select an array constant on the Functions palette, place the array shell on the block diagram, and place a string constant, numeric constant, a Boolean constant, or cluster constant in the array shell.

RestrictionsYou cannot create arrays of arrays. However, you can use a multidimensional array or create an array of clusters where each cluster contains one or more arrays. Also, you cannot create an array of subpanel controls, tab controls, .NET controls, ActiveX controls, charts, or multi-plot XY graphs.

1 Uninitialized array 2 Initialized array

21

Page 17: LABVIEW CORE 1

LabVIEW Core 1 Participant Guide

© National Instruments | 5-5

B. Common Array FunctionsObjective: Create and manipulate arrays using built-in array functions.

Multimedia: Common Array FunctionsFunctions 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 ArrayCreates an n-dimensional array in which every element is initialized to the value of element.

Insert Into ArrayInserts an element or subarray at the point you specify in index.

Page 18: LABVIEW CORE 1

Lesson 5 Creating and Leveraging Data Structures

5-6 | ni.com

Delete From ArrayDeletes 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 & MinReturns the maximum and minimum values in array, along with the indexes for each value.

Search 1D ArraySearches 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.

Page 19: LABVIEW CORE 1

LabVIEW Core 1 Participant Guide

© National Instruments | 5-7

Activity 5-1: Using Array FunctionsGoal: Complete the highlighted portion in each VI

DescriptionEach of the VIs shown has missing information. Determine what belongs in the highlighted section.

Block Diagram Result

Page 20: LABVIEW CORE 1

Lesson 5 Creating and Leveraging Data Structures

5-8 | ni.com

C. PolymorphismObjective: Understand the ability of various VIs to accept input data of different data types.

Polymorphism

Arithmetic Functions Are PolymorphicLabVIEW arithmetic functions are polymorphic.

Polymorphism The ability of VIs and functions to automatically adapt to accept input data of different data types.

Functions are polymorphic to varying degrees—none, some, or all of their inputs can be polymorphic.

Page 21: LABVIEW CORE 1

LabVIEW Core 1 Participant Guide

© National Instruments | 5-9

D.Auto-IndexingObjective: Use auto-indexed inputs and outputs to create graphs and 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. The tunnel image changes from a solid square to the image to indicate auto-indexing.

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

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

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.

2

1 3

Page 22: LABVIEW CORE 1

Lesson 5 Creating and Leveraging Data Structures

5-10 | ni.com

Charts vs. Graphs—Single-PlotCharts are generally used inside the While Loop and graphs are generally outside the While Loop.

Auto-Indexing with a Conditional TunnelYou can determine what values LabVIEW writes to the loop output tunnel based on a condition you specify.

For example, consider the following block diagram. The array Input Array contains the following elements: 7, 2, 0, 3, 1, 9, 5, and 7. Because of the conditional tunnel, the Values less than 5 array contains only the elements 2, 0, 3, and 1 after this loop completes all iterations.

Creating Two-Dimensional ArraysUse two For Loops, nested one inside the other, to create a 2D array.

1 Right-click the loop output tunnel and selecting Tunnel Mode»Conditional from the shortcut menu.

1 The inner loop creates the column elements and the outer loop creates the row elements.

1

Page 23: LABVIEW CORE 1

LabVIEW Core 1 Participant Guide

© National Instruments | 5-11

Auto-Indexing InputUse 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

Auto-Indexing Input—Different Array SizesIf 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 executes the number of times equal 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.

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

21

1

Page 24: LABVIEW CORE 1

Lesson 5 Creating and Leveraging Data Structures

5-12 | ni.com

Exer

cise

5-1

Man

ipul

atin

g A

rray

s

Goa

lM

anip

ulat

e ar

rays

usi

ng v

ario

us L

abV

IEW

fun

ctio

ns.

Des

crip

tion

You

are

giv

en a

VI a

nd a

sked

to

enha

nce

it f

or a

var

iety

of

purp

oses

. The

fro

nt p

anel

of

this

VI i

s bu

ilt. Y

ou c

ompl

ete

the

bloc

k di

agra

m t

o pr

actice

sev

eral

di

ffer

ent

tech

niqu

es t

o m

anip

ulat

e ar

rays

.

Impl

emen

tation

1.

Ope

n Manipulating Arrays.lvproj in

the

<Exercises>\LabVIEW Core 1\Manipulating Arrays d

irect

ory.

2.

Ope

n A

rray

Man

ipul

atio

n V

I fro

m t

he P

roje

ct E

xplo

rer

win

dow

. The

fro

nt p

anel

, sh

own

in F

igur

e5-1

, is

alre

ady

built

for

you

.

Figu

re 5

-1.

Arr

ay M

anip

ulat

ion

VI F

ront

Pan

el

Page 25: LABVIEW CORE 1

LabVIEW Core 1 Participant Guide

© National Instruments | 5-13

3.

Ope

n th

e bl

ock

diag

ram

and

com

plet

e ea

ch o

f th

e ca

ses

that

cor

resp

ond

to t

he t

abs

on t

he f

ront

pan

el a

s sh

own

in F

igur

es5-2

thr

ough

5-8

.

Figu

re 5

-2.

Arr

ay M

anip

ulat

ion

VI—

Con

cate

nate

Cha

nnel

s C

ase

4.

Sw

itch

to

the

fron

t pa

nel a

nd t

est

the

Con

cate

nate

Cha

nnel

s ca

se.

O

n th

e fr

ont

pane

l, cl

ick

the

Con

cate

nate

Cha

nnel

s ta

b.

Run

the

VI an

d no

tice

tha

t th

e si

ne w

ave

is c

onca

tena

ted

with

a sq

uare

wav

e.

5.

Sto

p th

e V

I.

6.

Sw

itch

to

the

bloc

k di

agra

m a

nd s

elec

t th

e A

dd/S

ubtr

act

Cha

nnel

s ca

se.

1Bui

ld A

rray

—Ex

pand

thi

s no

de t

o ac

cept

tw

o in

puts

, an

d th

en r

ight

-clic

k an

d se

lect

Con

cate

nate

inpu

ts f

rom

the

sho

rtcu

t m

enu.

2W

ire t

he s

ine

wav

e an

d sq

uare

wav

e ou

tput

s to

the

Bui

ld A

rray

fun

ctio

n to

cre

ate

a 1D

arr

ay w

ith

both

wav

efor

ms.

12

Page 26: LABVIEW CORE 1

Lesson 5 Creating and Leveraging Data Structures

5-14 | ni.com

7.

Com

plet

e th

e A

dd/S

ubtr

act

Cha

nnel

s ca

se a

s sh

own

in F

igur

e5-3

and

Fig

ure

5-4

.

Figu

re 5

-3. A

rray

Man

ipul

atio

n V

I—A

dd/S

ubtr

act

Cha

nnel

s Tru

e C

ase

Figu

re 5

-4.

Arr

ay M

anip

ulat

ion

VI—

Add

/Sub

trac

t C

hann

els

Fals

e C

ase

1Sub

trac

t?—

Wire

thi

s to

the

cas

e se

lect

or t

erm

inal

so

that

the

cor

rect

cas

e ex

ecut

es w

hen

you

clic

k th

e Sub

trac

t? b

utto

n on

the

fro

nt p

anel

. 2

Cas

e Str

uctu

re—

Plac

e a

Sub

trac

t fu

nction

in t

he T

rue

case

, so

tha

t th

e V

I sub

trac

ts t

he e

lem

ents

of

the

arra

y w

hen

the

Sub

trac

t? b

utto

n on

the

fro

nt

pane

l is

pres

sed.

1W

hen

the

valu

e of

the

Sub

trac

t? B

oole

an c

ontr

ol is

Fal

se,

the

arra

y el

emen

ts a

re a

dded

.

12

1

Page 27: LABVIEW CORE 1

LabVIEW Core 1 Participant Guide

© National Instruments | 5-15

Not

eThi

s ca

se d

emon

stra

tes

poly

mor

phic

fun

ctio

nalit

y by

add

ing

and

subt

ract

ing

elem

ents

of

the

arra

y.

8.

Sw

itch

to

the

fron

t pa

nel a

nd t

est

the

Add

/Sub

trac

t C

hann

els

case

.

O

n th

e fr

ont

pane

l, cl

ick

the

Add

/Sub

trac

t C

hann

els

tab.

Run

the

VI.

C

lick

the

Sub

trac

t? b

utto

n an

d ob

serv

e th

e be

havi

or o

f su

btra

ctin

g th

e sq

uare

wav

e fr

om t

he s

ine

wav

e.

9.

Sto

p th

e V

I.

10.

Sw

itch

to

the

bloc

k di

agra

m a

nd s

elec

t th

e Sel

ect

a C

hann

el c

ase.

11.

Com

plet

e th

e Sel

ect

a C

hann

el c

ase

as s

how

n in

Fig

ure

5-5

.

Figu

re 5

-5. A

rray

Man

ipul

atio

n V

I—Sel

ect

a C

hann

el

1Bui

ld A

rray

—C

ombi

nes

the

sine

and

squ

are

wav

es in

to o

ne 2

D a

rray

.2

Inde

x A

rray

—Ex

trac

ts row

0 o

r 1 fro

m the

2D

arr

ay. T

he o

utpu

t fr

om thi

s fu

nction

is a

1D

arr

ay a

nd is

the

wav

efor

m y

ou s

elec

t w

ith

the

Sel

ect C

hann

el

cont

rol.

The

wav

efor

m is

dis

play

ed o

n th

e Sin

gle

Cha

nnel

of

Dat

a W

avef

orm

Gra

ph a

nd t

he S

ingl

e C

hann

el o

f D

ata

Arr

ay in

dica

tor.

3Sel

ect

Cha

nnel

—W

ire t

o th

e ro

w in

put

of t

he In

dex

Arr

ay f

unct

ion.

4A

rray

Siz

e—Bec

ause

you

are

usi

ng a

1D

arr

ay,

this

fun

ctio

n ou

tput

s a

scal

ar v

alue

.

12

3

4

Page 28: LABVIEW CORE 1

Lesson 5 Creating and Leveraging Data Structures

5-16 | ni.com

Not

eThe

Sel

ect

a C

hann

el c

ase

uses

a p

rope

rty

node

to

chan

ge t

he c

olor

of

the

grap

h pl

ot. Y

ou le

arn

abou

t Pr

oper

ty N

odes

Lab

VIE

W C

ore

2.

12.

Sw

itch

to

the

fron

t pa

nel a

nd t

est

the

Sel

ect

a C

hann

el c

ase.

O

n th

e fr

ont

pane

l, cl

ick

the

Sel

ect

a C

hann

el t

ab.

Run

the

VI.

Sw

itch

bet

wee

n C

hann

el 0

and

Cha

nnel

1 a

nd n

otic

e th

e di

ffer

ent

valu

es s

how

n in

the

Sin

gle

Cha

nnel

of

Dat

a A

rray

indi

cato

r.

13.

Sto

p th

e V

I.

14.

Sw

itch

to

the

bloc

k di

agra

m a

nd s

elec

t th

e W

avef

orm

Dat

a ca

se.

15.

Com

plet

e th

e W

avef

orm

Dat

a ca

se b

lock

dia

gram

as

show

n in

Fig

ure

5-6

.

The

wav

efor

m d

atat

ype

is a

spe

cial

kin

d of

clu

ster

tha

t co

ntai

ns a

dditio

nal t

imin

g in

form

atio

n ab

out

the

wav

efor

m.

Figu

re 5

-6.

Arr

ay M

anip

ulat

ion

VI—

Wav

efor

m D

ata

Not

ePo

lym

orph

ism

is t

he a

bilit

y of

VIs

and

fun

ctio

ns t

o au

tom

atic

ally

ada

pt t

o ac

cept

inpu

t da

ta o

f di

ffer

ent

data

typ

es, in

clud

ing

arra

ys,

scal

ars,

and

wav

efor

ms.

VIs

and

fun

ctio

ns a

re p

olym

oprh

ic t

o va

ryin

g de

gree

s.

1A

dd—

Use

s th

e va

lue

from

the

Off

set

cont

rol t

o m

odify

the

valu

e of

the

wav

efor

m in

the

wav

efor

m d

atat

ype.

Not

ice

the

valu

e fr

om t

he O

ffse

t co

ntro

l m

ust

be c

oerc

ed t

o be

use

d w

ith

the

wav

efor

m d

atat

ype.

1

Page 29: LABVIEW CORE 1

LabVIEW Core 1 Participant Guide

© National Instruments | 5-17

16.

Sw

itch

to

the

fron

t pa

nel a

nd t

est

the

Wav

efor

m D

ata

case

.

O

n th

e fr

ont

pane

l, cl

ick

the

Wav

efor

m D

ata

tab.

Run

the

VI.

C

hang

e th

e va

lue

of t

he O

ffse

t co

ntro

l and

not

ice

the

squa

re w

ave

mov

e on

the

Wav

efor

m D

ata

char

t.

17.

Sto

p th

e V

I.

18.

Sw

itch

to

the

bloc

k di

agra

m a

nd s

elec

t th

e A

ll D

ata

Cha

nnel

cas

e.

19.

Com

plet

e th

e A

ll D

ata

Cha

nnel

cas

e as

sho

wn

in F

igur

e5-7

.

Figu

re 5

-7.

Arr

ay M

anip

ulat

ion

VI—

All

Dat

a

1A

dd—

Mod

ify

the

sam

e da

ta in

one

arr

ay b

y ad

ding

the

val

ue o

f th

e C

hann

el 1

Off

set

to e

ach

elem

ent

of t

he a

rray

.2

For

Loop

—Ex

trac

ts e

ach

elem

ent

of t

he a

rray

usi

ng a

uto

inde

xing

so

that

the

Add

fun

ctio

n in

the

For

Loo

p ca

n ad

d th

e sc

alar

val

ue.

3Bui

ld A

rray

—Tak

es t

he t

wo

1D

arr

ays

and

build

s a

2D

arr

ay.

Each

1D

arr

ay b

ecom

es a

row

in t

he 2

D a

rray

.4

Arr

ay S

ize—

Out

puts

a 1

D a

rray

whe

re e

ach

elem

ent

show

s th

e si

ze o

f ea

ch d

imen

sion

. In

thi

s ex

erci

se, yo

u ha

ve 2

ele

men

ts o

f da

ta f

or t

he n

umbe

r of

row

s an

d co

lum

ns.

5A

ll D

ata

Cha

nnel

and

Dat

a C

hann

el A

rray

indi

cato

rs d

ispl

ay t

he s

ame

data

.

4

5

23

1

Page 30: LABVIEW CORE 1

Lesson 5 Creating and Leveraging Data Structures

5-18 | ni.com

Not

eThe

pol

ymor

phic

fun

ctio

nalit

y of

Lab

VIE

W f

unct

ions

allo

ws

you

to p

erfo

rm t

he s

ame

oper

atio

n on

eac

h el

emen

t w

itho

ut e

xtra

ctin

g th

e ar

ray

elem

ents

, as

you

do

with

the

two

Add

fun

ctio

ns in

the

All

Dat

a C

hann

el c

ase.

20.

Sw

itch

to

the

fron

t pa

nel a

nd t

est

the

All

Dat

a C

hann

el c

ase.

O

n th

e fr

ont

pane

l, cl

ick

the

All

Dat

a C

hann

el t

ab.

Run

the

VI.

C

hang

e th

e va

lue

of t

he C

hann

el 1

Off

set

cont

rol a

nd o

bser

ve t

he b

ehav

ior.

21.

Sto

p th

e V

I.

22.

Sw

itch

to

the

bloc

k di

agra

m a

nd s

elec

t th

e W

avef

orm

Sub

set

case

.

23.

Com

plet

e th

e W

avef

orm

Sub

set

case

as

show

n in

Fig

ure

5-8

.

Figu

re 5

-8. A

rray

Man

ipul

atio

n V

I—W

avef

orm

Sub

set

1A

rray

Sub

set—

Extr

acts

a s

ubse

t of

an

exis

ting

arr

ay.

In t

his

exer

cise

, yo

u us

e th

is f

unct

ion

to z

oom

in o

n a

subs

et o

f th

e w

avef

orm

you

gen

erat

ed.

2N

umer

ic C

onst

ant—

The

se c

onst

ants

spe

cify

tha

t th

e fu

nctio

n ex

trac

t th

e firs

t tw

o ro

ws

star

ting

at e

lem

ent

0.

3Sta

rt V

alue

—Set

s th

e st

art

inde

x. T

he d

efau

lt v

alue

is s

et t

o st

art

at e

lem

ent

0.

4Le

ngth

—Set

s th

e nu

mbe

r of

ele

men

ts t

o ex

trac

t. T

he d

efau

lt va

lue

is s

et t

o ou

tput

1000 e

lem

ents

.

3 4

12

Page 31: LABVIEW CORE 1

LabVIEW Core 1 Participant Guide

© National Instruments | 5-19

24.

Sw

itch

to

the

fron

t pa

nel a

nd t

est

the

Wav

efor

m S

ubse

t ca

se.

O

n th

e fr

ont

pane

l, cl

ick

the

Wav

efor

m S

ubse

t ta

b.

Run

the

VI.

C

hang

e va

lue

of the

Sta

rt V

alue

and

Len

gth

slid

ers

and

notice

tha

t th

e Sub

set D

ata

wav

efor

m g

raph

x-a

xis

star

ts a

t ze

ro a

nd fin

ishe

s at

the

num

ber

of e

lem

ents

in t

he n

ew a

rray

. The

x-a

xis

star

ts a

t ze

ro b

ecau

se t

he V

I cre

ates

a b

rand

new

arr

ay a

nd t

he g

raph

doe

s no

t kn

ow w

here

the

dat

a w

as

loca

ted

in t

he o

rigin

al a

rray

.

25.

Sto

p th

e V

I.

Usi

ng t

he N

I Ex

ampl

e Fi

nder

to

Lear

n M

ore

abou

t A

rray

s

Use

the

NI E

xam

ple

Find

er t

o br

owse

or se

arch

exa

mpl

es in

stal

led

on y

our co

mpu

ter or

on

the

NI D

evel

oper

Zon

e at

ni.com/zone.

Exam

ple

VIs

can

sho

w

you

how

to

use

spec

ific

fun

ctio

ns a

nd p

rogr

amm

ing

conc

epts

suc

h as

arr

ays

and

poly

mor

phis

m.

Com

plet

e th

e fo

llow

ing

step

s to

use

the

NI Ex

ampl

e find

er t

o lo

cate

exa

mpl

e V

Is t

hat

dem

onst

rate

diff

eren

t w

ays

to u

se t

he A

rray

fun

ctio

n.

1.

Sel

ect

Hel

p»Fi

nd E

xam

ples

to

star

t th

e N

I Exa

mpl

e Fi

nder

.

2.

Clic

k th

e Sea

rch

tab

and

ente

r th

e ke

ywor

d array.

3.

Clic

k th

e Sea

rch

butt

on t

o find

VIs

usi

ng t

hat

keyw

ord.

4.

Clic

k on

e of

the

exa

mpl

e V

Is in

the

sea

rch

resu

lts

list

and

read

the

des

crip

tion

.

5.

Dou

ble-

clic

k an

exa

mpl

e V

I to

ope

n it.

6.

Rea

d th

roug

h th

e co

mm

ents

on

the

fron

t pa

nel a

nd b

lock

dia

gram

to

lear

n m

ore

abou

t w

hat

this

exa

mpl

e V

I dem

onst

rate

s.

7.

Run

the

exa

mpl

e, e

xam

ine

the

diff

eren

t ca

ses,

and

clic

k th

e Sto

p bu

tton

to

exit.

8.

Clo

se t

he V

Is a

nd t

he N

I Exa

mpl

e Fi

nder

whe

n yo

u ar

e fini

shed

.

End

of E

xerc

ise

5-1

Page 32: LABVIEW CORE 1

Lesson 5 Creating and Leveraging Data Structures

5-20 | ni.com

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

Clusters

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

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.

Clusters Clusters group data elements of mixed types

Cluster Array

• Mixed data types

• Fixed size

• Vary in size

• Contain only one data type

Page 33: LABVIEW CORE 1

LabVIEW Core 1 Participant Guide

© National Instruments | 5-21

Resize the cluster shell by dragging the cursor while you place the cluster shell.

Cluster OrderCluster 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.

Page 34: LABVIEW CORE 1

Lesson 5 Creating and Leveraging Data Structures

5-22 | ni.com

Autosizing ClustersAutosizing helps you arrange elements in clusters.NI recommends the following:

• Arrange cluster elements vertically.

• Arrange elements compactly.

• Arrange elements in their preferred order.

Disassembling ClustersUse the Unbundle and Unbundle By Name functions to return individual cluster elements.

Modifying a ClusterUse Bundle By Name whenever possible to access elements in a cluster. Use Bundle when some or all cluster elements are unnamed.

I

1 Unbundle By Name—Returns the cluster elements whose names you specify. The number of output terminals does not depend on the number of elements in the input cluster.

2 Unbundle—Splits a cluster into its individual elements

1 2

Page 35: LABVIEW CORE 1

LabVIEW Core 1 Participant Guide

© National Instruments | 5-23

Demonstration: Creating a Cluster on the Block DiagramUse the Bundle function to programmatically create a cluster on a block diagram. If the elements that are bundled have labels, you can access them using the Unbundle By Name function. Otherwise use the Unbundle function.

Multi-plot Graphs/Charts and XY GraphThe 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 DataUse the Context Help window to determine how to wire multi-plot data to Waveform Graphs, Charts and XY Graphs.

Page 36: LABVIEW CORE 1

Lesson 5 Creating and Leveraging Data Structures

5-24 | ni.com

Error ClustersLabVIEW contains a custom cluster called the error cluster. LabVIEW uses error clusters to pass error information.

Page 37: LABVIEW CORE 1

LabVIEW Core 1 Participant Guide

© National Instruments | 5-25

Exer

cise

5-2

Tem

pera

ture

War

ning

s V

I—C

lust

ers

Goa

lC

reat

e a

clus

ter

data

type

con

tain

ing

the

data

to

be p

asse

d ar

ound

an

appl

icat

ion

and,

in t

he p

roce

ss, cr

eate

sca

labl

e, r

eada

ble

code

.

Sce

nario

Ano

ther

dev

elop

er h

as c

reat

ed a

VI t

hat

disp

lays

tem

pera

ture

war

ning

s. T

his

VI is

par

t of

the

tem

pera

ture

wea

ther

sta

tion

pro

ject

stu

died

thr

ough

out

this

co

urse

. Y

our

task

is t

o up

date

thi

s V

I to

use

clus

ters

inst

ead

of in

divi

dual

ter

min

als

for

inpu

ts a

nd o

utpu

ts.

Des

ign

The

flo

wch

art

in F

igur

e5-9

illu

stra

tes

the

data

flo

w f

or t

he d

esig

n of

the

Tem

pera

ture

War

ning

s V

I.

Page 38: LABVIEW CORE 1

Lesson 5 Creating and Leveraging Data Structures

5-26 | ni.com

Figu

re 5

-9.

Tem

pera

ture

War

ning

s V

I Fl

owch

art

Cur

rent

Tem

p>=

Max

Tem

p?

Yes

No

No

Yes

No

War

ning

? =

Tru

eW

arni

ng ?

= F

alse

War

ning

Text

= N

oW

arni

ng?

War

ning

Tex

t =Fr

eeze

War

ning

Pas

s cu

rren

t val

ueof

War

ning

Tex

t

Cur

rent

Tem

p<

= M

in T

emp?

War

ning

Tex

t =H

eats

trok

eW

arni

ng

War

ning

Tex

t =N

o W

arni

ng

Yes

Page 39: LABVIEW CORE 1

LabVIEW Core 1 Participant Guide

© National Instruments | 5-27

Cre

ate

a cl

uste

r w

hich

con

tain

s th

e da

ta u

sed

by t

he T

empe

ratu

re W

arni

ngs

VI. Y

ou m

odify

the

Tem

pera

ture

War

ning

s V

I to

rece

ive

and

retu

rn d

ata

in t

he

form

of

that

sam

e cl

uste

r as

sho

wn

in F

igur

e5-1

0. The

mod

ifie

d V

I wor

ks in

a m

ore

mod

ular

fas

hion

with

othe

r su

bVIs

in t

he o

vera

ll ap

plic

atio

n.

Figu

re 5

-10.

Tem

pera

ture

War

ning

s V

I with

Clu

ster

s Fr

ont

Pane

l

Page 40: LABVIEW CORE 1

Lesson 5 Creating and Leveraging Data Structures

5-28 | ni.com

Impl

emen

tation

1.

Ope

n Weather Warnings.lvproj in

the

<Exercises>\LabVIEW Core1\Weather Warnings d

irect

ory.

2.

Ope

n Tem

pera

ture

War

ning

s V

I fro

m t

he P

roje

ct E

xplo

rer

win

dow

.

3.

Plac

e ex

isting

con

trol

s an

d in

dica

tors

in a

clu

ster

nam

ed Weather Data a

s sh

own

in F

igur

e5-1

1.

Figu

re 5

-11. C

reat

e C

lust

er

1C

lust

er—

Use

the

Clu

ster

con

trol

fro

m t

he S

ilver

pal

ette

and

cha

nge

the

labe

l to Weather Data.

2Sel

ect

cont

rols

and

indi

cato

rs t

o in

clud

e in

the

clu

ster

. <

Shi

ft>

-clic

k to

sel

ect

mul

tipl

e ob

ject

s.3

Dra

g th

e co

ntro

ls a

nd in

dica

tors

into

the

Wea

ther

Dat

a cl

uste

r.

31 2

Page 41: LABVIEW CORE 1

LabVIEW Core 1 Participant Guide

© National Instruments | 5-29

4.

Res

ize

the

clus

ter

so t

hat

all t

he e

lem

ents

are

vis

ible

and

arr

ange

d ve

rtic

ally

as

show

n in

Fig

ure

5-1

2.

Figu

re 5

-12.

Res

ize

Clu

ster

Con

trol

1A

utos

ize

clus

ter—

LabV

IEW

can

rea

rran

ge a

nd r

esiz

e th

e cl

uste

r fo

r yo

u. R

ight

-clic

k th

e bo

rder

of

the

Wea

ther

Dat

a cl

uste

r an

d se

lect

Aut

oSiz

ing»

Arr

ange

Ver

tica

lly.

1

Page 42: LABVIEW CORE 1

Lesson 5 Creating and Leveraging Data Structures

5-30 | ni.com

5.

Reo

rder

the

item

s in

the

clu

ster

as

show

n in

Fig

ure

5-1

3.

Figu

re 5

-13. R

eord

er C

lust

er

1Rig

ht-c

lick

the

edge

of

the

clus

ter

and

sele

ct R

eord

er C

ontr

ols

in C

lust

er.

2C

lick

the

cont

rols

to

togg

le t

he o

rder

of

the

item

s in

the

clu

ster

.3

Clic

k th

e C

onfirm

but

ton

to s

ave

the

chan

ges.

3

1 2

Page 43: LABVIEW CORE 1

LabVIEW Core 1 Participant Guide

© National Instruments | 5-31

6.

Mod

ify

the

VI to

rec

eive

and

ret

urn

clus

ter

data

.

Figu

re 5

-14. T

empe

ratu

re W

arni

ngs—

Wea

ther

Dat

a In

and

Wea

ther

Dat

a O

ut C

lust

ers

1W

eath

er D

ata—

<C

trl>

-clic

k th

e W

eath

er D

ata

clus

ter

and

drag

it t

o cr

eate

a c

opy.

Ren

ame

the

copy

Weather Data In.

2W

eath

er D

ata—

Rig

ht-c

lick

the

orig

inal

clu

ster

and

sel

ect

Cha

nge

to Ind

icat

or.

Ren

ame

the

indi

cato

r Weather Data Out.

21

Page 44: LABVIEW CORE 1

Lesson 5 Creating and Leveraging Data Structures

5-32 | ni.com

7.

Mod

ify

the

bloc

k di

agra

m a

s sh

own

in F

igur

e5-1

5 t

o ex

trac

t da

ta f

rom

the

inpu

t cl

uste

r.

Figu

re 5

-15. T

empe

ratu

re W

arni

ngs

with

Clu

ster

s Blo

ck D

iagr

am

Not

eIf t

he o

rder

of

the

elem

ents

in t

he U

nbun

dle

By

Nam

e an

d th

e Bun

dle

By

Nam

e fu

nction

s is

diffe

rent

tha

n w

hat

you

wan

t, y

ou c

an u

se

the

Ope

rating

too

l to

chan

ge t

he o

rder

.

8.

Sav

e an

d cl

ose

the

Tem

pera

ture

War

ning

s V

I.

Tes

t1.

Ente

r va

lues

in t

he C

urre

nt T

empe

ratu

re, M

ax T

empe

ratu

re a

nd M

in T

empe

ratu

re c

ontr

ols

in t

he W

eath

er D

ata

In c

lust

er.

2.

Run

the

VI an

d ve

rify

that

the

Wea

ther

Dat

a in

dica

tor

disp

lays

cor

rect

val

ues.

3.

Sav

e an

d cl

ose

the

VI

End

of E

xerc

ise

5-2

1U

nbun

dle

By

Nam

e—W

ire t

he W

eath

er D

ata

In c

ontr

ol a

nd e

xpan

d th

e U

nbun

dle

By

Nam

e fu

nction

to

disp

lay

thre

e item

s. W

ire t

he o

utpu

ts o

f th

e U

nbun

dle

By

Nam

e fu

nction

to

the

brok

en w

ires

in t

he o

rder

sho

wn.

Bec

ause

you

mov

ed in

divi

dual

con

trol

s an

d in

dica

tors

into

a s

ingl

e cl

uste

r, y

ou

mus

t us

e th

e U

nbun

dle

By

Nam

e fu

nction

to

wire

the

inte

rnal

con

trol

s an

d in

dica

tors

inde

pend

ently

of e

ach

othe

r.2

Bun

dle

By

Nam

e—W

ire the

Wea

ther

Dat

a In

clu

ster

aro

und

the

anal

ysis

cod

e to

the

inpu

t cl

uste

r of

the

Bun

dle

by N

ame

func

tion

. Dis

play

tw

o el

emen

ts

and

use

the

Ope

rating

too

l to

sele

ct W

arni

ng?

and

War

ning

Tex

t el

emen

ts.

Con

nect

the

bro

ken

wire

s to

the

Unb

undl

e By

Nam

e in

puts

as

show

n.

1

2

Page 45: LABVIEW CORE 1

LabVIEW Core 1 Participant Guide

© National Instruments | 5-33

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

control.

Control OptionsUse 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.

• Type definitions and strict type definitions link to all the instances of a custom control or indicator to a saved custom control or indicator file. You can make changes to all instances of the custom control or indicator by editing only the saved custom control or indicator file

• Strict type defs apply cosmetic changes too, whereas type defs do not.

Page 46: LABVIEW CORE 1

Lesson 5 Creating and Leveraging Data Structures

5-34 | ni.com

Demonstration: Creating and Identifying Type Definitions

Page 47: LABVIEW CORE 1

LabVIEW Core 1 Participant Guide

© National Instruments | 5-35

Exer

cise

5-3

Tem

pera

ture

War

ning

s V

I—Typ

e D

efin

itio

n

Goa

lTo

impr

ove

the

scal

abili

ty o

f yo

ur a

pplic

atio

n by

usi

ng typ

e de

fini

tion

s m

ade

from

cus

tom

clu

ster

con

trol

s, in

dica

tors

, and

con

stan

ts o

f a

part

icul

ar d

ata

type

.

Sce

nario

As

a La

bVIE

W d

evel

oper

, you

can

enc

ount

er s

itua

tion

s w

here

you

nee

d to

def

ine

your

ow

n cu

stom

dat

a ty

pes

in the

for

m o

f cl

uste

rs a

nd e

num

s. A

cha

lleng

e as

soci

ated

with

usin

g cu

stom

dat

a ty

pes

is t

hat

you

may

nee

d to

cha

nge

them

late

r in

dev

elop

men

t. In

add

itio

n, y

ou m

ay n

eed

to c

hang

e th

em a

fter

the

y ha

ve a

lread

y be

en u

sed

in V

Is. Fo

r ex

ampl

e, y

ou c

reat

e co

pies

of

a cu

stom

dat

a ty

pe a

nd u

se t

hem

as

cont

rols

, in

dica

tors

, or

con

stan

ts in

one

or m

ore

VIs

. The

n yo

u re

aliz

e th

at t

he c

usto

m d

ata

type

nee

ds t

o ch

ange

. Y

ou n

eed

to a

dd, re

mov

e, o

r ch

ange

item

s in

the

clu

ster

dat

a ty

pe o

r th

e en

um.

As

a de

velo

per

you

mus

t as

k yo

urse

lf t

he f

ollo

win

g qu

estion

s:

•W

hat

shou

ld h

appe

n to

the

cop

ies

of t

he c

usto

m d

ata

type

s us

ed in

VIs

tha

t ar

e al

read

y sa

ved?

•Sho

uld

the

copi

es r

emai

n un

chan

ged

or s

houl

d th

ey u

pdat

e th

emse

lves

to

reflec

t ch

ange

s to

the

orig

inal

?

Usu

ally

, yo

u w

ant

all t

he c

opie

s of

the

cus

tom

dat

a ty

pe t

o up

date

if y

ou u

pdat

e th

e or

igin

al c

usto

m d

ata

type

. To

achi

eve

this

you

nee

d co

pies

of

the

cust

om d

ata

type

s to

be

tied

to

a ty

pe d

efin

itio

n, w

hich

is d

efin

ed a

s fo

llow

s:

Typ

e de

fini

tion

—A

mas

ter

copy

of

a cu

stom

dat

a ty

pe t

hat

mul

tipl

e V

Is c

an u

se.

Impl

emen

tation

In thi

s ex

erci

se, yo

u m

odify

the

Tem

pera

ture

War

ning

s V

I tha

t yo

u re

vise

d in

Exe

rcis

e5-2

in s

uch

a w

ay tha

t th

e ch

ange

s to

the

Wea

ther

Dat

a cu

stom

dat

a ty

pe p

ropa

gate

thr

ough

the

app

licat

ion.

Whe

n co

mpl

ete,

the

Wea

ther

Sta

tion

app

licat

ion

mon

itor

s te

mpe

ratu

re a

nd w

ind

info

rmat

ion.

Thi

s ex

erci

se m

odifi

es t

he T

empe

ratu

re W

arni

ngs

VI. In

the

C

halle

nge

exer

cise

, yo

u m

odify

the

Win

dspe

ed W

arni

ngs

VI.

1.

Ope

n Weather Warnings.lvproj in

the

<Exercises>\LabVIEW Core1\Weather Warnings d

irect

ory.

2.

Ope

n Tem

pera

ture

War

ning

s V

I fro

m t

he P

roje

ct E

xplo

rer

win

dow

.

3.

Expe

rimen

t w

ith

chan

ging

an

exis

ting

clu

ster

.

Pl

ace

a Fi

le P

ath

Con

trol

(Silv

er) in

the

Wea

ther

Dat

a In

clu

ster

con

trol

.

N

otic

e th

at t

he T

empe

ratu

re W

arni

ngs

VI is

bro

ken.

Thi

s is

bec

ause

the

Wea

ther

Dat

a In

and

Wea

ther

Dat

a O

ut c

lust

ers

are

no lo

nger

the

sam

e da

ta t

ype.

O

pen

the

bloc

k di

agra

m a

nd n

otic

e th

e br

oken

wire

con

nect

ed t

o th

e W

eath

er D

ata

Out

ter

min

al.

Pr

ess

<C

trl-Z

> t

o un

do t

he a

dditio

n of

the

File

Pat

h C

ontr

ol.

Page 48: LABVIEW CORE 1

Lesson 5 Creating and Leveraging Data Structures

5-36 | ni.com

4.

Mak

e a

type

def

initio

n.

Rig

ht-c

lick

the

bord

er o

f th

e W

eath

er D

ata

In c

ontr

ol a

nd s

elec

t M

ake

Typ

e D

ef.

O

n th

e bl

ock

diag

ram

, th

e W

eath

er D

ata

In t

erm

inal

now

has

a b

lack

tria

ngle

on

the

corn

er in

dica

ting

tha

t it is

con

nect

ed t

o a

type

def

initio

n.

Rig

ht-c

lick

the

bord

er o

f th

e W

eath

er D

ata

In c

ontr

ol a

nd s

elec

t O

pen

Typ

e D

ef t

o di

spla

y th

e C

usto

m C

ontr

ol E

dito

r w

indo

w a

s sh

own

in

Figu

re5-1

6.

The

win

dow

look

s lik

e th

e fr

ont

pane

l of

a V

I bu

t it d

oes

not

have

a b

lock

dia

gram

.

Figu

re 5

-16. C

usto

m C

ontr

ol E

dito

r W

indo

w

Sav

e th

e cu

stom

con

trol

as Weather Data.ctl in

the

<Exercises>\LabVIEW Core 1\Weather Warnings d

irect

ory

and

clos

e th

e co

ntro

l edi

tor

win

dow

.

O

n th

e bl

ock

diag

ram

of

the

Tem

pera

ture

War

ning

s V

I, no

tice

the

coe

rcio

n do

t on

the

Wea

ther

Dat

a O

ut in

dica

tor

term

inal

. Thi

s in

dica

tes

that

the

in

dica

tor

is n

ot t

ied

to t

he t

ype

defini

tion

.

1The

con

trol

typ

e is

Typ

e D

ef, w

hich

mai

ntai

ns t

he li

nk b

etw

een

this

file

and

the

cus

tom

con

trol

cop

ies

used

in V

Is.

1

Page 49: LABVIEW CORE 1

LabVIEW Core 1 Participant Guide

© National Instruments | 5-37

5.

Tie

the

Wea

ther

Dat

a O

ut in

dica

tor

to t

he t

ype

defini

tion

.

Rig

ht-c

lick

the

bord

er o

f th

e W

eath

er D

ata

Out

indi

cato

r on

the

fro

nt p

anel

and

sel

ect

Rep

lace

»Sel

ect

a C

ontr

ol f

rom

the

sho

rtcu

t m

enu.

Bro

wse

to

and

sele

ct t

he Weather Data.ctl f

ile y

ou ju

st c

reat

ed.

Not

eY

ou c

an n

o lo

nger

add

or

rem

ove

elem

ents

to

or f

rom

the

clu

ster

con

trol

and

indi

cato

r on

the

fro

nt p

anel

. Y

ou m

ust

open

the

typ

e de

fini

tion

and

add

or

rem

ove

the

elem

ent

from

the

con

trol

edi

tor

win

dow

.

Sav

e th

e Tem

pera

ture

War

ning

s V

I.

Page 50: LABVIEW CORE 1

Lesson 5 Creating and Leveraging Data Structures

5-38 | ni.com

6.

Edit t

he W

eath

er D

ata

type

def

initio

n to

incl

ude

unit in

form

atio

n.

Rig

ht-c

lick

the

bord

er o

f th

e W

eath

er D

ata

In c

ontr

ol a

nd s

elec

t O

pen

Typ

e D

ef f

rom

the

sho

rtcu

t m

enu.

M

odify

the

fron

t pa

nel a

s sh

own

in F

igur

e5-1

7.

Figu

re 5

-17.

Wea

ther

Dat

a Typ

e D

efin

itio

n w

ith

Tem

pera

ture

Uni

ts

Sav

e th

e W

eath

er D

ata

type

def

initio

n an

d cl

ose

the

cont

rol e

dito

r w

indo

w.

N

otic

e th

at t

he W

eath

er D

ata

In c

ontr

ol a

nd W

eath

er D

ata

Out

indi

cato

r on

the

Tem

pera

ture

War

ning

s V

I hav

e be

en u

pdat

ed w

ith

the

chan

ges

you

mad

e to

the

Wea

ther

Dat

a ty

pe d

efin

itio

n. A

rran

ge t

he f

ront

pan

el o

f th

e V

I as

show

n in

Fig

ure

5-1

8.

1En

um (Silv

er)—

Plac

e an

enu

m in

the

clu

ster

and

ren

ame

it Units.

Rig

ht-c

lick

the

enum

and

sel

ect

Edit it

ems.

Cre

ate

an it

em f

or Celsius a

nd

Fahrenheit.

1

Page 51: LABVIEW CORE 1

LabVIEW Core 1 Participant Guide

© National Instruments | 5-39

Figu

re 5

-18. T

empe

ratu

re W

arni

ngs

VI w

ith

Typ

e D

ef C

ontr

ols

and

Indi

cato

rs

7.

Run

and

Sav

e th

e Tem

pera

ture

War

ning

s V

I.

Cha

lleng

eIn

thi

s ch

alle

nge

exer

cise

, yo

u m

odify

the

Win

dspe

ed W

arni

ngs

VI to

aug

men

t th

e W

eath

er S

tation

app

licat

ion.

1.

Add

the

Win

dspe

ed W

arni

ngs

VI to

the

Wea

ther

War

ning

s pr

ojec

t.

In

the

Pro

ject

Exp

lore

r w

indo

w, rig

ht c

lick

My

Com

pute

r an

d se

lect

Add

»File

fro

m t

he s

hort

cut

men

u.

N

avig

ate

to <Exercises>\LabVIEW Core 1\Weather Warnings\Support VIs a

nd s

elec

t Windspeed Warnings.vi.

Page 52: LABVIEW CORE 1

Lesson 5 Creating and Leveraging Data Structures

5-40 | ni.com

2.

Ope

n th

e W

inds

peed

War

ning

s V

I.

3.

Cop

y th

e W

eath

er D

ata

In c

lust

er f

rom

the

Tem

pera

ture

War

ning

s V

I to

the

Win

dspe

ed W

arni

ngs

VI.

4.

Rig

ht-c

lick

the

Wea

ther

Dat

a In

clu

ster

and

sel

ect

Ope

n Typ

e D

ef f

rom

the

sho

rtcu

t m

enu.

5.

Mod

ify

the

Wea

ther

Dat

a ty

pe d

efin

itio

n w

ith

win

dspe

ed c

ontr

ols

as s

how

n in

Fig

ure

5-1

9.

Figu

re 5

-19. W

inds

peed

War

ning

s V

I Typ

e D

efin

itio

n C

ontr

ols

and

Indi

cato

rs

Page 53: LABVIEW CORE 1

LabVIEW Core 1 Participant Guide

© National Instruments | 5-41

6.

Mod

ify

the

bloc

k di

agra

m o

f th

e W

inds

peed

War

ning

s V

I to

use

the

new

Wea

ther

Dat

a ty

pe d

efin

itio

n in

stea

d of

indi

vidu

al c

ontr

ols

and

indi

cato

rs,

as

show

n in

Fig

ure

5-2

0.

Figu

re 5

-20. W

inds

peed

War

ning

s V

I U

sing

Typ

e D

efin

itio

ns

7.

Ope

n Tem

pera

ture

War

ning

s V

I and

not

ice

that

the

Wea

ther

Dat

a In

con

trol

and

Wea

ther

Dat

a O

ut in

dica

tor

is u

pdat

ed t

o in

clud

e th

e W

inds

peed

dat

a.

8.

Sav

e an

d cl

ose

the

VI an

d th

e pr

ojec

t.

End

of E

xerc

ise

5-3

Page 54: LABVIEW CORE 1

Lesson 5 Creating and Leveraging Data Structures

5-42 | ni.com

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

Page 55: LABVIEW CORE 1

LabVIEW Core 1 Participant Guide

© National Instruments | 5-43

Activity 5-2: Lesson Review

1. You can create an array of arrays.

a. True

b. False

2. You have two input arrays wired to a For Loop. Auto-indexing is enabled on both tunnels. One array has 10 elements, the second array has five elements. A value of 7 is wired to the Count terminal, as shown in the following figure. What is the value of the Iterations indicator after running this VI?

3. Which of the following custom control settings defines the data type of all instances of a control but allows for different colors and font styles?

a. Control

b. Type Definition

c. Strict Type Definition

d. Cluster control

4. You have input data representing a circle: X Position (I16), Y Position (I16), and Radius (I16). In the future, you might need to modify your data to include the color of the circle (U32).

What data structure should you use to represent the circle in your application?

a. Three separate controls for the two positions and the radius.

b. A cluster containing all of the data.

c. A custom control containing a cluster.

d. A type definition containing a cluster.

e. An array with three elements.

Page 56: LABVIEW CORE 1
Page 57: LABVIEW CORE 1

LabVIEW Core 1 Participant Guide

© National Instruments | 5-45

Activity 5-2: Lesson Review - Answers

1. You can create an array of arrays.

a. True

b. False

You cannot drag an array data type into an array shell. However, you can create two-dimensional arrays.

2. You have two input arrays wired to a For Loop. Auto-indexing is enabled on both tunnels. One array has 10 elements, the second array has five elements. A value of 7 is wired to the Count terminal, as shown in the following figure. What is the value of the Iterations indicator after running this VI?

Value of Iterations = 4

LabVIEW does not exceed the array size. This helps to protect against programming error. LabVIEW mathematical functions work the same way—if you wire a 10 element array to the x input of the Add function, and a 5 element array to the y input of the Add function, the output is a 5 element array.

Although the for loop runs 5 times, the iterations are zero based, therefore the value of the Iterations indicators is 4.

3. Which of the following custom control settings defines the data type of all instances of a control but allows for different colors and font styles?

a. Control

b. Type Definition

c. Strict Type Definition

d. Cluster control

4. You have input data representing a circle: X Position (I16), Y Position (I16), and Radius (I16). In the future, you might need to modify your data to include the color of the circle (U32).

What data structure should you use to represent the circle in your application?

a. Three separate controls for the two positions and the radius.

b. A cluster containing all of the data.

c. A custom control containing a cluster.

d. A type definition containing a cluster.

e. An array with three elements.

Page 58: LABVIEW CORE 1