Anda di halaman 1dari 45

CLAD Study

Guide
Prepared by LabVIEW Student Ambassadors:
Julian Ferrer-Rios
Kristen Heck
Francesca Ramadori
Kelvin Tang
Table of Contents
Section 1: LabVIEW Programming Concepts...........................................................................................2
Section 2: LabVIEW Environment............................................................................................................6
Section 3: Software Constrcts in LabVIEW............................................................................................!
Section ": Programming Vis an# fnctions..............................................................................................16
Section $: %ata Commnication an# S&nc'roni(ation VIs an# )nctions..............................................1*
Section 6: VI Server an# )nctions.........................................................................................................21
Section +: Errors 'an#,ing VI-s an# )nctions........................................................................................2$
Section *: VI %esign Patterns..................................................................................................................2*
Section !: SbVI %esign..........................................................................................................................36
Section 1.: %ebgging VI-s.....................................................................................................................3*
Section 11: VI %esign an# %ocmentation.............................................................................................."2
Section 12: /emor&0 Performance0 an# %eterminism.............................................................................""
111
Section : LabVIEW Pro!rammin! Concepts
Data "lo#
LabVIEW follos a dataflo model for running Vis!
" block diagram node e#ecutes $en all its in%uts are available! W$en a node com%letes
e#ecution& it su%%lies data to its out%ut terminals and %asses t$e out%ut data to t$e ne#t node
in t$e dataflo %at$!
Visual 'asic& ())& J"V"& and most ot$er te#t-based %rogramming languages follo a control
flo model of %rogram e#ecution! In control flo& t$e se*uential order of %rogram elements
determines t$e e#ecution order of a %rogram!
(onsider t$e block diagram above! It adds to numbers and t$en multi%lies b+ , from t$e
result of t$e addition! In t$is case& t$e block diagram e#ecutes from left to rig$t& not because
t$e ob-ects are %laced in t$at order but because one of t$e in%uts of t$e .ulti%l+ function is
not valid until t$e "dd function $as finis$ed e#ecuting and %assed t$e data to t$e .ulti%l+
function! Remember t$at a node e#ecutes onl+ $en data are available at all of its in%ut
terminals& and it su%%lies data to its out%ut terminals onl+ $en it finis$es e#ecution! In t$e
second %iece of code& t$e /imulate /ignal E#%ress VI receives in%ut from t$e controls and
%asses its result to t$e gra%$!
0ou ma+ consider t$e add-multi%l+ and t$e simulate signal code to coe#ist on t$e same block
diagram in %arallel! T$is means t$at t$e+ begin e#ecuting at t$e same time and run
inde%endentl+ of one anot$er! If t$e com%uter running t$is code $ad multi%le %rocessors&
t$ese to %ieces of code could run inde%endentl+ of one anot$er 1eac$ on its on %rocessor2
it$out an+ additional coding!
121
Polymorp$ism
" %rogramming language feature t$at allos values of different data t+%es to be $andled
using a uniform interface!
In LabVIEW3 t$e abilit+ of VIs and functions to automaticall+ ada%t to acce%t in%ut data of
different data t+%es 1i!e! 4umeric Functions25 6seful $en %erforming t$e same o%eration on
different data t+%es
Section Practice %uestions
7! 0ou develo% a /ubVI t$at onl+ out%uts a value and need to use t$is /ubVI in a 1calling2
VI! W$ic$ of t$e folloing is t$e best a+ to enforce dataflo to control t$e e#ecution of t$e
/ubVI8
a! 6se t$e /ubVI in a /e*uence structure
b! .odif+ t$e /ubVI to $ave dumm+ in%uts t$at can be used from t$e calling VI
c! .odif+ t$e /ubVI to $ave Error clusters t$at can be used from t$e calling VI
d! .odif+ t$e /ubVI to $ave a global variable and use it from t$e calling VI
,! W$ic$ of t$e folloing does not conform to data flo %rogramming %aradigm8
a! /$ift Registers
b! Tunnels
c! /ubVIs
d! Local Variables
131
9! In t$e figure belo& $at ill Result e*ual $en t$is calculation is e#ecuted8
a! ::
b! ;<
c! =:
d! Indeterminate
>! W$at is t$e value in &'( (esult after t$e folloing code $as e#ecuted8

a! <
b! 7
c! True
d! False
:! W$at determines t$e %rogram order of e#ecution of code in LabVIEW8
a! T$e time $en +ou entered t$e code
b! It goes from left to rig$t!
c! T$e data flo
1"1
=! In t$e folloing VI& $at ill be t$e e#ecution order of functions8
a!
b!
c!
d!
Section Ans#ers
7! (
,! ?
9! '
>! '
:! (
=! (
1$1
Section ): LabVIEW En*ironment
LabVIEW %rograms are called *irtual instruments 1Vis2!
Controls are in%uts and indicators are out%uts!
Eac$ VI contains t$ree main %arts3
"ront panel @ Ho t$e user interacts it$ t$e VI
+loc, dia!ram @ T$e code t$at controls t$e %rogram
Icon-connector @ T$e means of connecting a VI to ot$er Vis
In LabVIEW& +ou build a user interface b+ using a set of tools and ob-ects! T$e user interface
is knon as t$e front panel! 0ou t$en add code using gra%$ical re%resentations of functions
to control t$e front %anel ob-ects! T$e bloc, dia!ram contains t$is code! In some a+s& t$e
161
block diagram resembles a floc$art!
0ou interact it$ t$e front %anel $en t$e %rogram is running! 0ou can control t$e %rogram&
c$ange in%uts& and see data u%dated in real time! Controls are used for in%uts suc$ as
ad-usting a slide control to set an alarm value& turning a sitc$ on or off& or sto%%ing a
%rogram! Indicators are used as out%uts! T$ermometers& lig$ts& and ot$er indicators dis%la+
out%ut values from t$e %rogram! T$ese ma+ include data& %rogram states& and ot$er
information!
Ever+ front %anel control or indicator $as a corres%onding terminal on t$e block diagram!
W$en +ou run a VI& values from controls flo t$roug$ t$e block diagram& $ere t$e+ are used
in t$e functions on t$e diagram& and t$e results are %assed into ot$er functions or indicators
t$roug$ ires!
Controls Palette
6se t$e Controls %alette to %lace controls and indicators on t$e front %anel! T$e Controls
%alette is available onl+ on t$e front %anel! To vie t$e %alette& select Vie#.Controls Palette!
0ou also can dis%la+ t$e Controls %alette b+ rig$t-clicking an o%en area on t$e front %anel!
Tack don t$e Controls %alette b+ clicking t$e %us$%in on t$e to% left corner of t$e %alette!
"unctions Palette
6se t$e "unctions %alette to build t$e block diagram! T$e "unctions %alette is available onl+
on t$e block diagram! To vie t$e %alette& select Vie#."unctions Palette! 0ou also can
dis%la+ t$e "unctions %alette b+ rig$t-clicking an o%en area on t$e block diagram! Tack don
t$e "unctions %alette b+ clicking t$e %us$%in on t$e to% left corner of t$e %alette!
Tools Palette
0ou can vie t$e Tools Aalette on bot$ t$e front %anel and block diagram! To vie t$e
%alette& select Vie#.Tools Palette! 0ou also can dis%la+ t$e Tools %alette b+ $olding s$ift)
rig$t-clicking an o%en area on t$e front %anel or block diagram!
If +ou enable t$e automatic selection tool and +ou move t$e cursor over ob-ects on t$e front
%anel or block diagram& LabVIEW automaticall+ selects t$e corres%onding tool from t$e Tools
1+1
"utomatic /election Tool
%alette! Toggle automatic selection tool b+ clicking t$e Automatic Selection Tool button in
t$e Tools %alette!
6se t$e 'peratin! Tool to c$ange t$e values of a control or select t$e te#t it$in a control!
6se t$e Positionin! Tool to select& move& or resiBe ob-ects! T$e Aositioning Tool c$anges
s$a%e $en it moves over a corner of a resiBable ob-ect!
6se t$e Labelin! Tool to edit te#t and create free labels! T$e Labeling Tool c$anges to a
cursor $en +ou create free labels!
6se t$e Wirin! Tool to ire ob-ects toget$er on t$e block diagram!
Section ) Practice %uestions
7! W$ic$ of t$e folloing is t$e best met$od to u%date an indicator on t$e front %anel8
a!6se a Value %ro%ert+ node
b!Wire directl+ to t$e indicator terminal
c!6se a local variable
d!6se a functional global variable
Section ) Ans#ers
7! '
1*1
Section /: Soft#are Constructs in LabVIEW
0 "ront panel #indo# and bloc, dia!ram ob1ects
a! (ontrols& indicators& IC controls and refnums
i! (ontrol @ front %anel ob-ect for simulating in%ut& dis%la+s values t$at ill
be %assed TC functions on block diagram
7! Knobs& %us$ buttons& etc!
,! 6suall+ $as a $ite background
ii!Indicator @ front %anel ob-ect for out%ut & dis%la+s values %assed FRC.
functions on block diagram
7! Dra%$s& LE?s& etc!
,! 6suall+ $as a gra+ background
iii! IEC (ontrols
iv! Refnums
b! Terminals& constants& nodes
i! Terminals- re%resentation of front %anel 1FA2 ob-ects 1controls and
indicators2 on t$e block diagram 1'?25 entr+ and e#it %oints for data
e#c$ange beteen FA and '?
7! Remember %osition of terminal doesnFt matter- label and data t+%e
defines $at FA ob-ect t$e terminal is connected to
ii!(onstants- onl+ on '?
iii! 4odes
7! Function
a! Aale +ello background
b! Fundamental o%erating elements of LV
c! ?ouble-clicking selects item
,! subVI
a! VI it$in a VI
b! "n+ VI $as %otential to be a subVI
c! ?ouble-click on subVI to o%en FA
d! E#%ress VIs G s%ecial t+%e
i! (onfiguration indo
9! /tructure
a! E#am%les3 $ile loo%& for loo%& case structure& se*uence
structure
c! Aalettes& u%date modes& and legends of c$arts and gra%$s
i! Aalettes
7! Dra%$ %alette
a! (ursor mode- focus to cursor so cursor moves
b! Boom mode @ $orB or vert onl+ Boom& bo# Boom& Boom
1!1
inEout 1s$ift ) click for Boom out2
c! drag mode @ click and drag %lot vie around- scale auto
u%dates
ii!6%date modes
7! ($art adds %oint eac$ iteration- maintains $istor+
a! /tri% c$art @ entire %lot redran eac$ iteration in order for
%lot to a%%ear to scroll to t$e left
b! /co%e c$art- %oints %lotted until end of #scale reac$ed&
t$en %lot clears& and %lot begins at far left again
c! /ee% c$art @ red line t$at indicates t$e front edge of ne
data being %lotted over old data!
,! Dra%$ redras %oint1s2 eac$ iteration-
a! 6se a c$art inside a loo% to see full set of data 1d+namicall+
u%dates2
b! 6se a gra%$ outside a loo% to see full set of data
iii! Legends
7! Alot legend
a! /$os color of eac$ %lot and %lot name
,! /cale legend
a! /$os #- and +-scale titles& can lock scales& s$o full data
range& and edit t$e format of t$e numbers
9! (ursor legend
a! Cnl+ available for gra%$s
b! Lists cursors and coordinates
c! (an create cursors from $ere
d! .ec$anical action of 'oolean ob-ects Hreall+ $el%ful e#am%le VI3 I.ec$anical
"ction of 'ooleans!viJ in t$e E#am%le Finder- searc$ Imec$anicalJK
i! /itc$ @
7! W$en %ressed- value c$ange on don click of left mouse button
,! W$en released- value c$ange on release of left mouse button
9! 6ntil released- value c$ance on don click and release of left
mouse button
ii!Latc$ @ $as to be read b+ LV and returns to its original state
7! W$en %ressed- value c$ange on don click of left mouse button
,! W$en released- value c$ange on release of left mouse button
9! 6ntil released- value c$ance on don click and release of left
mouse button
e! Aro%ert+ nodes
i! "ccess %ro%erties of an ob-ect 1item2
ii!"llo +ou to modif+ ob-ects a%%earance or be$avior 1for e#am%le2
11.1
%rogrammaticall+
iii! C%erate to% to bottom
iv! '+ default& if error occurs $alf-a+ don& remaining %ro%ert+
modifications ill not e#ecute and error ill be out%ut
2. Data types and data structures Hfor more details 1more t$an covered on (L"?2
-L$tt%3EEBone!ni!comEreferenceEen-MME$el%E9;79=7'-
<7Elve#codeconce%tsEmanagerNdataNt+%esE K
a! 4umeric @
i! re%resent numbers
ii!c$oose re%resentation G number of bits used to store t$e number 1more
bits& more %recision %ossible25 ie I9,& 6O& ?'L
iii! Crange 1?'L2& 'lue 1Integer2& Dra+ 1FMA2
b! /tring
i! /e*uence of "/(II c$aracters
ii!Tables& te#t entr+& labels are e#am%les of string ob-ects
iii! ($ange dis%la+ format3 4ormal& PQF(odes& Aassord& He#
iv! Aink
c! 'oolean
i! TrueEFalse
ii!Dreen
iii! .ec$anical action 1see above2
d! Enumerated (ontrolE(onstantEIndicator 1Enum2
i! Aairs of string and numeric in defined list
ii!6seful because easier to mani%ulate numbers t$an strings sometimes
1state mac$ines2
e! %at$ data t+%e
i! %latform 1C/2 inde%endent5 t$e file manager 1lo level LV2 determines
$o t$e data t+%e is defined
f! "rra+ and cluster data t+%es
i! "rra+s
7! (om%osed of elements 1data2 and dimension 1siBe2
,! "ll elements must be of same data t+%e- defined $en created
1%lacing numerical control in an arra+ s$ell control creates a
numeric arra+ control2
g! Waveform
i! T$ree %arts to it
7! t<3 time Bero
,! deltaNt3 time increment
9! 03 value& intensit+& voltage& etc!
$! Timestam% data t+%e
1111
i! time Bone-inde%endent number of seconds t$at $ave ela%sed since 7,3<<
a!m!& Frida+& Januar+ 7& 7R<>& 6niversal Time! If year and mont$ are out
of range& t$e results are un%redictable! If year is before 7R<>& time
stamp is negative!
i! Variant data t+%e
i! "llos +ou to $andle data in a general a+
/0 Wor,in! #it$ ob1ects and data types on front panel #indo#s
a! Ranges& formats& re%resentation& and scaling
i! "%%ro%riate use
7! E#am%le3 if +ou are measuring t$e angle of a $alf rotation t$e
range s$ould be <-7O<
b! (ustomiBing controls
i! (ustom control
7! /ingle instance of uni*ue control or indicator
ii!T+%e definitions
7! Linked to file so c$anges to file ill be seen in eac$ instance of
t+%e deffed controlEindicator
,! "%%earance is not linked to file- data t+%e 1I9,& 6O& list of enum&
string2
iii! /trict t+%e definitions
7! Linked to file so c$anges to file ill be seen in eac$ instance of
t+%e deffed controlEindicator
,! "%%earance I/ linked so EVER0THI4D e#ce%t label& descri%tion&
and default value c$anges
20 Pro!ram control structures and data stora!e
a! Loo%ing structures 1for loo%s and $ile loo%s2
i! For Loo%
7! E#ecutes set number of times- defined b+ 4 terminal or inde#ed
tunnel
,! Aossible e#ecute Bero times
9! Tunnels automaticall+ out%ut an arra+ of data
ii!W$ile Loo%
7! /to%s e#ecuting based on t$e value at t$e conditional terminal
,! .ust run at least once 1do-$ile loo%2
9! Tunnels automaticall+ out%ut last value
iii! Inde#ing on loo% boundaries
7! In%ut3 one element in t$e arra+ ill be %assed in it$ eac$ loo%
iteration
,! Cut%ut3 an element is added to t$e arra+ it$ eac$ loo% iteration&
t$e entire arra+ ill be %assed out
iv! /$ift registers
1121
7! Aair of terminals on left and rig$t side of loo%- forced to be aligned
,! Value read from out%ut of s$ift register 1left side2 ill be t$e same
value as t$e value %assed to t$e s$ift register in%ut 1rig$t side2!
9! 7
st
iteration of loo%3
a! if initialiBed 1value %assed into s$ift register from outside
t$e loo%2& t$e initialiBing value ill be t$e value read from
t$e s$ift register!
b! If uninitialiBed& t$e value in t$e s$ift register from t$e last
time t$e loo% as e#ecuted ill be t$e value read from t$e
s$ift register 1t$is is utiliBed in functional globals2- if never
run before& uses default value 1usuall+ <2
b! (ase and se*uence structures
i! Flat and stacked se*uence structures
7! (an be used to force e#ecution order& but usuall+ anot$er a+
1error ire2
,! /$ould be avoided because cannot be sto%%ed in t$e middle!
9! /tacked means t$at +ou onl+ see one frame at a time- scroll
t$roug$ to see ot$ers
ii!(ase selector values and data t+%es
7! (ase selector acce%ts values to determine $ic$ case to e#ecute
,! If value case selector reads does not matc$ an+ of t$e cases&
default case ill e#ecute!
9! Enums useful because donFt $ave to orr+ about t+%os it$
strings& and %lain numerics are $arder to kee% track of!
>! Error ire can be ired to case selector to %rogrammaticall+
c$oose to e#ecute certain code $en t$ere is or is not an error-
case structure turns red and green to indicate error case and no
error case!
iii! ?ata %assing- tunnels and se*uence locals
7! Tunnels %ass values in or out of structures
a! (olor ill matc$ data t+%e
i! /olid- all cases ired& no inde#ing& InormalJ
ii!C%en- 1not seen on loo%s5 out%utErig$t-side onl+2 one
or more cases isnFt %roviding a value to out%ut
iii! /mall $ite s*uare inside @ use default if
unired
iv! W$ite it$ brackets of data t+%e color- 1seen
onl+ on loo%s2 auto inde#ing enabled
,! /e*uence local- onl+ for stacked se*uence structures
a! /imilar to s$ift register in t$at it %asses data from one
instance 1loo%& se*uence frame2 to anot$er
b! "rro to indicate if in%ut or ou%ut
1131
c! Event structures
i! 4otif+ and filter events 1user interface2
7! 4otif+-
a! Left side of event structure
b! event $a%%ened& get values from event
c! Dreen arro in Edit Event indo
,! Filter @
a! event is about to $a%%en& able to c$ange $at $a%%ens
b! rig$t side of event structure
c! red arro in Edit Event indo and ends it$ I8J
ii!Value 1signaling2 %ro%erties of controls
7! T$ese %ro%erties can be Icaug$tJ b+ an event structure
iii! ?+namic events and user events
7! ?+namic events-
a! use $en onl+ ant event to be registered during %art of
t$e a%%lications e#ecution
b! enable +ou to $andle events in a subVI
c! rig$t-click on event structure to select /$o ?+namic Event
Terminals
,! 6ser Events
a! Arogrammaticall+ create an event t$at +ou define 1instead
of t$e ones alread+ available t$roug$ t$e event structure2
b! 6se Denerate 6ser Event to $ave event occur and be sent
to event structure to be $andled
d! Formula node
i! "llos +ou to use te#t to e#ecute a function and mat$ematical formulas
1cos& sin& log& etc2
e! (onditional disable and diagram disable structures
i! Arogrammaticall+ enable and disable code @ useful if anting to make file
IEC function correctl+ in bot$ develo%ment and e#ecutable environments
ii!6seful in troubles$ooting code to narro don %roblem s%ot
f! Timed structures- loo% and se*uence
i! .ore useful in a real-time o%erating s+stem 1deterministic2
ii!Eac$ loo% or frame ill o%erate in t$e time +ou s%ecif+ @ ill indicate if
doesnFt using Finis$ed Late8 ?ata 4ode element
iii! (an set %riorit+ of loo%& %rocessor t$e loo% s$ould use to e#ecute&
etc
g! Variables- ire is ala+s %referred& race conditions %ossible
i! Local
7! Wit$in a single VI
11"1
ii!Dlobal
7! VI-to-VI
,! Looks like a front-%anel-onl+ VI t$at stores t$e values
iii! Functional Dlobal
7! VI-to-VI
,! FA and '?- uninitialiBed s$ift register used to store data
9! Arotects data from to instances tr+ing access at same time and
causing race condition
iv! /$ared
7! VI-to-VI across a netork
,! ?e%lo+ed to netork for use b+ multi%le VIs on t$e netork
11$1
Section 2: Pro!rammin! Vis and functions
0 3umeric4 +oolean4 strin!4 pat$4 and *ariant
a2 1see above2
)0 Con*ersion4 comparison4 and manipulation
a2 Functions s%ecificall+ for converting3 num-L string& string -L num& %at$ -L string&
string -L %at$& etc
b2 Functions s%ecificall+ for mani%ulating certain data t+%es3 build %at$& stri% %at$&
concatenate string& bool -L num arra+& etc
/0 Arrays and clusters
a2 'ot$ $ave s$ells
b2 "rra+s
7! must be same data t+%e
,! dimension and data
9! inde# element from arra+
c2 (lusters
7! Drou%ing of man+ data t+%es 1including arra+s and ot$er clusters2
,! 6nbundle and bundle cluster elements
20 Timin!
a2 Wait timers
7! Wait
7! Will ait until t$e s%ecified time $as ela%sed
,! W$en in a loo%& runs in %arallel to ot$er code inside loo% 1assuming no
de%endencies on ot$er code in loo%2- if code takes longer t$an t$e ait time&
ne#t loo% iteration ill begin immediatel+& ot$erise t$e ait ill com%lete
and t$en ne#t loo% iteration ill begin
,! Wait until ne#t millisecond multi%le
7! Will ait until a multi%le of t$e time s%ecified is reac$ed
,! W$en in a loo% and assuming no de%endenc+ on ot$er code in loo%& it ill
run in %arallel- if ,< ms is ired to it& imagine marks along a time line ever+
,< ms! If t$e code runs >: ms& t$e ne#t loo% iteration cannot begin until t$e
ne#t mark& $ic$ ould be at =< ms!
b2 tick count 1ms2
7! starts at Bero 1cannot convert into real dateEtime2
,! ma# value G 1,S9,2-75 t$erefore can rollover back to Bero if alloed to count
%ast its ma# -L bad information
c2 dateEtime functions
d2 Timing functions related to timed structures
50 file I-' formats
a2 "/(II
7! Te#t file
1161
,! Dood to use $en ant to o%en it$ anot$er %rogram 1note%ad& te#t edit& ord&
etc2
b2 'inar+
7! Takes least amount of memor+
,! Efficient
9! (annot be easil+ read b+ user or o%ened b+ anot$er %rogram
>! .ust kno $o to decode t$e file
c2 ?atalog
7! T+%e of binar+ file
,! 6sed to rite clustered data to file
d2 /torage1!tdm2
7! Internal structure %ublicl+ documented 1created b+ 4I2
,! T+%e of binar+ file it$ an inde# file for faster IEC %erformance
9! "ble to a%%l+ %ro%erties to file at different levels3 file& grou%& c$annel
e2 Waveform
f2 M.L 1E#tensible .arku% Language-standardiBed2
7! /et of functions s%ecificall+ for M.L
,! Alatform inde%endent
g2 (onfiguration
7! ini file
,! /et of functions s%ecificall+ for config files
9! Alatform inde%endent
60 Wa*eform and #a*eform file I-'
a2 /torage VIs used to rite aveform data to binar+ measurement files 1!tdm2
70 Dynamic and user e*ents
a2 1see above2
11+1
Section 5: Data Communication and Sync$roni8ation VIs and
"unctions
Local Variables
Local variables allo data to be %assed beteen %arallel loo%s! 0ou can read or rite a single
control or indicator from more t$an one location in t$e %rogram! Local variables brea, t$e
dataflo# paradi!m and s$ould be used s%aringl+!
/ometimes +ou ma+ need to access a front %anel ob-ect from more t$an one %lace on t$e
block diagram or to %ass data beteen structures t$at +ou cannot connect b+ a ire! To
accom%lis$ t$ese tasks& +ou ould use a local variable!
Local variables are located on t$e "unctions %alette under Pro!rammin!.Structures!
0ou use a local variable b+ first selecting t$e ob-ect +ou ant to access! 0ou can eit$er click
on t$e local variable it$ t$e C%erating tool and select t$e ob-ect +ou ant to access& or rig$t-
click on t$e local variable and c$oose t$e ob-ect from t$e Select Item menu!
4e#t& +ou must decide to eit$er read or rite to t$e ob-ect! Rig$t-click on t$e local variable
and c$oose C$an!e to (ead or C$an!e to Write!
Global Variables
6se global variables to access and %ass data amon! se*eral VIs
?iffers from local *ariables because local variables are used to access and %ass data
bet#een parallel loops 9#it$in one VI:0 W$en +ou create a global variable& LabVIEW
automaticall+ creates a s%ecial global VI& $ic$ $as a front %anel but no block diagram!
S$ared Variable
Re%resents a s$ared variable on t$e block diagram! 6se s$ared variables to s$are data
among VIs or beteen locations on t$e block diagram t$at +ou cannot connect it$ ires!
DataSoc,et
6se t$e ?ata/ocket VI and functions to %ass data beteen VIs %rogrammaticall+! ?ata/ocket
be used it$ basicall+ an+ %rotocol t$at utiliBes t$e Transmission (ontrol Arotocol 1T(A2 in
some form!
To use ?ata/ockets it is necessar+ to set u% t$e ?ata/ockets /erver& a %rogram t$at runs on
one of t$e mac$ines in t$e netork and acts as an intermediar+& so t$at multi%le clients can
readErite data! T$e data transfer uses t$e ?atasocket Transfer Arotocol 1?/TA2!
11*1
Protocols
6se t$e Arotocols VIs and functions to e#c$ange data beteen a%%lications b+ using
%rotocols suc$ as T(AEIA& 6?A& serial& Ir?"& 'luetoot$& and /.TA!
3otifiers
6se t$e 4otifier C%erations functions to sus%end t$e e#ecution of a block diagram until +ou
receive data from anot$er section of t$e block diagram or from anot$er VI running in t$e same
a%%lication instance!
%ueues
6se t$e Tueue C%erations functions to create a *ueue for communicating data beteen
sections of a block diagram or from anot$er VI!
Semap$ores
6se t$e /ema%$ore VIs to limit t$e number of tasks t$at can simultaneousl+ o%erate on a
s$ared 1%rotected2 resource! " %rotected resource or critical section of code mig$t include
riting to global variables or communicating it$ e#ternal instruments!
Section 5 Practice %uestions
7! W$ic$ of t$e folloing cannot be used to transfer data8
a! /ema%$ores
b! Tueues
c! 4otifiers
d! Local variables
11!1
,! W$ic$ of t$e folloing illustrates an advantage of a global variable over a local
variable8
a! " global variable can %ass data beteen to inde%endent VIs running simultaneousl+
b! Cnl+ t$e global variable can %ass arra+ data& local variables cannot
c! Dlobal variables follo t$e dataflo model& and t$erefore cannot cause race conditions
d! Dlobal variables do not re*uire oned labels to o%erate
Section 5 Ans#ers
7! "
,! "
12.1
Section 6: VI Ser*er and "unctions
In LabVIEW %rogramming& a VI /erver can be use to %rogrammaticall+ control front
%anel ob-ects& VIs& and LabVIEW& and to d+namicall+ load& edit& and run VIs on a
com%uter or remotel+ across a netork! 0ou can control broser access to t$e VIs and
configure $ic$ VIs remote a%%lications can control!
Confi!urin! t$e VI Ser*er Pa!e
/elect ToolsUC%tions to dis%la+ t$e C%tions dialog bo# and select VI /erver from t$e
(ategor+ list to dis%la+ t$is %age! If a target in a LabVIEW %ro-ect su%%orts t$e VI
/erver& +ou also can rig$t-click t$e target& suc$ as .+ (om%uter& select Aro%erties
from t$e s$ortcut menu& and select VI /erver from t$e (ategor+ list to dis%la+ t$is
%age!
To configure VI /erver o%tions for t$e main a%%lication instance& dis%la+ t$is %age
from t$e C%tions dialog bo#! To configure VI /erver o%tions for a target& dis%la+ t$is
%age from t$e Aro%erties dialog bo# for t$e target! To configure VI /erver settings for
a %ro-ect a%%lication instance& rig$t-click t$e target in t$e Aro-ect E#%lorer indo!
T$e VI /erver %age includes t$e folloing com%onents3
ArotocolsV6se t$is section to configure t$e VI /erver! T$e default VI /erver
settings are "ctiveM enabled and T(AEIA disabled!
o T(AEIAVEnables VI server su%%ort for T(AEIA! If +ou allo remote a%%lications
to connect using T(AEIA& +ou also s$ould s%ecif+ $ic$ mac$ine addresses can
access t$e VI /erver in t$e .ac$ine "ccess section of t$is %age! T$is c$eckbo#
does not contain a c$eckmark b+ default!
AortV/ets t$e T(AEIA %ort at $ic$ t$e VI server listens for re*uests!
From ToolsUC%tions t$is %ort number is 99=9& b+ default& $ic$ is a
registered %ort number reserved for use b+ LabVIEW! For targets& t$e
default is < causing t$e o%erating s+stem to d+namicall+ select a %ort! If
+ou ant to run multi%le a%%lication instances on t$e mac$ine& eac$ it$
its on VI /erver running& +ou must $ave a uni*ue VI /erver %ort
number! 0ou also can use t$e /erver3Aort %ro%ert+ to set t$e LabVIEW VI
/erver %ort %rogrammaticall+!
/ervice nameV/ets t$e service name for t$e VI /erver T(A Instance! To
retrieve an a%%lication reference it$out t$e %ort number& use /ervice
name in con-unction it$ t$e C%en "%%lication Reference function b+
iring a /ervice name to t$e %ol+mor%$ic %ort number or /ervice name
in%ut!
If +ou dis%la+ t$is %age from t$e C%tions dialog bo#& t$is service name is
.ain "%%lication InstanceEVI /erver b+ default! If +ou dis%la+ t$is %age
from t$e Aro%erties dialog bo# for a target& t$e service name is target
nameEVI /erver b+ default! 0ou can use t$e /erver3/ervice 4ame
%ro%ert+ to set t$e service name %rogrammaticall+!
6se defaultV/ets /ervice name to its default value! T$is
1211
c$eckbo# contains a c$eckmark b+ default! To edit /ervice name&
remove t$e c$eckmark from t$e c$eckbo#!
o "ctiveMV1Windos2 Enables VI server su%%ort for "ctiveM "utomation! T$is
c$eckbo# is available onl+ from t$e ToolsUC%tions navigation! T$is c$eckbo#
contains a c$eckmark b+ default!
VI /cri%tingV6se t$is section to enable VI /cri%ting!
o /$o VI /cri%ting functions& %ro%erties and met$odsVEnables VI /cri%ting
functions on t$e VI /cri%ting %alette and additional VI /erver %ro%erties and
met$ods! "ll functions& %ro%erties& and met$ods +ou enable t$roug$ VI /cri%ting
dis%la+ as blue!
?is%la+ additional VI /cri%ting information in (onte#t Hel% indoV
?is%la+s connector %ane terminal numbers in t$e (onte#t Hel% indo!
Alace a c$eckmark in t$e /$o VI /cri%ting functions& %ro%erties and
met$ods c$eckbo# to enable t$is o%tion!
"ccessible /erver ResourcesV6se t$is section to indicate t$e tasks t$at remote
a%%lications can accom%lis$!
o VI callsV"llos remote a%%lications to call VIs e#%orted t$roug$ t$e VI /erver!
If +ou allo remote a%%lications access to VIs& s%ecif+ $ic$ VIs can be
e#%orted! T$is c$eckbo# contains a c$eckmark b+ default!
o VI %ro%erties and met$odsV"llos remote a%%lications to read and set t$e
%ro%erties of VIs and to call met$ods for VIs t$roug$ t$e VI /erver! If +ou allo
remote a%%lications access to VIs& s%ecif+ $ic$ VIs can be e#%orted! T$is
c$eckbo# contains a c$eckmark b+ default!
o "%%lication %ro%erties and met$odsV"llos remote a%%lications to read and set
t$e %ro%erties of t$e a%%lication instance and to call met$ods for t$e a%%lication
instance t$roug$ t$e VI /erver! T$is c$eckbo# contains a c$eckmark b+ default!
o (ontrol %ro%erties and met$odsV"llos remote a%%lications to read and set t$e
%ro%erties of controls and to call met$ods for controls t$roug$ t$e VI /erver!
T$is c$eckbo# contains a c$eckmark b+ default!
.ac$ine "ccessV6se t$is section to control mac$ine access to VIs t$roug$ t$e VI
/erver!
o /ac'ine access ,ist2Lists mac'ines t'at #o an# #o not 'ave access to t'e VI Server.
3o a,so can se t'e Server:4CP5IP 6ccess List propert& to ,ist programmatica,,& t'e
4CP5IP a##resses of mac'ines t'at ma& access t'e VI server.
4ote3 If +ou c$ange t$e .ac$ine access list& mac$ines t$at are
currentl+ connected to t$e VI server ill not be disconnected even if
t$e+ are no longer alloed access to t$e server!
o .ac$ine nameEaddressVEnter t$e name or IA address of t$e mac$ine +ou
ant to add to t$e .ac$ine access list!
o "llo accessV"llos access to t$e mac$ine1s2 selected in .ac$ine access list!
o ?en+ accessV?enies access to t$e mac$ine1s2 selected in .ac$ine access list!
o "ddV"dds a ne entr+ to t$e .ac$ine access list! T$e ne entr+ a%%ears
belo t$e selected entr+ in t$e .ac$ine access list!
1221
o RemoveVRemoves t$e selected entr+ from t$e .ac$ine access list!
E#%orted VIsV6se t$is section to add& edit& and remove VIs from t$e E#%orted VIs
list!
o E#%orted VIs listVLists t$e VIs t$at can be e#%orted! 0ou also can use t$e
/erver3VI "ccess List %ro%ert+ to list %rogrammaticall+ t$e VIs on t$e VI /erver
t$at are accessible b+ remote clients!
o E#%orted VIVEnter a VI to list in E#%orted VIs! 0ou can use ildcards in t$e VI
name or director+ %at$ +ou enter!
o "llo accessV"llos access to t$e VI1s2 selected in E#%orted VIs! T$is o%tion
is selected b+ default!
o ?en+ accessV?enies access to t$e VI1s2 selected in E#%orted VIs!
o "ddV"dds a ne entr+ to E#%orted VIs!
o RemoveVRemoves t$e selected entr+ from E#%orted VIs!
6ser "ccessV6se t$is section to control user access to VIs t$roug$ t$e VI /erver!
0ou also can use t$e ?omain "ccount .anager to manage domain users and
grou%s!
o 7ser an# grop access ,ist2Lists sers an# grops t'at can an# cannot access t'e VI
Server. If &o #o not inc,#e sers or grops in t'is ,ist0 a,, sers an# grops associate#
wit' mac'ines t'at 'ave access permission can access t'e VI Server.
4ote3 If t$e 6ser and grou% access list is c$anged& users t$at are
currentl+ connected to t$e server ill not be disconnected even if
t$e+ are no longer alloed access to t$e VI /erver!
o "llo accessV"llos access to t$e users and grou%s selected in 6ser and
grou% access list!
o ?en+ accessV?enies access to t$e users and grou%s selected in 6ser and
grou% access list!
o "ddV?is%la+s t$e "dd 6sers and Drou%s dialog bo#& in $ic$ +ou can select a
domain& user& and grou%!
o RemoveVRemoves t$e selected entr+ from t$e 6ser and grou% access list!
1231
VI Ser*er Application
(om%lete t$e folloing ste%s to create a VI /erver a%%lication3
1. (onfigure t$e VI /erver to allo t$e T(AEIA %rotocol!
2. 7se t'e 8pen 6pp,ication 9eference fnction to open a reference to a ,oca, or remote
app,ication instance.
4ote3 If +ou $ave multi%le a%%lication instances o%en simultaneousl+&
suc$ as if +ou are orking it$ a LabVIEW %ro-ect or targets of a
LabVIEW %ro-ect& multi%le VI /ervers can be listening on different %orts!
C%en an a%%lication reference to a s%ecific a%%lication instance b+
stating t$e mac$ine name and t$e %ort or service name!
3. 6se t$e C%en VI Reference function to o%en a reference to a VI on t$e local or
remote com%uter t$at alread+ e#ists in memor+ for t$e a%%lication instance& or to
d+namicall+ load a VI from disk! Hoever& be aare t$at if t$e in%ut to vi %at$ is a
file %at$& t$is function aits until t$e user interface is idle to load t$e VI from disk!
". 6se t$e Aro%ert+ 4ode to get or set %ro%erties or t$e Invoke 4ode to
invoke met$ods!
$. 0ou also can use a (all '+ Reference 4ode to call a d+namicall+ loaded
VI !
6. 6se t$e (lose Reference function to close an+ o%en references!
12"1
Section 7: Errors $andlin! VI;s and "unctions
Have +ou ever onder $at is t$e loest line in most of t$e VIFs8 T$at line is an s%ecial line
called Error InECut! T$is line is an s%ecial cluster T+%e called Error cluster& $ic$ consists of3
7! 'oolean3 Indicating if t$ere is an error!
,! 9,-bit Integer3 Indicating t$e code of t$e error!
9! /tring3 Indicating t$e source of t$e error& i!e! t$e cause of t$e error!
T$is cluster $as t$e same %ro%erties of an+ ot$er clusters& $oever it $as ot$er s%ecial
features! T$e first of t$em is t$at t$is line is usuall+ used to guarantee se*uence! Folloing
t$e LabVIEW rule t$at establis$es t$at an+ subVI or function needs to $ave all its in%uts in
order to run& if t$e out%ut error line is connected to t$e in%ut of anot$er subVI& t$e second
subVI onFt run until t$e %revious ends!
"not$er c$aracteristic of t$e error cluster is t$at& $en connected to a case structure& it ill
create to cases3 Error and 4o Error& $ic$ can be used to ski% ste%s t$at canFt be e#ecuted
unless ever+t$ing else $as no errors! "lso is used to guarantee se*uence $en t$ere are
functions or VIFs t$at doesnFt $ave error line!
T$ere are to different a+s of $andling errors& automatic and manuall+!
Automatic3 W$en LabVIEW is configured to $andle t$e VIFs automaticall+ 1FileL VI
Aro%ertiesLE#ecutionLEnable "utomatic Error Handling2& $en it encounters a unired
Error line& it ill $alt t$e e#ecution and $ig$lig$t $ere t$e error occurred!
<anual3 To $andle erros manuall+ t$ere are certain VIFs meant to do it $ic$ are
%resent at t$e ArogrammingL?ialogW6serInterface3
12$1
o /im%le Error $andler and Deneral Error Handler3 ?is%la+s $en an error
occurred& s$oing t$e cause of t$e error and o%tionall+ an error dialog bo#& t$e
difference beteen t$e sim%le and t$e general is t$at t$e general also acce%ts
custom error codes!
o .erging& creating& clearing and searc$ing error VIFs3 also t$e user ma+ need to
clear errors if t$e %rogram solves t$e %roblem b+ itself& also& $en building
/ubVIFs it is im%ortant to add t$e %revious errors to t$e errors t$at can be added
from t$e subVI& and after several subVIFs adding error& is useful to searc$ for t$e
first error& since t$e error $andler VIFs s$os t$e error it$ most %riorit+!
o 6ser interface ?ialog 'o#es3 T$is VIFs are used to inform t$e user $enever an
error occurred and also to allo t$e user to decide t$e action to im%lement if t$e
%rogram re*uires it!
W$en creating VIFs& e mig$t %roduce errors t$at LabVIEW doesnFt inter%ret t$em as errors!
For e#am%le& $en e $ave a division b+ <3
1261
LabVIEW ill give infinite as result& $oever& for some a%%lication t$at means t$at an error
occurred! For t$ose cases& it is %ossible to create +our on error codes and im%lement t$em
in labVIEW! To do so& it is necessar+ to create a X-error!t#t file! Fortunatel+ LabVIEW $as an
interface meant to $el% creating t$is file3 ToolsL"dvancedLEdit Error (odes! It ill ask +ou if
+ou ant to create a ne file or edit one& eit$er a+ +ou can add or edit errors!
"ll t$e errors are saved at Y4ational Instruments LocationL L/$aredLErrors!
12+1
Section =: VI Desi!n Patterns
A !eneral VI desi!n pattern consists of / main parts:
7! Startup3 InitialiBe $ardare or getting signals or data from a file!
,! <ain application3 "nal+Be t$e in%ut signal or data continuousl+ until it is
terminated b+ a conditional terminal or a user action!
9! S$utdo#n3 ?is%la+s out%ut data or log into file!
Desi!n Pattern Selection "lo# C$art
12*1
State <ac$ine Desi!n Pattern
T$e state mac$ine design %attern is used for algorit$ms t$at can be e#%licitl+
re%resented it$ a state diagram!
" state mac$ine in LabVIEW consist of folloing block diagram com%onents3
7! W$ile Loo%3 E#ecute current state continuousl+!
,! /$ift Register3 6sed to store and transit ne#t state to current state!
9! (ase /tructure3 (ontains %rogram code for eac$ state!
>! /tate Functionalit+ (ode3 Arogram code for eac$ state in case structure!
:! Transition (ode3 ?etermine ne#t state!
State <ac$ine Desi!n Pattern
%ueued <essa!e >andler:
It is used to im%lement code for a user interface! .essages is *ueued and $andled
one-b+-one in t$e order of t$e *ueue! Eac$ subdiagram in t$e *ueued message
$andler re%resents a $andling routine!
It is similar to a state mac$ine design but it$ t$e s$ift register $olding on to t$e
*ueued message!
12!1
Parallel Loop ? <aster-Sla*e Desi!n Pattern
Parallel Loop Desi!n Pattern
"bove block diagram illustrates t$e %arallel loo% design %attern! T$e error cluster ires
are used to e#ecute bot$ $ile loo%s in %arallel! Hoever& t$is design %attern is not efficient
as t$ere mig$t be a race condition $en im%lementing data accessing mec$anism $ere
t$ere ma+ be multi%le loo%s accessing t$e data at t$e same instance of time!
" solution to t$is ould be using t$e masterEslave design %attern as de%icted in block
diagram belo!
<aster-Sla*e Desi!n Pattern
13.1
T$e masterEslave design %attern is used for e#ecuting to or more %rocesses
simultaneousl+ and %ass data among %rocesses! T$is design %attern ma+ consist
multi%le %arallel loo%s& eac$ running at different rates! T$ere ill be a loo% acts
as t$e master $ic$ controls all t$e ot$er loo%s knon as t$e slave loo%s! T$e
race condition is avoided b+ using a notifies to %ass data from t$e master to t$e
slave! 'enefits of using notifies in masterEslave design %attern is t$at all slave
loo%s are s+nc$roniBed to t$e master loo%! /lave loo% e#ecutes onl+ $en t$e
master loo% sends a notification!
Producer-Consumer 9Data: Desi!n Pattern
Producer-Consumer 9Data: Desi!n Pattern
T$is design %attern en$ances t$e data s$aring among multi%le loo%s running at
different rates! T$e %arallel loo%s are se%arated into , categories3 t$e loo% %roducing
data 1%roducer2 and t$e loo% consuming data 1consumer2!
.ain benefits3
-Arocess multi%le sets of data in order!
-Tueues data in t$e consumer loo%!
'asicall+& t$e data is continuousl+ *ueued b+ t$e %roducer into t$e consumer loo%
*ueue and is %rocessed b+ t$e consumer loo% at its on %ace!
@ser Interface E*ent >andler Desi!n Pattern
T$e event-based design %attern benefits in terms of efficienc+ as t$e+ onl+ res%ond
$en an event occurs!
It consists of folloing block diagram com%onents3
1311
7! E*ent Structure3 (ontains %rogram code for eac$ detected user
interface event!
,! W$ile Loop3 .onitor user interface event continuousl+!
9! Timeout Terminal3 (ontrols $en t$e timeout event e#ecutes!
>! E*ent Data 3ode!
@ser Interface E*ent >andler Desi!n Pattern
1321
Producer-Consumer 9E*ent: Desi!n Pattern
Producer-Consumer 9E*ent: Desi!n Pattern
T$is design %attern is similar to t$e %roducerEconsumer 1data2 design %attern&
$oever& t$e consumer loo% e#ecutes as an event occurrence is detected in t$e
%roducer loo%!
.ain benefits3
-Efficientl+ res%onds as+nc$ronousl+ to t$e user interface!
-Tueues can transfer an+ data t+%e!
1331
"unctional Global Variable
6ninitialiBed s$ift registers in for or $ile loo%s can be used to $old data as long as
t$e VI never goes out of memor+! T$e s$ift register $olds t$e last state of t$e s$ift
register! T$us& a loo% it$ an uninitialiBed s$ift register is a functional global variable!
.ain 'enefits3
- (ontrol access to data in a s$ift register!
-Eliminate t$e %ossibilit+ of a race condition!
"unctional Global Variable
"bove is a VI e#am%le of a functional global variable& $en t$e enumerated in%ut is
I/etJ& t$e in%ut value is s$ifted and stored into t$e s$ift register! Cn t$e ot$er $and&
$en t$e enumerated in%ut is IDetJ& it ill retrieved t$e stored value from t$e s$ift
register and dis%la+ it at t$e out%ut!
13"1
Desi!n Patterns Table of Comparison
Desi!n Pattern @se Pros Cons
Deneral /tandard control
flo
?istinct initialiBe&
run and sto%
%$ases
6nable to return
to a %revious
state
/tate .ac$ine /tate se*uence
s+stem control
(ontrols
se*uences
?oes not store
future se*uences
to e#ecute
Tueued .essage
Handler
En$anced state
mac$ine it$
storing of future
se*uences to
e#ecute
1message2
/tores future
se*uences to
e#ecute
?oes not use
memor+
efficientl+
Aarallel Loo% .ulti%le task
%rocessing in a VI
Efficient use of
com%uting
resources
'ad
s+nc$roniBation
and $ave race
condition
.asterE/lave Aarallel loo%s
it$
s+nc$roniBation
Aasses
messages and
$andles loo%
s+nc$roniBation
?oes not lend
itself ell to
%assing data
AroducerE(onsu
mer 1?ata2
?ata %roducing
and %rocessing in
%arallel
/tores data for
later %rocessing
?oes not %rovide
loo%
s+nc$roniBation
6ser Interface
Event Handler
Res%onds to user
interface event
Handles user
interface
messages
?oes not allo
for intensive
%rocessing
a%%lications
AroducerE(onsu
mer 1Event2
AroducerE(onsu
mer 1?ata2 $ic$
res%onds to user
interface event
/e%arates t$e
user interface
from %rocessor-
intensive code
?oes not
integrate non-
user interface
events ell
13$1
Section A: SubVI Desi!n
.odularit+ is t$e %ro%ert+ of scaling a VI in sub modules $ic$ $ave s%ecial features and can
be rec+cled in ot$er VIFs! T$ese modules are called subVIFs& and& since a /ubVI is a VI
modified into a small block visualiBation& double clicking it ill o%en a front %anel and a block
diagram!
Ever+ /ubVI needs an Icon and a (onnector %ane to be called /ubVI3
a! Icon3 Dra%$ical re%resentation of a VI! (ustomiBable 1double click2
b! (onnector Aane3 .a% of t$e terminals of a VI! In%uts to t$e left& Cut%uts to t$e
rig$t 1accessing via rig$t clickL/$o (onnector2
T$e icon must be modified in order to re%resent $at does t$e /ubVI does& for t$is reason t$e
Icon Editor $as a built in %aint indo to modif+ t$e image3
T$e connector Aane re%resents t$e In%uts and Cut%uts of a /ubVI! T$ere are man+ t+%es of
connectors suited for an+ a%%lication! It is im%ortant to note t$at& for convention& In%uts goes
left and Cut%uts goes Rig$t! To link t$e terminal it$ t$e IEC3
: First (lick t$e terminal in t$e conector Aane
: T$e click on t$e In%ut or Cut%ut& t$e terminal ill c$ange color as a confirmation
: Finall+ c$oose if t$e connector is Re*uired& Recommended or C%tional b+ Rig$t
(licking t$e terminal L T$is (onnection isL
1361
W$en designing /ubVIFs& it is im%ortant to consider t$e %revious errors as t$e errors t$at t$e
/ubVI is adding& one of t$e most common error $andling met$ods in /ubVI is t$e ne#t one3
" %ol+mor%$ic VI is an s%ecial VI t$at acce%ts several ?ata T+%es& an e#am%le could be t$e
multi%l+ function& since it can acce%t an+ data T+%e! In order to create a %ol+mor%$ic VI is
necessar+ to create all t$e VIFs t$at are going to be %art of t$e %ol+mor%$ic VI it$ t$e same
connector %ane configuration! "fter t$at go to3 FileL4eLAol+mor%$ic VI! " ne indo ill
%rom%t& $ere +ou ill $ave to add all t$e VIFs! T$e icon of t$is VI ill also need to be created
b+ clicking into t$e Edit Icon! T$is VI ill automaticall+ decide $ic$ instance of t$e VIFs
added to use!
13+1
Section B: Debu!!in! VI;s
W$en +ou run a VI it ma+ $a%%en t$at it doesnFt even run or it does somet$ing +ou erenFt
e#%ecting!
If t$e VI doesnFt run& t$e first ste% is to c$eck t$e 'roken arro at t$e to% of t$e 'lock
?iagram or t$e Front Aanel3
T$e ne#t indo ill %rom%t3
13*1
T$e most common causes for a VI to be broken are3
9! T$e block diagram contains a broken ire!
>! " re*uired terminal of a /ubVI is not ired
:! " /ubVI is broken!
/o once t$e VI is not broken& t$e ne#t ste% is to run it& if it orks t$e debugging %rocess is
overZ Hoever& it mig$t $a%%en t$at t$e VI gives an une#%ected result or it $alts at t$e middle
of t$e e#ecution due to errors! T$e debugging %rocess is t$e ne#t one3
7! ($eck t$e errors if t$e+ e#ist!
,! 6se t$e conte#t Hel% in /ubVI to c$eck t$e default values and be sure t$at t$e default
value corres%onds to $at +ou ant!
9! Eliminate all t$e arnings
>! ($eck ?ata T+%es& sometimes $en using different data t+%es& information can be lost
due to ?ata T+%e casting!
If t$at doesnFt ork& t$e ne#t ste% is to debug t$e e#ecution of t$e VI using t$e ne#t tools
alone or combined3
; >i!$li!$t ECecution3 "n animation of t$e block ?iagram e#ecution it$ values at t$e
out%uts! T$is met$od s$os t$e movement of ?ata!
13!1
; Sin!le Steppin!3 E#ecutes onl+ one ste% of t$e VI! 6sed it$ t$e Hig$lig$ted
E#ecution %rovides an incredible debugging tool!
; Probin! Tools3 /$os t$e value over a ire! In Hig$lig$ting e#ecution or /ingle
/te%%ing! (lick on t$e Wire
; +rea,points3 Aause t$e e#ecution $enever t$ere is ne ?ata "t a Wire!
1".1
; Suspend #$en ECecuted3 T$is orks as a 'reak%oing for /ubVIFs! Cnce t$e /ubVI is
e#ecuted it ill %ause t$e $ole VI! "nd ill o%en t$e front %anel of t$e /ubVI!
1"11
Section : VI Desi!n and Documentation
0 @ser interface and bloc, dia!ram layout
a! 6I
i! Cne monitor or less
7! Tabs to organiBe and condense if too man+ controlsEindicators to
limit to one monitor
ii!Drou% controls and indicators logicall+
7! Related items s$ould be grou%ed toget$er
,! 6se decorations to clarif+ or em%$asiBe grou%ings
iii! Font and color
7! 6se brig$t colors s%aringl+ and onl+ for t$ings t$at need to stand
out 1i!e! sto% button2
,! Font s$ould be uniform
9! 'old te#t for grou%ing titles or $eading
>! Te#t siBe s$ould be logical
a! larger te#t for $eadings or im%ortant information&
b! te#t s$ould be siBed to t$e control @ fill buttons& but not
over$elm t$e front %anel
b0 bloc, dia!ram
i! minimiBe ire crossings and bends
ii!data flo s$ould go left to rig$t
iii! terminals s$ould be aligned 3 in%uts on t$e left& out%uts on t$e rig$t
)0 <odular and $ierarc$ical desi!n
a! 6se subVIs $en code is re%eated
b! (om%le# code t$at ac$ieves a single function can be %laced in a subVI
/0 subVI icons and connector pane layout
a! connector %ane la+out 1onl+ accessible from front %anel2
i! Left G in%uts& Rig$tG out%uts
ii!'ottom terminals on sides are usuall+ reserved for error ires
iii! To% terminals on side are usuall+ reserved for reference ires
b! Icons
i! Aicture s$ould describe $at t$e VI does
ii!/$ould $ave border- no IfloatingJ ire connections[confuses
%rogrammer
iii! Related subVIs s$ould $ave a related icons 1e#am%le3 ?"Tm# $as
bar at to% t$at sa+s ?"Tm#2
20 VI properties
a! ?ocumentation
i! /$os u% in conte#t $el%
b! Aassord %rotect
i! If distributing code to ot$ers& +ou can %ut a %assord on t$e block
diagram so t$e+ canFt reuse or recreate it
c! Windo a%%earance
i! 'asicall+ allos +ou to select t$e Iindo t+%eJ @ t$e main difference
beteen t$em is t$e number of menu bars visible!
1"21
d! Windo siBe @ useful if ill be run on a monitor it$ different resolution from
develo%ment mac$ine
e! Run-Time %osition @ $en it runs do +ou ala+s ant it to a%%ear in a s%ecific
location on t$e monitor8
50 Documentin! VIs
a! (ontrols Eindicators
i! ?escri%tion and ti% stri%
ii!Labels
iii! (a%tions
7! 6se ca%tions instead of labels to localiBe a VI it$out breaking t$e
VI! 6nlike a label& a ca%tion does not affect t$e name of t$e ob-ect
1$ic$ +ou ma+ be using to access t$at item %rogrammaticall+
t$roug$ VI /erver2& and +ou can use a ca%tion as a more
descri%tive ob-ect label! T$e ca%tion a%%ears onl+ in t$e front
%anel indo!
b! FA and '?
i! Free labels- te#t bo#es not associatedEtied to an ob-ect
ii!/elf documenting code @ using clusters and t$e 6nbundle b+ 4ame so
t$at t$e labels are visible in t$e unbundle
iii! Wire labels for long ires 1no available in LV ,<7<& ot$erise use
free labels to label ires2
c! VI
i! ?ocumentation under VI Aro%erties
7! T$is ill s$o u% in t$e (onte#t Hel% Windo
,! Rig$t-click on VI Icon LL VI Aro%erties LL ?ocumentation
1"31
Section ): <emory4 Performance4 and Determinism
0 Tools for identifyin! memory and performance issues
c! Arofile memor+ and %erformance
i! Tools LLArofileLLArofile Aerformance and .emor+
ii!tool for anal+Bing $o +our a%%lication uses e#ecution time and memor+!
iii! identif+ t$e s%ecific VIs or %arts of VIs to o%timiBe
7! For e#am%le& if +ou notice t$at a %articular subVI takes a long time
to e#ecute& +ou can focus +our attention on im%roving t$e
%erformance of t$at VI!
iv! %rovides a roug$ estimate of t$e average e#ecution time of t$e VIs
used in an a%%lication!
7! limited to millisecond resolution!
,! ?ue to t$e non-deterministic e#ecution& e#ecution time s$ould be
averaged over several iterations for accurate measurements! VI
Time dis%la+s t$e total amount of time s%end e#ecuting eac$ VI!
d! /$o buffer allocations
i! Tools LLArofileLL/$o 'uffer "llocations
7! /$os $ere buffers are created on t$e block diagram
,! ?oes 4CT s$o buffer size & $ic$ is de%endent on data t+%e
9! Feer buffer allocations 1using ires instead of local variables&
$ic$ creates a co%+2 means faster %erformance
e! VI metrics- VI "nal+Ber
i! interactivel+ and %rogrammaticall+ test VIs to identif+ areas for
im%rovement!
ii!main categories3
\ +loc, Dia!ram @ ($ecks block diagram %erformance and st+le
issues& suc$ as iring& loo% and structure usage& coercion dots& and
unnecessar+ elements on t$e block diagram!
\ CompleCity <etrics @ ($ecks for VI com%le#it+& suc$ as nesting&
code reuse& and modularit+!
\ Documentation @ ($ecks for documentation for develo%ers and
users it$in a VI& suc$ as VI and control descri%tions and block diagram
comments! ($ecks t$e s%elling on VIs& front %anels& and block diagrams!
\ "ront Panel @ ($ecks front %anel design and user interface
issues& suc$ as control usage& font selection& and labels!
\ General @ ($ecks %erformance and st+le issues t$at do not fit into
t$e ot$er categories& suc$ as file %ro%erties& icons and connector %anes&
and VI %ro%erties!
\ VI <etrics @ ($ecks block diagram and front %anel metrics& suc$
as t$e number of connector %ane in%uts and out%uts& controls and
indicators& and nodes!
,! Pro!rammin! practices
a! Enforcing data flo
1""1
i! Hel%ful to use an error ire to enforce data flo
b! 6I u%dates and res%onse to user interface controls
i! 4o need to u%date 6I faster t$an :-7< %er second& because $umans
canFt detect a c$ange faster t$an t$at and monitors $ave a limited u%date
rate too
ii!Wa+s to u%date 6I
7! 'est3 ire directl+ to terminal
,! 'etter3 local variable- ma+ re*uire co%+ to be made -L slodon
9! Dood3 %ro%ert+ nodes- ma+ re*uire co%+ and to load front %anel
into memor+ if not alread+
iii! 6se Event structure over %olling front %anel @ Islee%ingJ functions
1like event structure2 are more efficient
c! ?ata t+%e selection& coercion& and buffer allocation
i! For numbers t$at can onl+ be integers& use I9,& 69,& I7=& 67=& IO& 6
ii!'it de%t$- t$e number in 6O or u7= is based on $o man+ bits +ou need
to re%resent t$e number
7! For e#am%le& a 6O number can count from < to ,::& if +ou ere to
add anot$er to a 6O $en it is at ,:: it ould ra% around to <!
iii! "void coercion- causes to memor+ locations for eac$ version of
t$e value and is less efficient on lo level
iv! To create files t$at take t$e least amount of memor+& use t$e
smallest numeric re%resentation %ossible for +our %recision needs!
v!C%timiBe code to allocate feer number of buffers
d! "rra+& string& and loo% o%erations
i! 'uilding arra+s d+namic ill use significantl+ more memor+ because LV
$as to reallocate an entire ne memor+ s%ace $en an element is added
@ it is better to initialiBe an arra+ to t$e ma#imum siBe and use re%lace
arra+ subset
7! "%%ending to an arra+ is better t$an %re%ending to an arra+
because of buffer allocation re*uirements
,! "uto-inde#ing is also better because LV can %redict t$e buffer siBe
a$ead of time 1$as to kno for number of loo% iterations an+a+2
e! Local and global variables& %ro%ert+ nodes& and references
i! ?o not use a variable $ere a ire can be used- goes against LVFs data
flo %aradigm
7! 6sing a %ro%ert+ node to u%date a front %anel value causes t$e
front %anel of t$e target VI to load into memor+ G slos don code
if front %anel is not alread+ in memor+
ii!(an call subVIs b+ reference instead of -ust %utting t$em on t$e block
diagram
7! Cn block diagram3 subVI loaded into memor+ $en main VI is
loaded 1ever seen t$e screen $ere LV is looking for t$e subVIs 8
it %rom%ts +ou to c$oose it if it canFt find it2
,! '+ reference3 subVI loaded $en called
1"$1

Anda mungkin juga menyukai