Sei sulla pagina 1di 122

1e|emark Un|vers|ty Co||ege

ueparLmenL of LlecLrlcal Lnglneerlng, lnformaLlon 1echnology and CyberneLlcs


Faculty of Technology, Postboks 203, Kjlnes ring 56, N-3901 Porsgrunn, Norway. Tel: +47 35 57 50 00 Fax: +47 35 57 54 01





lnLroducLlon Lo LabvlLW
PAnS-L11L8 PALvC8SLn, 2014.03.07


ll

reface
1hls documenL explalns Lhe baslc concepLs of LabvlLW.
?ou flnd addlLlonal resources, code, eLc. here:
hLLp://home.hlL.no/~hansha/?LuLorlal=labvlew

?ou need Lo lnsLall Lhe LabvlLW rofesslonal uevelopmenL SysLem.

lor more lnformaLlon abouL LabvlLW, vlslL my 8log: hLLp://home.hlL.no/~hansha/



lll

1able of ConLenLs
reface ....................................................................................................................................... ll
1able of ConLenLs ...................................................................................................................... lll
1 lnLroducLlon ........................................................................................................................ 1
1.1 uaLaflow rogrammlng ................................................................................................ 1
1.2 Craphlcal rogrammlng ............................................................................................... 1
1.3 8eneflLs ........................................................................................................................ 2
2 SLarL uslng LabvlLW ............................................................................................................ 4
2.1 1he LabvlLW LnvlronmenL .......................................................................................... 4
2.2 lronL anel .................................................................................................................. 3
2.3 8lock ulagram .............................................................................................................. 7
2.4 ConLrols aleLLe ......................................................................................................... 10
2.4.1 numerlc Sub aleLLe ........................................................................................... 12
2.4.2 8oolean Sub aleLLe ............................................................................................ 13
2.4.3 SLrlng & aLh Sub aleLLe .................................................................................... 13
2.3 luncLlon aleLLe ......................................................................................................... 13
2.6 1ools aleLLe .............................................................................................................. 14
2.7 Wlrlng ........................................................................................................................ 16
2.8 1oolbar ....................................................................................................................... 16
2.9 LxecuLlon ................................................................................................................... 17
2.10 1he Cb[ecLs shorL-cuL menu .................................................................................... 18
2.11 uaLaflow rogrammlng ........................................................................................... 19
2.12 Pelp ......................................................................................................................... 20
Lxerclses ............................................................................................................................. 20
lv 1able of ConLenLs

1uLorlal: An lnLroducLlon Lo LabvlLW
3 Sub vls .............................................................................................................................. 24
3.1 CreaLe new Sub vl from ScraLch ................................................................................ 26
3.1.1 lnpuL and CuLpuL Subvl ConnecLors ................................................................... 26
3.1.2 lcon LdlLor ........................................................................................................... 28
3.2 CreaLe Sub vl from exlsLlng code ............................................................................... 29
3.3 uslng Sub vls ............................................................................................................. 30
Lxerclses ............................................................................................................................. 31
4 CusLomlze LabvlLW .......................................................................................................... 33
Lxerclses ............................................................................................................................. 34
3 Loops and SLrucLures ........................................................................................................ 33
3.1 Loops ......................................................................................................................... 33
3.1.1 lor Loop .............................................................................................................. 36
3.1.2 Whlle Loop .......................................................................................................... 37
3.2 SLrucLures .................................................................................................................. 38
3.2.1 Case SLrucLure ..................................................................................................... 38
3.2.2 Sequence SLrucLure ............................................................................................ 39
3.2.3 LvenL SLrucLure ................................................................................................... 40
Lxerclses ............................................................................................................................. 42
6 1roubleshooLlng and uebugglng ...................................................................................... 43
6.1 Pow Lo flnd errors ..................................................................................................... 43
6.2 PlghllghL LxecuLlon .................................................................................................... 43
6.3 robes ........................................................................................................................ 46
6.4 8reakpolnLs ................................................................................................................ 47
6.3 SLep lnLo/over/ouL debugglng ................................................................................... 48
Lxerclses ............................................................................................................................. 49
v 1able of ConLenLs

1uLorlal: An lnLroducLlon Lo LabvlLW
7 Worklng wlLh uaLa ............................................................................................................ 31
7.1 Arrays ......................................................................................................................... 31
7.1.1 AuLo-lndexlng ..................................................................................................... 31
7.1.2 Array luncLlons ................................................................................................... 32
7.2 ClusLer ........................................................................................................................ 34
7.2.1 ClusLer Crder ...................................................................................................... 33
7.2.2 ClusLer LlemenLs ................................................................................................. 36
Lxerclses ............................................................................................................................. 37
8 Worklng wlLh SLrlngs ........................................................................................................ 39
Lxerclses ............................................................................................................................. 61
9 Lrror Pandllng ................................................................................................................... 63
9.1 llndlng Lrror .............................................................................................................. 63
9.2 Lrror Wlrlng ............................................................................................................... 63
9.3 Lrror Pandllng ln Subvls ............................................................................................ 64
9.4 Lrror Pandllng ............................................................................................................ 63
Lxerclses ............................................................................................................................. 66
10 Worklng wlLh ro[ecLs .................................................................................................... 67
10.1 ro[ecL Lxplorer ....................................................................................................... 67
10.2 ueploymenL ............................................................................................................. 68
Lxerclses ............................................................................................................................. 71
11 ueslgn 1echnlques .......................................................................................................... 72
11.1 lorce rogram llow ................................................................................................. 72
11.2 ShlfL 8eglsLer ........................................................................................................... 73
11.3 SLaLe rogrammlng ArchlLecLure ............................................................................. 74
11.4 MulLlple Loops/arallel programmlng ..................................................................... 77
vl 1able of ConLenLs

1uLorlal: An lnLroducLlon Lo LabvlLW
11.3 1emplaLes ................................................................................................................ 78
Lxerclses ............................................................................................................................. 80
12 user lnLerface ................................................................................................................. 83
12.1 vl roperLles ............................................................................................................ 84
Lxerclses ............................................................................................................................. 87
13 loLLlng uaLa ................................................................................................................... 88
13.1 CusLomlzlng ............................................................................................................. 90
Lxerclses ............................................................................................................................. 92
14 1lps & 1rlcks .................................................................................................................... 94
14.1 10 funcLlons you need Lo know abouL ..................................................................... 94
14.2 1he 10 mosL useful ShorL-cuLs ................................................................................. 99
13 Lxample AppllcaLlon ..................................................................................................... 100
16 AddlLlonal Lxerclses ...................................................................................................... 103
17 WhaL's nexL? ................................................................................................................ 110
17.1 My 8log .................................................................................................................. 110
17.2 1ralnlng .................................................................................................................. 110
17.3 AddlLlonal 8esources ............................................................................................. 110
17.4 Lxamples ................................................................................................................ 110
17.3 uocumenLaLlon ...................................................................................................... 111
17.6 LabvlLW Wlkl ........................................................................................................ 112
17.7 LabvlLW on ?ou1ube ............................................................................................ 112
Culck 8eference .................................................................................................................... 113


1

1 lnLroducLlon
LabvlLW (shorL for LaboraLory VlrLual InsLrumenLaLlon Lnglneerlng Workbench) ls a
plaLform and developmenL envlronmenL for a vlsual programmlng language from naLlonal
lnsLrumenLs. 1he graphlcal language ls named "C". Crlglnally released for Lhe Apple
MaclnLosh ln 1986, LabvlLW ls commonly used for daLa acqulslLlon, lnsLrumenL conLrol, and
lndusLrlal auLomaLlon on a varleLy of plaLforms lncludlng MlcrosofL Wlndows, varlous flavors
of unlx, Llnux, and Mac CS x. 1he laLesL verslon of LabvlLW ls verslon LabvlLW 2011. vlslL
naLlonal lnsLrumenLs aL www.nl.com.
1he code flles have Lhe exLenslon .vl", whlch ls an abbrevlaLlon for vlrLual lnsLrumenL".
LabvlLW offers loLs of addlLlonal Add-Cns and 1oolklLs.
1.1 uaLaflow rogrammlng
1he programmlng language used ln LabvlLW, also referred Lo as C, ls a daLaflow
programmlng language. LxecuLlon ls deLermlned by Lhe sLrucLure of a graphlcal block
dlagram (Lhe Lv-source code) on whlch Lhe programmer connecLs dlfferenL funcLlon-nodes
by drawlng wlres. 1hese wlres propagaLe varlables and any node can execuLe as soon as all
lLs lnpuL daLa become avallable. Slnce Lhls mlghL be Lhe case for mulLlple nodes
slmulLaneously, C ls lnherenLly capable of parallel execuLlon. MulLl-processlng and
mulLl-Lhreadlng hardware ls auLomaLlcally explolLed by Lhe bullL-ln scheduler, whlch
mulLlplexes mulLlple CS Lhreads over Lhe nodes ready for execuLlon.
1.2 Craphlcal rogrammlng
LabvlLW Lles Lhe creaLlon of user lnLerfaces (called fronL panels) lnLo Lhe developmenL cycle.
LabvlLW programs/subrouLlnes are called vlrLual lnsLrumenLs (vls). Lach vl has Lhree
componenLs: a block dlagram, a fronL panel, and a connecLor panel. 1he lasL ls used Lo
represenL Lhe vl ln Lhe block dlagrams of oLher, calllng vls. ConLrols and lndlcaLors on Lhe
fronL panel allow an operaLor Lo lnpuL daLa lnLo or exLracL daLa from a runnlng vlrLual
lnsLrumenL. Powever, Lhe fronL panel can also serve as a programmaLlc lnLerface. 1hus a
vlrLual lnsLrumenL can elLher be run as a program, wlLh Lhe fronL panel servlng as a user
lnLerface, or, when dropped as a node onLo Lhe block dlagram, Lhe fronL panel deflnes Lhe
lnpuLs and ouLpuLs for Lhe glven node Lhrough Lhe connecLor pane. 1hls lmplles each vl can
be easlly LesLed before belng embedded as a subrouLlne lnLo a larger program.
2 lnLroducLlon
1uLorlal: An lnLroducLlon Lo LabvlLW

1he graphlcal approach also allows non-programmers Lo bulld programs slmply by dragglng
and dropplng vlrLual represenLaLlons of lab equlpmenL wlLh whlch Lhey are already famlllar.
1he LabvlLW programmlng envlronmenL, wlLh Lhe lncluded examples and Lhe
documenLaLlon, makes lL slmple Lo creaLe small appllcaLlons. 1hls ls a beneflL on one slde,
buL Lhere ls also a cerLaln danger of underesLlmaLlng Lhe experLlse needed for good quallLy
"C" programmlng. lor complex algorlLhms or large-scale code, lL ls lmporLanL LhaL Lhe
programmer possess an exLenslve knowledge of Lhe speclal LabvlLW synLax and Lhe
Lopology of lLs memory managemenL. 1he mosL advanced LabvlLW developmenL sysLems
offer Lhe posslblllLy of bulldlng sLand-alone appllcaLlons. lurLhermore, lL ls posslble Lo creaLe
dlsLrlbuLed appllcaLlons, whlch communlcaLe by a cllenL/server scheme, and are Lherefore
easler Lo lmplemenL due Lo Lhe lnherenLly parallel naLure of C-code.
1.3 8eneflLs
Cne beneflL of LabvlLW over oLher developmenL envlronmenLs ls Lhe exLenslve supporL for
accesslng lnsLrumenLaLlon hardware. urlvers and absLracLlon layers for many dlfferenL Lypes
of lnsLrumenLs and buses are lncluded or are avallable for lncluslon. 1hese presenL
Lhemselves as graphlcal nodes. 1he absLracLlon layers offer sLandard sofLware lnLerfaces Lo
communlcaLe wlLh hardware devlces. 1he provlded drlver lnLerfaces save program
developmenL Llme. 1he sales plLch of naLlonal lnsLrumenLs ls, Lherefore, LhaL even people
wlLh llmlLed codlng experlence can wrlLe programs and deploy LesL soluLlons ln a reduced
Llme frame when compared Lo more convenLlonal or compeLlng sysLems. A new hardware
drlver Lopology (uACmx8ase), whlch conslsLs malnly of C-coded componenLs wlLh only a
few reglsLer calls Lhrough nl MeasuremenL Pardware uuk (urlver uevelopmenL klL)
funcLlons, provldes plaLform lndependenL hardware access Lo numerous daLa acqulslLlon
and lnsLrumenLaLlon devlces. 1he uACmx8ase drlver ls avallable for LabvlLW on Wlndows,
Mac CS x and Llnux plaLforms.
1hls documenL lnLroduclng Lhe followlng Lhemes:
SLarL uslng LabvlLW
o 1he LabvlLW LnvlronmenL
o lronL anel and 8lock ulagram
o aleLLes: ConLrol aleLLe, luncLlons aleLLe, 1ools aleLLe
o uaLa 1ypes
o roperLy nodes
Sub vls
Loops and SLrucLures
1roubleshooLlng and uebugglng
3 lnLroducLlon
1uLorlal: An lnLroducLlon Lo LabvlLW

Worklng wlLh uaLa
o Arrays
! Array luncLlons
o ClusLer
Worklng wlLh SLrlngs
Lrror Pandllng
Worklng wlLh ro[ecLs uslng ro[ecL Lxplorer
ueslgn 1echnlques
o ShlfL 8eglsLer
o SLaLe Machlne
o MulLlple Loops
user lnLerface
loLLlng uaLa
ueploymenL: 8ulldlng LxecuLable AppllcaLlons (.exe)
lnLroducLlon Lo Add Cns and 1oolklLs
o 8rlefly explanaLlons.
o More deLall abouL ConLrol and SlmulaLlon 1oolklL ln laLer chapLer
lnLroducLlon Lo uAC - uaLa AcqulslLlon
o MAx - MeasuremenL and AuLomaLlon Lxplorer
o nl-uACmx
Culck 8eference wlLh keyboard ShorL-cuLs


lor more lnformaLlon abouL LabvlLW, vlslL my 8log: hLLp://home.hlL.no/~hansha/

4

2 SLarL uslng LabvlLW
1hls chapLer explalns Lhe baslc concepLs ln LabvlLW.
1he Loplcs are as follows:
1he LabvlLW LnvlronmenL
lronL anel and 8lock ulagram
aleLLes: ConLrol aleLLe, luncLlons aleLLe, 1ools aleLLe
uaLa 1ypes
roperLy nodes
2.1 1he LabvlLW LnvlronmenL
LabvlLW programs are called VlrLual InsLrumenLs, or vls, because Lhelr appearance and
operaLlon lmlLaLe physlcal lnsLrumenLs, such as oscllloscopes and mulLlmeLers. LabvlLW
conLalns a comprehenslve seL of Lools for acqulrlng analyzlng, dlsplaylng, and sLorlng daLa, as
well as Lools Lo help you LroubleshooL your code.
When openlng LabvlLW, you flrsL come Lo Lhe CeLLlng SLarLed" wlndow.

3 SLarL uslng LabvlLW
1uLorlal: An lnLroducLlon Lo LabvlLW

ln order Lo creaLe a new vl, selecL 8lank vl" or ln order Lo creaLe a new LabvlLW pro[ecL,
selecL LmpLy pro[ecL".
When you open a blank vl, an unLlLled fronL panel wlndow appears. 1hls wlndow dlsplays
Lhe fronL panel and ls one of Lhe Lwo LabvlLW wlndows you use Lo bulld a vl. 1he oLher
wlndow conLalns Lhe block dlagram. 1he secLlons below descrlbe Lhe fronL panel and Lhe
block dlagram.
2.2 lronL anel
When you have creaLed a new vl or selecLed an exlsLlng vl, Lhe lronL anel and Lhe 8lock
ulagram for LhaL speclflc vl wlll appear.

ln LabvlLW, you bulld a user lnLerface, or fronL panel, wlLh conLrols and lndlcaLors. ConLrols
are knobs, push buLLons, dlals, and oLher lnpuL devlces. lndlcaLors are graphs, LLus, and
oLher dlsplays.
?ou bulld Lhe fronL panel wlLh conLrols and lndlcaLors, whlch are Lhe lnLeracLlve lnpuL and
ouLpuL Lermlnals of Lhe vl, respecLlvely. ConLrols are knobs, push buLLons, dlals, and oLher
lnpuL devlces. lndlcaLors are graphs, LLus, and oLher dlsplays. ConLrols slmulaLe lnsLrumenL
6 SLarL uslng LabvlLW
1uLorlal: An lnLroducLlon Lo LabvlLW

lnpuL devlces and supply daLa Lo Lhe block dlagram of Lhe vl. lndlcaLors slmulaLe lnsLrumenL
ouLpuL devlces and dlsplay daLa Lhe block dlagram acqulres or generaLes.
L.g., a numerlc" can elLher be a numerlc ConLrol" or a numerlc lndlcaLor", as seen below.

l you selecL a numerlc ConLrol", lL can easy be changed Lo an numerlc lndlcaLor" by rlghL
cllck on Lhe ob[ecL an selecL Change Lo lndlcaLor"

Cr opposlLe, l you selecL a numerlc lndlcaLor", lL can easy be changed Lo an numerlc
ConLrol" by rlghL cllck on Lhe ob[ecL an selecL Change Lo ConLrol"
7 SLarL uslng LabvlLW
1uLorlal: An lnLroducLlon Lo LabvlLW



1he dlfference beLween a numerlc ConLrol" and a numerlc lndlcaLor" ls LhaL for a
numerlc ConLrol" you may enLer a value, whlle Lhe numerlc lndlcaLor" ls read-only, l.e.,
you may only read Lhe value, noL change lL.

1he appearance ls also sllghLly dlfferenL, Lhe numerlc ConLrol" has an lncremenL and an
decremenL buLLon ln fronL, whlle Lhe numerlc lndlcaLor" has a darker background color ln
order Lo lndlcaLe LhaL lLs read-only.
2.3 8lock ulagram
AfLer you bulld Lhe user lnLerface, you add code uslng vls and sLrucLures Lo conLrol Lhe fronL
panel ob[ecLs. 1he block dlagram conLalns Lhls code. ln some ways, Lhe block dlagram
resembles a flowcharL.
8 SLarL uslng LabvlLW
1uLorlal: An lnLroducLlon Lo LabvlLW



AfLer you bulld Lhe fronL panel, you add code uslng graphlcal represenLaLlons of funcLlons Lo
conLrol Lhe fronL panel ob[ecLs. 1he block dlagram conLalns Lhls graphlcal source code. lronL
panel ob[ecLs appear as Lermlnals, on Lhe block dlagram. 8lock dlagram ob[ecLs lnclude
Lermlnals, subvls, funcLlons, consLanLs, sLrucLures, and wlres, whlch Lransfer daLa among
oLher block dlagram ob[ecLs.
1he llgure below shows a fronL panel and lLs correspondlng block dlagram wlLh fronL panel
and block dlagram componenLs.
9 SLarL uslng LabvlLW
1uLorlal: An lnLroducLlon Lo LabvlLW


1he dlfferenL componenLs are as follows:
1. 1oolbar
2. Cwned Label
3. numerlc ConLrol
4. lree Label
3. numerlc ConLrol 1ermlnal
6. knob 1ermlnal
7. numerlc ConsLanL
8. MulLlply luncLlon
9. lcon
10. knob ConLrol
10 SLarL uslng LabvlLW
1uLorlal: An lnLroducLlon Lo LabvlLW

11. loL Legend
12. x? Craph
13. Wlre uaLa aLh
14. x? Craph 1ermlnal
13. 8undle luncLlon
16. Subvl
17. lor Loop SLrucLure
2.4 ConLrols aleLLe
1he ConLrols and luncLlons paleLLes conLaln sub paleLLes of ob[ecLs you can use Lo creaLe a
vl. When you cllck a sub paleLLe lcon, Lhe enLlre paleLLe changes Lo Lhe sub paleLLe you
selecLed. 1o use an ob[ecL on Lhe paleLLes, cllck Lhe ob[ecL and place lL on Lhe fronL panel or
block dlagram. 1he ConLrols paleLLe ls avallable only on Lhe fronL panel. 1he ConLrols paleLLe
conLalns Lhe conLrols and lndlcaLors you use Lo bulld Lhe fronL panel.

11 SLarL uslng LabvlLW
1uLorlal: An lnLroducLlon Lo LabvlLW

1he mosL used Sub aleLLes are Lhe numerlc Sub aleLLe, Lhe 8oolean Sub aleLLe and Lhe
SLrlng & aLh Sub aleLLe.
?ou may change Lhe appearance and Lhe conLenLs of Lhe ConLrols paleLLe:
?ou may ln Lhe paleLLe, so lL ls always vlslble, [usL cllck Lhe llLLle pln buLLon ln Lhe
upper lefL corner of Lhe paleLLe:

lf you wanL Lo change Lhe conLenL and appearance of Lhe paleLLe, cllck Lhe vlew" buLLon.

Pere you may change Lhe way Lhe paleLLe should look.

lf you cllck Change vlslble CaLegorles." you may change whlch CaLegorles you wanL Lo have
vlslble.
12 SLarL uslng LabvlLW
1uLorlal: An lnLroducLlon Lo LabvlLW


2.4.1 numerlc Sub aleLLe
numerlcal ConLrol" and numerlcal lndlcaLor" are Lhe mosL used ob[ecLs ln Lhe numerlc sub
paleLLe.

13 SLarL uslng LabvlLW
1uLorlal: An lnLroducLlon Lo LabvlLW

2.4.2 8oolean Sub aleLLe
1hls paleLLe has loLs of dlfferenL buLLons you may use. Ck, Cancel and SLop buLLons are
useful.

2.4.3 SLrlng & aLh Sub aleLLe
ln Lhe SLrlng and aLh paleLLe we have SLrlng ConLrols, Combo 8ox, eLc.

2.3 luncLlon aleLLe
14 SLarL uslng LabvlLW
1uLorlal: An lnLroducLlon Lo LabvlLW

1he luncLlons paleLLe ls avallable only on Lhe block dlagram. 1he luncLlons paleLLe conLalns
Lhe vls and funcLlons you use Lo bulld Lhe block dlagram.

2.6 1ools aleLLe
?ou can creaLe, modlfy, and debug vls uslng Lhe Lools locaLed on Lhe floaLlng 1ools paleLLe.
1he 1ools paleLLe ls avallable on boLh Lhe fronL panel and Lhe block dlagram. A Lool ls a
speclal operaLlng mode of Lhe mouse cursor. 1he cursor corresponds Lo Lhe lcon of Lhe Lool
selecLed ln Lhe 1ools paleLLe. use Lhe Lools Lo operaLe and modlfy fronL panel and block
dlagram ob[ecLs.
13 SLarL uslng LabvlLW
1uLorlal: An lnLroducLlon Lo LabvlLW


1he 1ools paleLLe ls avallable from Lhe vlew menu:

lf you make sure AuLomaLlc wlrlng" ls dlsabled (l recommend you do so!) you may use
Lhe 1ab key on your keyboard ln order Lo swlLch beLween Lhe mosL common Lools.
1he mosL used Lools are:
use Lhe Cperat|ng too|, shown aL lefL, Lo change Lhe values of a conLrol or selecL
Lhe LexL wlLhln a conLrol. 1he CperaLlng Lool changes Lo Lhe lcon shown aL lefL when lL
moves over a LexL conLrol, such as a numerlc or sLrlng conLrol.
use Lhe os|t|on|ng too|, shown aL lefL, Lo selecL, move, or reslze ob[ecLs. 1he
oslLlonlng Lool changes Lo reslzlng handles when lL moves over Lhe edge of a reslzable
ob[ecL.
use Lhe Labe||ng too|, shown aL lefL, Lo edlL LexL and creaLe free labels. 1he
Labellng Lool changes Lo Lhe followlng lcon when you creaLe free labels.
use Lhe W|r|ng too|, shown aL lefL, Lo wlre ob[ecLs LogeLher on Lhe block dlagram.
16 SLarL uslng LabvlLW
1uLorlal: An lnLroducLlon Lo LabvlLW


2.7 Wlrlng
ln order Lo creaLe Lhe loglcal flow beLween Lhe ob[ecL on Lhe 8lock ulagram, you need Lo use
Lhe Wlrlng Lool ln order Lo connecL Lhe dlfferenL ob[ecLs LogeLher.
use Lhe Wlrlng Lool Lo wlre ob[ecLs LogeLher on Lhe block dlagram.
Avallable keyboard ShorLcuLs when deallng wlLh Wlrlng:

Ctr|-8 ls very useful. 1hls shorL-cuL removes all broken wlres on Lhe 8lock ulagram.
2.8 1oolbar
8elow we see Lhe LabvlLW 1oolbar:

17 SLarL uslng LabvlLW
1uLorlal: An lnLroducLlon Lo LabvlLW

1he behavlors of Lhe dlfferenL buLLons are as follows:
Cllck Lhe 8un buLLon Lo run a vl. LabvlLW complles Lhe vl, lf necessary. ?ou can run a vl
lf Lhe 8un buLLon appears as a solld whlLe arrow. 1he solld whlLe arrow, shown above, also
lndlcaLes you can use Lhe vl as a subvl lf you creaLe a connecLor pane for Lhe vl.
Whlle Lhe vl runs, Lhe 8un buLLon appears as shown aL lefL lf Lhe vl ls a Lop-level vl,
meanlng lL has no callers and Lherefore ls noL a subvl.
lf Lhe vl LhaL ls runnlng ls a subvl, Lhe 8un buLLon appears as shown aL lefL.
1he 8un buLLon appears broken, shown aL lefL, when Lhe vl you are creaLlng or edlLlng
conLalns errors. lf Lhe 8un buLLon sLlll appears broken afLer you nlsh wlrlng Lhe block
dlagram, Lhe vl ls broken and cannoL run. Cllck Lhls buLLon Lo dlsplay Lhe Lrror llsL wlndow,
whlch llsLs all errors and warnlngs.
Cllck Lhe 8un ConLlnuously buLLon, shown aL lefL, Lo run Lhe vl unLll you aborL or pause
execuLlon. ?ou also can cllck Lhe buLLon agaln Lo dlsable conLlnuous runnlng.
Whlle Lhe vl runs, Lhe AborL LxecuLlon buLLon, shown aL lefL, appears. Cllck Lhls buLLon
Lo sLop Lhe vl lmmedlaLely lf Lhere ls no oLher way Lo sLop Lhe vl. lf more Lhan one runnlng
Lop-level vl uses Lhe vl, Lhe buLLon ls dlmmed.
noLe: Avold uslng Lhe AborL LxecuLlon buLLon Lo sLop a vl. LlLher leL Lhe vl compleLe lLs daLa
ow or deslgn a meLhod Lo sLop Lhe vl programmaLlcally. 8y dolng so, Lhe vl ls aL a known
sLaLe. lor example, place a buLLon on Lhe fronL panel LhaL sLops Lhe vl when you cllck lL.
Cllck Lhe ause buLLon, shown aL lefL, Lo pause a runnlng vl. When you cllck Lhe ause
buLLon, LabvlLW hlghllghLs on Lhe block dlagram Lhe locaLlon where you paused execuLlon,
and Lhe ause buLLon appears red. Cllck Lhe buLLon agaln Lo conLlnue runnlng Lhe vl.
2.9 LxecuLlon
ln addlLlon Lo Lhe 1oolbar buLLons above Lhe followlng keyboard ShorLcuLs are avallable
when deallng wlLh LxecuLlon:

18 SLarL uslng LabvlLW
1uLorlal: An lnLroducLlon Lo LabvlLW


2.10 1he Cb[ecLs shorL-cuL menu
1he mosL ofLen-used menu ls Lhe ob[ecL shorLcuL menu. All LabvlLW ob[ecLs and empLy
space on Lhe fronL panel and block dlagram have assoclaLed shorLcuL menus. use Lhe
shorLcuL menu lLems Lo change Lhe look or behavlor of fronL panel and block dlagram
ob[ecLs. 1o access Lhe shorLcuL menu, rlghL-cllck Lhe ob[ecL, fronL panel, or block dlagram.
1he numerlc conLrol has Lhe followlng shorL-cuL/rlghL-cllck menu:

19 SLarL uslng LabvlLW
1uLorlal: An lnLroducLlon Lo LabvlLW

1he shorL-cuL menu wlll be dlfferenL for Lhe dlfferenL conLrols or ob[ecLs.
2.11 uaLaflow rogrammlng
LabvlLW follows a daLaflow model for runnlng vls. A block dlagram node execuLes when all
lLs lnpuLs are avallable. When a node compleLes execuLlon, lL supplles daLa Lo lLs ouLpuL
Lermlnals and passes Lhe ouLpuL daLa Lo Lhe nexL node ln Lhe daLaflow paLh.
vlsual 8aslc, C++/C#, !ava, and mosL oLher LexL-based programmlng languages follow a
conLrol flow model of program execuLlon. ln conLrol flow, Lhe sequenLlal order of program
elemenLs deLermlnes Lhe execuLlon order of a program.

Lxamp|e: Dataf|ow rogramm|ng


1he Lxample shows a block dlagram LhaL adds Lwo numbers and Lhen subLracLs 30.00 from
Lhe resulL of Lhe addlLlon. ln Lhls case, Lhe block dlagram execuLes from lefL Lo rlghL, noL
because Lhe ob[ecLs are placed ln LhaL order, buL because Lhe SubLracL funcLlon cannoL
execuLe unLll Lhe Add funcLlon flnlshes execuLlng and passes Lhe daLa Lo Lhe SubLracL
funcLlon. 8emember LhaL a node execuLes only when daLa are avallable aL all of lLs lnpuL
Lermlnals, and lL supplles daLa Lo lLs ouLpuL Lermlnals only when lL flnlshes execuLlon.
Lxamp|e: Dataf|ow rogramm|ng

20 SLarL uslng LabvlLW
1uLorlal: An lnLroducLlon Lo LabvlLW

ln Lhls example, conslder whlch code segmenL would execuLe flrsL-Lhe Add, 8andom
number, or ulvlde funcLlon. ?ou cannoL know because lnpuLs Lo Lhe Add and ulvlde
funcLlons are avallable aL Lhe same Llme, and Lhe 8andom number funcLlon has no lnpuLs. ln
a slLuaLlon where one code segmenL musL execuLe before anoLher and no daLa dependency
exlsLs beLween Lhe funcLlons, use oLher programmlng meLhods, such as error clusLers, Lo
force Lhe order of execuLlon.
2.12 Pelp
1he ConLexL Pelp wlndow (CLrl +P) dlsplays baslc lnformaLlon abouL LabvlLW ob[ecLs
when you move Lhe cursor over each ob[ecL. 1he ConLexL Pelp wlndow ls vlslble by defaulL.
1o Loggle dlsplay of Lhe ConLexL Pelp wlndow, selecL Pelp-Show ConLexL Pelp, press Lhe
CLrl-P keys, or cllck Lhe Show ConLexL Pelp Wlndow buLLon on Lhe Loolbar.
When you move Lhe cursor over fronL panel and block dlagram ob[ecLs, Lhe ConLexL Pelp
wlndow dlsplays Lhe lcon for subvls, funcLlons, consLanLs, conLrols, and lndlcaLors, wlLh
wlres aLLached Lo each Lermlnal. When you move Lhe cursor over dlalog box opLlons, Lhe
ConLexL Pelp wlndow dlsplays descrlpLlons of Lhose opLlons. ln Lhe wlndow, requlred
connecLlons are bold, recommended connecLlons are plaln LexL, and opLlonal connecLlons
are dlmmed or do noL appear. 1he llgure below shows an example of Lhe ConLexL Pelp
wlndow.

Lxerclses
Lxerc|se: Create your f|rst LabVILW app||cat|on (VI)
21 SLarL uslng LabvlLW
1uLorlal: An lnLroducLlon Lo LabvlLW

CreaLe a slmple LabvlLW appllcaLlon (vl) wlLh a lronL anel wlLh some ConLrols and
lndlcaLors. CreaLe Lhe loglc by connecLlng Lhe 1ermlnals on Lhe 8lock ulagram
1he lronL anel could look someLhlng llke Lhls:

1he 8lock ulagram could look someLhlng llke Lhls:

SLarL Lhe program wlLh Lhe 8un buLLon.

Lxerc|se: Create a s|mp|e Ca|cu|ator
CreaLe a slmple calculaLor LhaL Add and SubLracL 2 numbers llke Lhls:
22 SLarL uslng LabvlLW
1uLorlal: An lnLroducLlon Lo LabvlLW



SLarL Lhe program wlLh Lhe 8un buLLon.

Lxerc|se: Wr|te Data to I||e
CreaLe a vl LhaL wrlLes daLa Lo a 1exL llle.
use vls or funcLlons from Lhe llle l/C paleLLe

1he program could look someLhlng llke Lhls:
23 SLarL uslng LabvlLW
1uLorlal: An lnLroducLlon Lo LabvlLW




Lxerc|se: kead Data from I||e
CreaLe anoLher vl LhaL read Lhe LexL flle you creaLed ln Lhe prevlous vl.

24

3 Sub vls
1hls chapLer explalns Lhe baslc concepLs of creaLlng and uslng Sub vls ln LabvlLW.
1oplcs:
CreaLe new Sub vl from ScraLch
CreaLe Sub vl from exlsLlng code
uslng Sub vls
When you place a vl on Lhe block dlagram, LabvlLW conslders Lhe vl Lo be a subvl. When
you double-cllck a subvl, lLs fronL panel and block dlagram appear, raLher Lhan a dlalog box
ln whlch you can conflgure opLlons. 1he fronL panel lncludes conLrols and lndlcaLors. 1he
block dlagram lncludes wlres, fronL panel lcons, funcLlons, posslbly subvls, and oLher
LabvlLW ob[ecLs. 1he upper rlghL corner of Lhe fronL panel and block dlagram dlsplays.
8elow we see an example of a bad 8lock ulagram. 1hls example does noL make use of Lhe
Subvl funcLlonallLy ln LabvlLW aL all! 1hls makes Lhe 8lock dlagram hard Lo read and
undersLand. 1he slze of Lhe dlagram ls also Loo large! 1he 8lock ulagram should always flL
lnLo Lhe screen. 8oLh Lhe lronL anel and Lhe 8lock ulagram should flL lnLo a screen
resoluLlon of 1024x768.

23 Sub vls
1uLorlal: An lnLroducLlon Lo LabvlLW

WlLh use of Subvls, Lhe example above could Lurn lnLo, e.g.:

As you can see, much of Lhe code ln Lhe Maln vl have been replaced and puL lnLo Subvls.
1he program ls now more readable.
AnoLher approach ls Lo use a so-called SLaLe Machlne prlnclple (more abouL Lhls ln chapLer
11 - ueslgn 1echnlques ).

Avallable keyboard ShorLcuLs when deallng wlLh Sub vls:

26 Sub vls
1uLorlal: An lnLroducLlon Lo LabvlLW

3.1 CreaLe new Sub vl from ScraLch
SelecL 8lank vl" ln Lhe CeLLlng SLarLed" wlndow when openlng LabvlLW, or when LabvlLW
ls already opened selecL llle - new v" or use Lhe shorL-cuL CLrl+n.
3.1.1 lnpuL and CuLpuL Subvl ConnecLors
MosL Subvls wlll have lnpuL and ouLpuL connecLors". 1hls ls slmllar wlLh funcLlons or
meLhods ln oLher programmlng language LhaL have lnpuL argumenLs and an ouLpuL/resulL.
ln order Lo creaLe connecLors, 8lghL-cllck on Lhe lcon ln Lhe upper rlghL corner of Lhe vl and
selecL Show ConnecLor".


?ou may selecL dlfferenL aLLerns, l.e., how many lnpuL and ouLpuL connecLors you need.
27 Sub vls
1uLorlal: An lnLroducLlon Lo LabvlLW


Make sure you selecL a aLLern wlLh enough connecLors even lf you don'L need all Lhe
connecLors aL Lhe momenL. l recommend LhaL you sLandardlze on Lhe paLLern ln Lhe llgure
above.
SelecL Lhe Wlre Lool and cllck on Lhe wanLed connecLor, Lhen cllck on Lhe ConLrol or
lndlcaLor on Lhe lronL anel you wanL Lo connecL Lo Lhls connecLor.

?ou should always follow Lhese connecLor rules:
upper lefL connecLor: 8eference" ln
upper rlghL connecLor: 8eference" CuL
Lower lefL connecLor: Lrror ln ClusLer
Lower rlghL connecLor: Lrror CuL ClusLer
Lxamp|e: SubVI Connectors
See example below abouL Lhese connecLor rules:
28 Sub vls
1uLorlal: An lnLroducLlon Lo LabvlLW


MosL common vls LhaL exlLs follow Lhese rules, see example below.

lf you follow Lhese connecLor rules lL's much easler Lo creaLe a clean and neaL code llke Lhls:

8y dolng Lhls lL's also clear how Lhe uaLa flows ln Lhe program. lL should always flow from
lefL Lo rlghL.
3.1.2 lcon LdlLor
?ou should also creaLe a sulLable lcon for your Subvl.
29 Sub vls
1uLorlal: An lnLroducLlon Lo LabvlLW

ln order Lo open Lhe lcon LdlLor, double-cllck on Lhe lcon ln Lhe upper rlghL corner of your vl.


8elow we see a block dlagram wlLh Subvls lcon appearance creaLed wlLh Lhe lcon LdlLor.

3.2 CreaLe Sub vl from exlsLlng code
lf you flnd ouL LhaL you code ls geLLlng messy, you could conslder puL some code lnLo a
Subvl.
30 Sub vls
1uLorlal: An lnLroducLlon Lo LabvlLW

1he procedure ls as follows:
1. SelecL Lhe parL of your code you wanL Lo Lurn lnLo a Subvl
2. lrom Lhe LdlL menu, selecL CreaLe Subvl"
3. LabvlLW wlll auLomaLlcally creaLe a Subvl for Lhe selecLed code.
4. Clean up auLomaLlcally creaLed wlres, eLc.
3. CreaLe a sulLable lcon for your Subvl

AlLhough Lhls ls qulLe easy Lo do Lhls, l do noL recommend LhaL you use Lhls funcLlonallLy Lo
much. 1hls ls because you should creaLe and use Subvls from Lhe flrsL momenL you sLarL
creaLlng your appllcaLlon and noL afLerwards when you flnd ouL LhaL you have been creaLlng
a messy code.
So you should sLrucLure and deslgn your code wlLh Lhe use of Subvls from Lhe beglnnlng!
3.3 uslng Sub vls
8elow we see an example of how Lo use Subvls ln a program (1op vl or Subvls):

31 Sub vls
1uLorlal: An lnLroducLlon Lo LabvlLW

?ou may open a Subvl from Lhe llle menu, selecL a Subvl from Lhe luncLlons paleLLe or use
drag and drop ln dlfferenL ways, e.g., you may drag a vl from Lhe llle Lxplorer ln Wlndows
dlrecLly lnLo an exlsLlng vl you have already opened ln LabvlLW
Lxerclses
Lxerc|se: Convert C to I VI
CreaLe a Subvl LhaL converL a 1emperaLure ln Celslus Lo a 1emperaLure ln lahrenhelL

1. CreaLe Lhe Subvl
2. CreaLe Lhe lronL anel and Lhe 8lock ulagram as shown above
3. CreaLe necessary ConnecLors
4. CreaLe a sulLable lcon, e.g.:

3. use Lhe Subvl ln anoLher vl
6. 8un Lhe program Lo see lf lL works
7. Lxpand Lhe program so you can selecL lf you wanL Lo converL from Celslus Lo
lahrenhelL or from lahrenhelL Lo Celslus
32 Sub vls
1uLorlal: An lnLroducLlon Lo LabvlLW



Lxerc|se: Convert ex|st|ng code |nto a SubVI
ConverL a parL of your appllcaLlon lnLo a Subvl by uslng Lhe CreaLe Subvl funcLlon ln
LabvlLW.




33

4 CusLomlze LabvlLW
LabvlLW has loLs of posslblllLles for cusLomlzlng Lhe appearance and Lhe use of Lhe LabvlLW
envlronmenL. SelecL CpLlons." from Lhe 1ools menu.

1he defaulL seLLlngs ls noL necessary Lhe besL, here are some recommendaLlons for seLLlng
up Lhe LabvlLW envlronmenL.
Category: 8|ock D|agram
34 CusLomlze LabvlLW
1uLorlal: An lnLroducLlon Lo LabvlLW


ulsable !"#$%& #()* +,-,"." opLlon. 1hls prevenLs LabvlLW from auLomaLlcally
connecLlng ad[acenL blocks. AlLhough lL seems useful Lo have auLo wlrlng enables, lL
ls my experlence LhaL Lhe auLo wlrlng ls a llLLle annoylng slnce lL Lends Lo draw wlres
beLween blocks when you do noL wanL any wlre.
ulsable /%#0& 1-*") 2#"&% &%&3&")4 #4 ,0*"45 *2),*". 1hls causes LabvlLW Lo use
small Lermlnal lcons on Lhe block dlagram. lf you, lnsLead, acLlvaLe Lhls opLlon, Lhe
Lermlnal lcons are larger, wlLh a mlmlc of Lhe elemenL as lL appears aL Lhe fronL
panel.
Category: Contro|s]Iunct|ons a|ettes
ln Lhe lormaL llsL: selecL 6#)&.*-7 890*"4 #": ;&<)="
Category: A||gnment Gr|d
1urn off >?*+ @-*") /#"&% A-,:" and >?*+ B%*0C D,#.-#3 A-,:"
Lxerclses
Lxerc|se: Custom|ze LabVILW
1ry Lhe dlfferenL seLLlngs explalned ln Lhls chapLer. 1urn Lhem on and off and waLch Lhe
dlfferenL.


33

3 Loops and SLrucLures
1hls chapLer explalns Lhe baslc concepLs of Loops and SLrucLures ln LabvlLW.
1he Loplcs are as follows:
lor Loop
Whlle Loop
Case SLrucLure
Sequence SLrucLure
LvenL SLrucLure
1he dlfferenL Loops and SLrucLures avallable are locaLed ln Lhe >)-(0)(-&4" sub paleLLe ln
Lhe luncLlons paleLLe on Lhe 8lock ulagram.

3.1 Loops
1he mosL lmporLanL loops are:
Ior Loop
Wh||e Loop
36 Loops and SLrucLures
1uLorlal: An lnLroducLlon Lo LabvlLW

1hese loops wlll be explalned ln deLall below.
3.1.1 lor Loop
A lor Loop execuLes a sub dlagram a seL number of Llmes. 1he llgure below shows an empLy
lor Loop ln LabvlLW.

A lor loop execuLes lLs sub dlagram n Llmes, where " ls Lhe value wlred Lo Lhe counL ( )
Lermlnal. 1he lLeraLlon ( ) Lermlnal provldes Lhe currenL loop lLeraLlon counL, whlch ranges
from 0 Lo "-1.
AfLer you creaLe a lor Loop, you can use sh|ft reg|sters Lo pass values from one lLeraLlon Lo
Lhe nexL. lf you wlre an array Lo a lor Loop, you can read and process every elemenL ln LhaL
array by enabllng auto-|ndex|ng. ?ou also can enable auLo-lndexlng by conflgurlng a lor
Loop Lo reLurn an array of every value generaLed by Lhe loop.
?ou can add a cond|t|ona| term|na| Lo conflgure a lor Loop Lo sLop when a 8oolean
condlLlon or an error occurs. A lor Loop wlLh a condlLlonal Lermlnal execuLes unLll Lhe
condlLlon occurs or unLll all lLeraLlons compleLe, whlchever happens flrsL. 1o add a
condlLlonal Lermlnal Lo a lor Loop, rlghL-cllck Lhe lor Loop border and selecL CondlLlonal
1ermlnal from Lhe shorLcuL menu. ?ou musL wlre Lhe condlLlonal Lermlnal and elLher wlre
Lhe counL Lermlnal or auLo-lndex an lnpuL array for Lhe loop Lo execuLe and for Lhe vl Lo run.
1o converL a lor Loop Lo a Whlle Loop, rlghL-cllck Lhe lor Loop and selecL 8eplace wlLh Whlle
Loop from Lhe shorLcuL menu.
Lxamp|e: Ior Loop
1he followlng example uses a lor Loop ln order Lo creaLe an array wlLh 10 elemenLs and flll lL
wlLh random numbers.
37 Loops and SLrucLures
1uLorlal: An lnLroducLlon Lo LabvlLW


3.1.2 Whlle Loop
A Whlle loop repeaLs Lhe sub dlagram lnslde lL unLll Lhe condlLlonal Lermlnal, an lnpuL
Lermlnal, recelves a parLlcular 8oolean value. 1he 8oolean value depends on Lhe
conLlnuaLlon behavlor of Lhe Whlle Loop. 8lghL-cllck Lhe condlLlonal Lermlnal and selecL Stop
|f 1rue or Cont|nue |f 1rue from Lhe shorLcuL menu. ?ou also can wlre an error clusLer Lo Lhe
condlLlonal Lermlnal, rlghL-cllck Lhe Lermlnal, and selecL Stop on Lrror or Cont|nue wh||e
Lrror from Lhe shorLcuL menu. 1he Whlle Loop always execuLes aL leasL once.
8elow we see an empLy Whlle loop:

AfLer you creaLe a Whlle Loop, you can use shlfL reglsLers Lo pass values from one lLeraLlon
Lo Lhe nexL. lf you wlre an array Lo a Whlle Loop, you can read and process every elemenL ln
LhaL array by enabllng auLo-lndexlng.
ln order Lo converL a Whlle Loop lnLo a lor Loop, rlghL-cllck Lhe Whlle Loop and selecL
8eplace wlLh lor Loop" from Lhe shorLcuL menu. 1o converL a Whlle Loop lnLo a 1lmed
Loop, rlghL-cllck Lhe Whlle Loop and selecL 8eplace wlLh 1lmed Loop" from Lhe shorLcuL
menu.
Lxamp|e: Wh||e Loop
38 Loops and SLrucLures
1uLorlal: An lnLroducLlon Lo LabvlLW

1hls example run unLll elLher Lhe user cllcks Lhe sLop buLLon or number of lLeraLlons ls
greaLer Lhan 10.

3.2 SLrucLures
3.2.1 Case SLrucLure
1he Case SLrucLure has one or more sub dlagrams, or cases, exacLly one of whlch execuLes
when Lhe sLrucLure execuLes. 1he value wlred Lo Lhe selecLor Lermlnal deLermlnes whlch
case Lo execuLe and can be 8oolean, sLrlng, lnLeger, or enumeraLed Lype. ?ou may rlghL-cllck
Lhe sLrucLure border Lo add or deleLe cases. use Lhe Labellng Lool Lo enLer value(s) ln Lhe
case selecLor label and conflgure Lhe value(s) handled by each case.
8elow we see an empLy Case sLrucLure:

39 Loops and SLrucLures
1uLorlal: An lnLroducLlon Lo LabvlLW

8elow we see an example of a Case sLrucLure wlLh 2 cases, a 1rue" case and a lalse" case.
uependlng of Lhe 8oolean lnpuL value, Lhe numerlc1 and numerlc2 ls elLher Added or
SubLracLed.

3.2.2 Sequence SLrucLure
A Sequence sLrucLure ConslsLs of one or more sub dlagrams, or frames, LhaL execuLe
sequenLlally. 8lghL-cllck Lhe sLrucLure border Lo add and deleLe frames or Lo creaLe sequence
locals Lo pass daLa beLween frames. use Lhe SLacked Sequence sLrucLure Lo ensure a sub
dlagram execuLes before or afLer anoLher sub dlagram.
8elow we see an empLy Sequence sLrucLure.
40 Loops and SLrucLures
1uLorlal: An lnLroducLlon Lo LabvlLW


8elow we see an example where we use Sequence Local", l.e., we pass a value from one
sequence Lo Lhe nexL
Note! 1o Lake advanLage of Lhe lnherenL parallellsm ln LabvlLW, avold overuslng Sequence
sLrucLures. Sequence sLrucLures guaranLee Lhe order of execuLlon, buL prohlblL parallel
operaLlons. AnoLher negaLlve Lo uslng Sequence sLrucLures ls LhaL you cannoL sLop Lhe
execuLlon parL way Lhrough Lhe sequence.
3.2.3 LvenL SLrucLure
An LvenL sLrucLure has one or more sub dlagrams, or evenL cases, exacLly one of whlch
execuLes when Lhe sLrucLure execuLes. 1he LvenL sLrucLure walLs unLll an evenL happens,
Lhen execuLes Lhe approprlaLe case Lo handle LhaL evenL. 8lghL-cllck Lhe sLrucLure border Lo
add new evenL cases and conflgure whlch evenLs Lo handle. Wlre a value Lo Lhe 1lmeouL
Lermlnal aL Lhe Lop lefL of Lhe LvenL sLrucLure Lo speclfy Lhe number of mllllseconds Lhe
41 Loops and SLrucLures
1uLorlal: An lnLroducLlon Lo LabvlLW

LvenL sLrucLure should walL for an evenL Lo occur. 1he defaulL ls -1, lndlcaLlng never Lo Llme
ouL.
8elow we see an example:


8lghL-cllck on Lhe border ln order Lo Add/LdlL LvenL Cases, see Lhe dlalog box below.
42 Loops and SLrucLures
1uLorlal: An lnLroducLlon Lo LabvlLW


Lxerclses
Lxerc|se: Ior Loop
CreaLe a vl wlLh a lor Loop. CreaLe Lhe loglc Lo flnd ouL lf a number ln an array ls greaLer
Lhan 10. See lronL anel below:
43 Loops and SLrucLures
1uLorlal: An lnLroducLlon Lo LabvlLW


Lxerc|se: Wh||e Loop
CreaLe a vl wlLh a Whlle Loop. CreaLe Lhe loglc Lo flnd ouL whlch (Lhe flrsL) lndex ln Lhe array
LhaL have a number greaLer Lhan 30. See lronL anel below:

Lxerc|se: Case Structure
CreaLe a vl wlLh a Case SLrucLure.
use a Case sLrucLure lnslde a lor Loop Lo wrlLe Lhe LexL 1he number ls greaLer Lhan 10" lf
value ls greaLer Lhan 10. See lronL anel below:

44 Loops and SLrucLures
1uLorlal: An lnLroducLlon Lo LabvlLW



Lxerc|se: Sequence Structure
CreaLe a vl wlLh a Sequence SLrucLure. See lronL anel below:


Lxerc|se: Lvent Structure
CreaLe a vl wlLh an LvenL SLrucLure. See lronL anel below:

43

6 1roubleshooLlng and
uebugglng
1hls chapLer explalns Lhe baslc concepLs of LroubleshooLlng and debugglng ln LabvlLW.
1oplcs:
Pow Lo flnd errors
PlghllghL LxecuLlon
robes
8reakpolnLs
SLep lnLo/over/ouL debugglng
6.1 Pow Lo flnd errors
lf a vl does noL run, lL ls a broken, or nonexecuLable", vl. 1he 8un buLLon ofLen
appears broken, shown aL lefL, when you creaLe or edlL a vl. lf lL ls sLlll broken when you
flnlsh wlrlng Lhe block dlagram, Lhe vl ls broken and wlll noL run. Cenerally, Lhls means LhaL a
requlred lnpuL ls noL wlred, or a wlre ls broken.
Cllck Lhe broken 8un buLLon Lo dlsplay Lhe Lrror llsL wlndow, whlch llsLs all Lhe errors.
uouble-cllck an error descrlpLlon Lo dlsplay Lhe relevanL block dlagram or fronL panel and
hlghllghL Lhe ob[ecL LhaL conLalns Lhe error.
6.2 PlghllghL LxecuLlon
vlew an anlmaLlon of Lhe execuLlon of Lhe block dlagram by cllcklng Lhe PlghllghL
LxecuLlon buLLon. LxecuLlon hlghllghLlng shows Lhe flow of daLa on Lhe block dlagram from
one node Lo anoLher uslng bubbles LhaL move along Lhe wlres. noLe! LxecuLlon hlghllghLlng
greaLly reduces Lhe speed aL whlch Lhe vl runs.
46 1roubleshooLlng and uebugglng
1uLorlal: An lnLroducLlon Lo LabvlLW


6.3 robes
use Lhe robe Lool Lo check lnLermedlaLe values on a wlre as a vl runs.
When execuLlon pauses aL a node because of slngle-sLepplng or a breakpolnL, you also can
probe Lhe wlre LhaL [usL execuLed Lo see Lhe value LhaL flowed Lhrough LhaL wlre. ?ou also
can creaLe a cusLom probe Lo speclfy whlch lndlcaLor you use Lo vlew Lhe probed daLa. lor
example, lf you are vlewlng numerlc daLa, you can choose Lo see LhaL daLa ln a charL wlLhln
Lhe probe. 1o creaLe a cusLom probe, rlghL-cllck a wlre and selecL CusLom robe-new from
Lhe shorLcuL menu.
47 1roubleshooLlng and uebugglng
1uLorlal: An lnLroducLlon Lo LabvlLW


6.4 8reakpolnLs

use Lhe 8reakpolnL Lool Lo place a breakpolnL on a vl, node, or wlre on Lhe block
dlagram and pause execuLlon aL LhaL locaLlon. When you seL a breakpolnL on a wlre,
execuLlon pauses afLer daLa pass Lhrough Lhe wlre. lace a breakpolnL on Lhe block dlagram
workspace Lo pause execuLlon afLer all nodes on Lhe block dlagram execuLe. When a vl
pauses aL a breakpolnL, LabvlLW brlngs Lhe block dlagram Lo Lhe fronL and uses a marquee
Lo hlghllghL Lhe node or wlre LhaL conLalns Lhe breakpolnL. LabvlLW hlghllghLs breakpolnLs
wlLh red borders for nodes and block dlagrams and red bulleLs for wlres. When you move
Lhe cursor over an exlsLlng breakpolnL, Lhe black area of Lhe 8reakpolnL Lool cursor appears
whlLe. use Lhe 8reakpolnL Lool Lo cllck an exlsLlng breakpolnL Lo remove lL.
?ou may also rlghL-cllck on Lhe wlre ln order Lo seL a breakpolnL or open Lhe 8reakpolnL
Manager.
48 1roubleshooLlng and uebugglng
1uLorlal: An lnLroducLlon Lo LabvlLW


8reakpolnL Manager ls a Lool for enable, dlsable and deleLe breakpolnLs.

6.3 SLep lnLo/over/ouL debugglng
Avallable keyboard ShorLcuLs when uebugglng:

49 1roubleshooLlng and uebugglng
1uLorlal: An lnLroducLlon Lo LabvlLW

Lxerclses
Lxerc|se: n|gh||ght Lxecut|on
Lnable PlghllghL LxecuLlon" ln one of your programs, and see how lL works.

Lxerc|se: robes
SeL Several robes around ln your appllcaLlon and waLch how lL works. use Lhe robe waLch
Wlndow and check ouL Lhe funcLlonallLy Lhls Lool offers.
Also check ouL Lhe CusLom robe" and Lhe llnd robe" funcLlonallLy.


Lxerc|se: 8reakpo|nts
SeL some 8reakpolnL around ln your code and check ouL how lL works. use Lhe 8reakpolnL
Manager Lool.
Lxample:


30 1roubleshooLlng and uebugglng
1uLorlal: An lnLroducLlon Lo LabvlLW

Lxerc|se: Step |nto]over]out debugg|ng
use Lhe SLep lnLo/over/ouL funcLlonallLy LogeLher wlLh your 8reakpolnLs and learn how you
can use Lhem and see whaL Lhe dlfference beLween Lhem ls.

31

7 Worklng wlLh uaLa
1hls chapLer explalns Lhe baslc concepLs of creaLlng and uslng Sub vls ln LabvlLW.
1oplcs:
Arrays
Array luncLlons
ClusLer
7.1 Arrays
Arrays are very powerful Lo use ln LabvlLW. ln all your appllcaLlons you would probably use
boLh Cne-ulmenslonal Arrays and 1wo-ulmenslonal Arrays.
7.1.1 AuLo-lndexlng
LabvlLW uses a powerful mechanlsm called AuLo-lndexlng".
lor Lxample you may use a lor loop Lo creaLe Array daLa llke Lhls:

Cr you may use an Array llke Lhls ln order Lo auLomaLlcally speclfy number of lLeraLlons:
32 Worklng wlLh uaLa
1uLorlal: An lnLroducLlon Lo LabvlLW


7.1.2 Array luncLlons
LabvlLW has loLs of bullL-ln funcLlons for manlpulaLlng arrays.

1he mosL useful Array funcLlons are:
Array Slze
lndex Array
33 Worklng wlLh uaLa
1uLorlal: An lnLroducLlon Lo LabvlLW

ueleLe from Array
Search 1u Array
lnlLlallze Array
8ulld Array
Array SubseL
Array ConsLanL
All Lhese funcLlons are baslc (buL very useful) array funcLlons you wlll probably be uslng ln all
your appllcaLlons and vls.


Lxamp|e: Array funct|ons
ln Lhls example we see how we can use Lhese Array funcLlons and whaL Lhey do.

34 Worklng wlLh uaLa
1uLorlal: An lnLroducLlon Lo LabvlLW

1he resulLlng lronL anel ls as follows:

7.2 ClusLer
ClusLers group daLa elemenLs of mlxed Lypes, such as a bundle of wlres, as ln a Lelephone
cable, where each wlre ln Lhe cable represenLs a dlfferenL elemenL of Lhe clusLer. A clusLer ls
slmllar Lo a record or a sLrucL ln LexL-based programmlng languages. 8undllng several daLa
elemenLs lnLo clusLers ellmlnaLes wlre cluLLer on Lhe block dlagram and reduces Lhe number
of connecLor pane Lermlnals LhaL subvls need. 1he connecLor pane has, aL mosL, 28
Lermlnals. lf a fronL panel conLalns more Lhan 28 conLrols and lndlcaLors LhaL you wanL Lo
use programmaLlcally, group some of Lhem lnLo a clusLer and asslgn Lhe clusLer Lo a Lermlnal
on Lhe connecLor pane. Llke an array, a clusLer ls elLher a conLrol or an lndlcaLor. A clusLer
cannoL conLaln a mlxLure of conLrols and lndlcaLors.
33 Worklng wlLh uaLa
1uLorlal: An lnLroducLlon Lo LabvlLW


AlLhough clusLer and array elemenLs are boLh ordered, you musL unbundle all clusLer
elemenLs aL once raLher Lhan lndex one elemenL aL a Llme. ?ou also can use Lhe unbundle
8y name" funcLlon Lo access speclflc clusLer elemenLs.
Lxample of a ClusLer ln LabvlLW:

7.2.1 ClusLer Crder
?ou may sorL Lhe dlfferenL elemenLs ln Lhe clusLer by rlghL-cllck on Lhe clusLer border and
selecL 8eorder ConLrols ln ClusLer."
36 Worklng wlLh uaLa
1uLorlal: An lnLroducLlon Lo LabvlLW


7.2.2 ClusLer LlemenLs
ln order Lo manlpulaLe and work wlLh clusLer LabvlLW offers loLs of funcLlons, such as Lhe
8undle" and unbundle" funcLlons.

ln order Lo wrlLe Lo a clusLer from Lhe code, you may use Lhe 8undle" funcLlon or Lhe
8undle 8y name" funcLlon. See example below:
37 Worklng wlLh uaLa
1uLorlal: An lnLroducLlon Lo LabvlLW

Lxamp|e: C|usters

ln order Lo geL access Lo Lhe dlfferenL elemenLs ln Lhe clusLer, you need Lo unbundle" by
uslng Lhe unbundle" funcLlon or Lhe unbundle 8y name". See example below:

Lxerclses
Lxerc|se: Arrays
CreaLe some slmple vls where you use Lhese array funcLlons Lo manlpulaLe array daLa:
Array Slze
lndex Array
ueleLe from Array
Search 1u Array
lnlLlallze Array
8ulld Array
Array SubseL
38 Worklng wlLh uaLa
1uLorlal: An lnLroducLlon Lo LabvlLW

Lxerc|se: Arrays
CreaLe a Subvl LhaL flnd Lhe peaks" ln Lhe lnpuL array regardlng Lo an lnpuL peak level.

Lxerc|se: C|usters
CreaLe a ClusLer and geL Lhe dlfferenL values from Lhe conLrols ln Lhe ClusLer. See lronL anel
below:



39

8 Worklng wlLh SLrlngs
Worklng and manlpulaLlng wlLh sLrlngs ls an lmporLanL parL ln LabvlLW developmenL.
Cn Lhe lronL panel we have Lhe followlng SLrlng conLrols and lndlcaLors avallable from Lhe
ConLrol paleLLe:

Cn Lhe 8lock ulagram we have Lhe followlng SLrlng funcLlons avallable from Lhe luncLlons
paleLLe:

Some of Lhe mosL lmporLanL SLrlng funcLlons are:
Concatenate Str|ngs
60 Worklng wlLh SLrlngs
1uLorlal: An lnLroducLlon Lo LabvlLW


1hls funcLlon concaLenaLes several sLrlngs lnLo on sLrlng:

Search and kep|ace Str|ng

use Lhls when you wanL Lo replace or remove a cerLaln LexL ln a sLrlng.


Match attern
61 Worklng wlLh SLrlngs
1uLorlal: An lnLroducLlon Lo LabvlLW


1hls ls Lhe mosL useful funcLlon when lL comes Lo sLrlng manlpulaLlon.


Iormat Into Str|ng

Lxample:

Lxerclses
Pere are some exerclses uslng some of Lhe SLrlng funcLlons LhaL are avallable ln LabvlLW.
Lxerc|se: SubVI: kemove |ead|ng zeros |n str|ng.v|
62 Worklng wlLh SLrlngs
1uLorlal: An lnLroducLlon Lo LabvlLW

CreaLe a Subvl whlch removes leadlng zeros ln a sLrlng. CreaLe a 1esL vl LhaL uses Lhe Subvl.

Lxerc|se: SubVI: kemove space from end of str|ng.v|
CreaLe a Subvl whlch removes all spaces from Lhe end of Lhe sLrlng. CreaLe a 1esL vl LhaL
uses Lhe Subvl.

Lxerc|se: SubVI: Add 2 Str|ng.v|
CreaLe a Subvl whlch adds 2 sLrlngs lnLo one. CreaLe a 1esL vl LhaL uses Lhe Subvl.



63

9 Lrror Pandllng
1hls chapLer explalns Lhe baslc concepLs of handle errors ln your code.
1oplcs:
llndlng Lrrors
Lrror Wlrlng
Lrror Pandllng
9.1 llndlng Lrror
lf a vl does noL run, lL ls a broken, or nonexecuLable", vl. 1he 8un buLLon ofLen appears
broken, shown aL lefL, when you creaLe or edlL a vl. lf lL ls sLlll broken when you flnlsh wlrlng
Lhe block dlagram, Lhe vl ls broken and wlll noL run. Cenerally, Lhls means LhaL a requlred
lnpuL ls noL wlred, or a wlre ls broken. Cllck Lhe broken 8un buLLon Lo dlsplay Lhe Lrror llsL
wlndow, whlch llsLs all Lhe errors. uouble-cllck an error descrlpLlon Lo dlsplay Lhe relevanL
block dlagram or fronL panel and hlghllghL Lhe ob[ecL LhaL conLalns Lhe error.
9.2 Lrror Wlrlng
Lrror handllng ls lmporLanL ln all programmlng languages. LabvlLW has powerful mechanlsm
for handllng errors and error wlrlng.
?ou should always wlre Lhe Lrror clusLer beLween all Subvls, nodes, eLc. LhaL supporL Lhls,
see example below.

1he Lrror clusLer ls locaLed ln Lhe ConLrols paleLLe here:
64 Lrror Pandllng
1uLorlal: An lnLroducLlon Lo LabvlLW



1he Lrror ClusLer:

1he Lrror clusLer conLalns of Lhe followlng parLs:
SLaLus - 1rue/lalse. lalse: no Lrror, 1rue: Lrror
Code - Lrror Code
Source - 1exLual Lrror message
9.3 Lrror Pandllng ln Subvls
When creaLlng Subvls you should always creaLe an Lrror ln and an Lrror CuL. ln Lhe Subvl
code you should also use a Case sLrucLure and wlre Lhe Lrror ln clusLer Lo Lhe Case SelecLor
as shown below.
63 Lrror Pandllng
1uLorlal: An lnLroducLlon Lo LabvlLW


9.4 Lrror Pandllng
LabvlLW has several useful Subvls, eLc for Lrror Pandllng:
66 Lrror Pandllng
1uLorlal: An lnLroducLlon Lo LabvlLW


1hese are:

ln general you should always show Lhe error Lo Lhe user. See LabvlLW Pelp for more deLalls
of how Lo use Lhese Subvls.
Lxerclses
Lxerc|se: Lrror nand||ng
Check ouL Lhe dlfferenL Lrror vls ln LabvlLW. use Lhem ln some of your prevlous vls.

67

10 Worklng wlLh ro[ecLs
1hls chapLer explalns Lhe baslc concepLs of Lhe pro[ecL Lxplorer ln LabvlLW.
1oplcs:
ro[ecL Lxplorer
8ulldlng .exe (execuLable) appllcaLlons
ueploymenL: CreaLe an lnsLaller
10.1 ro[ecL Lxplorer
lL ls noL necessary Lo use Lhe ro[ecL Lxplorer when developlng your LabvlLW code, buL lL ls
an easy way Lo sLrucLure your code, especlally for larger pro[ecLs.

1he pro[ecL Lxplorer ls necessary when you wanL Lo deploy your code lnLo, e.g., an
execuLable (.exe) appllcaLlon, bulld a seLup, eLc.
68 Worklng wlLh ro[ecLs
1uLorlal: An lnLroducLlon Lo LabvlLW

1he ro[ecL Lxplorer ls also very useful when you lnLegraLe a source conLrol Lool, such as
1eam loundaLlon Server, vlsual Source Safe, eLc. 1hen you may easlly check flles ln and ouL
of Lhe source code sysLem.
ln order Lo creaLe a new ro[ecL ln LabvlLW, slmply selecL LmpLy ro[ecL" from Lhe CeLLlng
SLarLed wlndow when you open LabvlLW.


10.2 ueploymenL
When your appllcaLlon ls flnlshed, you may wanL Lo dlsLrlbuLe or deploy your appllcaLlon and
share lL wlLh oLhers.
1he ro[ecL Lxplorer glves you several cholces when lL comes Lo dlsLrlbuLe and deploy your
appllcaLlon. Some of Lhe opLlons are:
CreaLe an executab|e appllcaLlon (.exe) - Lhls means LhaL Lhe LargeL doesn'L need Lo
have LabvlLW lnsLalled on Lhelr compuLer. All Lhe LargeL need ls LabvlLW 8un-8lme,
whlch ls a small lnsLallaLlon package.
69 Worklng wlLh ro[ecLs
1uLorlal: An lnLroducLlon Lo LabvlLW

?ou may creaLe your own |nsta||er, so all Lhe LargeL need ls Lo run a seLup.exe ln
order Lo use your appllcaLlon
CLher posslblllLles ls Lo creaLe a Web Serv|ce or a Shared Llbrary (DLL) of your
appllcaLlon
All Lhese opLlons are avallable from Lhe ro[ecL Lxplorer, [usL rlghL-cllck on your 8ulld
SpeclflcaLlons" node.


We wlll go Lhrough how we creaLe an execuLable appllcaLlon. Cllck 8ulld
SpeclflcaLlons-new-AppllcaLlon (LxL).
ln Lhe roperLles wlndow flll ln your name of Lhe appllcaLlon.
70 Worklng wlLh ro[ecLs
1uLorlal: An lnLroducLlon Lo LabvlLW


Make sure you selecL a SLarLup vl.

1here are loLs of properLles and seLLlng you may use ln order Lo creaLe your appllcaLlon, go
Lhrough all Lhe CaLegorles ln Lhe roperLles wlndow.
When you have flnlshed all Lhe sLeps, [usL selecL 8ulld" ln order Lo creaLe your appllcaLlon.
When you make changes ln your appllcaLlon, lL ls easy Lo rebulld your appllcaLlon:
71 Worklng wlLh ro[ecLs
1uLorlal: An lnLroducLlon Lo LabvlLW


Lxerclses
Lxerc|se: ro[ect Lxp|orer
CreaLe a new ro[ecL and puL on of your exlsLlng appllcaLlon lnLo Lhe pro[ecL
Lxerc|se: Dep|oyment
CreaLe an execuLable appllcaLlon

72

11 ueslgn 1echnlques
1hls chapLer explalns some useful Lechnlques Lo use when creaLlng your appllcaLlon.
1oplcs:
lorce Lhe rogram llow uslng an Lrror clusLer
ShlfL 8eglsLer
SLaLe Machlne
MulLlple Loops
1emplaLes
11.1 lorce rogram llow
As menLloned earller, LabvlLW follows a daLaflow model for runnlng vls. A block dlagram
node execuLes when all lLs lnpuLs are avallable. When a node compleLes execuLlon, lL
supplles daLa Lo lLs ouLpuL Lermlnals and passes Lhe ouLpuL daLa Lo Lhe nexL node ln Lhe
daLaflow paLh.
ln Lhe example below we cannoL be sure LhaL Lhe uACmx WrlLe.vl execuLes before Lhe
uACmx SLop 1ask.vl execuLes. LabvlLW wlll ln Lhls case randomly execuLe one of Lhese flrsL.
lf Lhe SLop vl happens Lo execuLe flrsL Lhen Lhe WrlLe vl wlll falled because Lask has been
sLopped.


ln Lhe example below we wlre Lhe Lrror clusLer Lhrough all Lhe vls, and Lhere wlll be no
doubL LhaL Lhe WrlLe vl wlll execuLe before Lhe SLop vl.
73 ueslgn 1echnlques
1uLorlal: An lnLroducLlon Lo LabvlLW


1hls approach wlll also Lake care of Lhe error handllng ln your program, whlch ls very
lmporLanL ln real-world appllcaLlons.
11.2 ShlfL 8eglsLer
use shlfL reglsLers on lor Loops and Whlle Loops Lo Lransfer values from one loop lLeraLlon
Lo Lhe nexL. ShlfL reglsLers are slmllar Lo sLaLlc varlables ln LexL-based programmlng
languages. A shlfL reglsLer appears as a palr of Lermlnals, dlrecLly opposlLe each oLher on Lhe
verLlcal sldes of Lhe loop border. 1he rlghL Lermlnal conLalns an up arrow and sLores daLa on
Lhe compleLlon of an lLeraLlon. LabvlLW Lransfers Lhe daLa connecLed Lo Lhe rlghL slde of Lhe
reglsLer Lo Lhe nexL lLeraLlon. CreaLe a shlfL reglsLer by rlghL-cllcklng Lhe lefL or rlghL border
of a loop and selecLlng Add ShlfL 8eglsLer from Lhe shorLcuL menu.
A shlfL reglsLer Lransfers any daLa Lype and auLomaLlcally changes Lo Lhe daLa Lype of Lhe
flrsL ob[ecL wlred Lo Lhe shlfL reglsLer. 1he daLa you wlre Lo Lhe Lermlnals of each shlfL
reglsLer musL be Lhe same Lype.
1o lnlLlallze a shlfL reglsLer, wlre any value from ouLslde Lhe loop Lo Lhe lefL Lermlnal. lf you
do noL lnlLlallze Lhe shlfL reglsLer, Lhe loop uses Lhe value wrlLLen Lo Lhe shlfL reglsLer when
Lhe loop lasL execuLed or Lhe defaulL value for Lhe daLa Lype lf Lhe loop has never execuLed.
use a loop wlLh an unlnlLlallzed shlfL reglsLer Lo run a vl repeaLedly so LhaL each Llme Lhe vl
runs, Lhe lnlLlal ouLpuL of Lhe shlfL reglsLer ls Lhe lasL value from Lhe prevlous execuLlon. use
an unlnlLlallzed shlfL reglsLer Lo preserve sLaLe lnformaLlon beLween subsequenL execuLlons
of a vl. AfLer Lhe loop execuLes, Lhe lasL value sLored ln Lhe shlfL reglsLer remalns aL Lhe rlghL
Lermlnal. lf you wlre Lhe rlghL Lermlnal ouLslde Lhe loop, Lhe wlre Lransfers Lhe lasL value
sLored ln Lhe shlfL reglsLer. ?ou can add more Lhan one shlfL reglsLer Lo a loop. lf you have
mulLlple operaLlons wlLhln a loop, use mulLlple shlfL reglsLers Lo sLore Lhe daLa values from
Lhose dlfferenL processes ln Lhe sLrucLure.
74 ueslgn 1echnlques
1uLorlal: An lnLroducLlon Lo LabvlLW



11.3 SLaLe rogrammlng ArchlLecLure
CreaLlng vls uslng Lhe SLaLe Machlne approach ls very useful when creaLlng (large)
appllcaLlons.
ln general, a sLaLe machlne ls a model of behavlor composed of a flnlLe number of sLaLes,
LranslLlons beLween Lhose sLaLes, and acLlons. lL ls slmllar Lo a "flow graph" where we can
lnspecL Lhe way ln whlch Lhe loglc runs when cerLaln condlLlons are meL.


SomeLlmes, you may wanL Lo change Lhe order of Lhe sequence, repeaL one lLem ln Lhe
sequence more ofLen Lhan Lhe oLher lLems, sLop a sequence lmmedlaLely, or have lLems ln
Lhe sequence LhaL may execuLe only when cerLaln condlLlons are meL. AlLhough your
program may noL have any such requlremenLs, Lhere ls always Lhe posslblllLy LhaL Lhe
program musL be modlfled ln Lhe fuLure. 1herefore, a sLaLe programmlng archlLecLure ls a
good cholce, even lf a sequenLlal programmlng sLrucLure ls sufflclenL. 1he followlng llsL
73 ueslgn 1echnlques
1uLorlal: An lnLroducLlon Lo LabvlLW

descrlbes more complex programmlng requlremenLs LhaL [usLlfy Lhe use of a sLaLe
programmlng archlLecLure for an appllcaLlon.
?ou need Lo change Lhe order of Lhe sequence
?ou musL repeaL an lLem ln Lhe sequence more ofLen Lhan oLher lLems
?ou wanL some lLems ln Lhe sequence Lo execuLe only when cerLaln condlLlons are
meL

1he SLaLe Machlne approach ln LabvlLW uses a Case sLrucLure lnslde a Whlle loop Lo handle
Lhe dlfferenL sLaLes ln Lhe program, and Lhe LranslLlons beLween Lhem. 1he ShlfL 8eglsLer ls
used Lo save daLa from and beLween Lhe dlfferenL sLaLes.
8elow we see examples of a sLaLe machlne prlnclple lmplemenLed ln LabvlLW.
Slmple SLaLe Machlne prlnclple
76 ueslgn 1echnlques
1uLorlal: An lnLroducLlon Lo LabvlLW


SLaLe Machlne wlLh mulLlple LranslLlons dependlng on Lhe SLaLe:


More advanced SLaLe Machlne uslng ShlfL 8eglsLers:
77 ueslgn 1echnlques
1uLorlal: An lnLroducLlon Lo LabvlLW


11.4 MulLlple Loops/arallel
programmlng
CfLen, you need Lo program mulLlple Lasks so LhaL Lhey execuLe aL Lhe same Llme. ln
LabvlLW Lasks can run ln parallel lf Lhey do noL have a daLa dependency beLween Lhem, and
lf Lhey are noL uslng Lhe same shared resource. An example of a shared resource ls a flle, or
an lnsLrumenL.

uslng mulLlple Whlle loops ls someLlmes useful ln appllcaLlons LhaL need Lo handle user
lnLeracLlons ln parallel wlLh, e.g., uAC operaLlons, eLc.
8elow we see an example of how Lhls sLrucLure could look llke. 1he upper loop could handle
lnLeracLlon wlLh Lhe user, whlle Lhe lower loop could handle uAC operaLlons, such as
readlng and wrlLlng Lo some l/C equlpmenLs.
78 ueslgn 1echnlques
1uLorlal: An lnLroducLlon Lo LabvlLW


ln order Lo pass daLa beLween Lhe loops, you may e.g. use local varlables. 1he loop may have
dlfferenL Llme cycles. 1he l/C may requlre fasLer cycles Lhan Lhe user lnLeracLlon loop.
11.3 1emplaLes
?ou should creaLe your own LemplaLes for such vl you use a loL. lL ls easy Lo creaLe your own
LemplaLes for scraLch, [usL creaLe a vl as you normally do and Lhen save lL as a LemplaLe wlLh
Lhe endlng .v|t". ?ou may also converL a vl you already made [usL by changlng Lhe exLenslon
Lo .vlL".
?ou should copy your LemplaLes Lo Lhe LabvlLW LemplaLe folder whlch ls defaulL locaLed ln
C:\rogram llles\naLlonal lnsLrumenLs\LabvlLW x.x\1emplaLes\".
79 ueslgn 1echnlques
1uLorlal: An lnLroducLlon Lo LabvlLW



1he 1emplaLes wlll Lhen be avallable from Lhe CeLLlng SLarLed Wlndow or llle-new. ln
LabvlLW.
l may case l have creaLed a sub folder called My 1emplaLes" where l place all my LemplaLes.
80 ueslgn 1echnlques
1uLorlal: An lnLroducLlon Lo LabvlLW


Lxerclses
Pere are some exerclses abouL shlfL-reglsLers, SLaLe Machlnes and parallel programmlng.
Lxerc|se: Sh|ft-reg|ster
CreaLe a vl (see example below) where you have Lhe followlng sLaLes:
lnlLlallze
WrlLe
8ead
Close
ln Lhe vl you wlll use a shlfL-reglsLer as a Lemporary sLorage. ln Lhe WrlLe sLaLe you WrlLe
uaLa Lo Lhe sLorage (shlfL-reglsLer) whlle you ln Lhe 8ead sLaLe wlll read Lhe uaLa from Lhe
SLorage.
See Lxample below:
81 ueslgn 1echnlques
1uLorlal: An lnLroducLlon Lo LabvlLW


WrlLe a 1esL program LhaL LesL Lhe Subvl, e.g.,

1hls example shows how you can use a shlfL-reglsLer as a Lemporary sLorage, whlch ls very
useful ln many slLuaLlons.
Lxerc|se: State Mach|ne
use Lhe SLaLe Machlne prlnclple on one of your prevlous exerclses.

Lxerc|se: ara||e| rogramm|ng
CreaLe a vl LhaL conslsLs of 2 parallel loops. use local varlables and oLher mechanlsms ln
order Lo share daLa beLween Lhe 2 loops.

Lxerc|se: 1emp|ates
82 ueslgn 1echnlques
1uLorlal: An lnLroducLlon Lo LabvlLW

SLrlp some of yours prevlous vls and save Lhem as reusable 1emplaLes.

83

12 user lnLerface
1hls chapLer explalns Lhe baslc concepLs of creaLlng user-frlendly Craphlcal user lnLerfaces
(Cul) ln LabvlLW.
1oplcs:
uecoraLlons
1ab ConLrol
SpllLLer
Sub anel
LLc.
8elow we see a lronL anel (Cul) wlLh a poor" deslgn.

1he lnformaLlon (ConLrols and lndlcaLors) on Lhe lronL anel ls noL sLrucLured. ?ou should
group elemenLs LhaL naLurally belong LogeLher and use dlfferenL colors wlLh care.
When creaLlng Craphlcal user lnLerfaces (Cul) you should use Lhe conLrols from Lhe SysLem
paleLLe and noL from Lhe Modern or Classlc paleLLes. Modern ConLrols may be used ln Sub
vls wlLh no vlslble user lnLerface (for Lhe user).
84 user lnLerface
1uLorlal: An lnLroducLlon Lo LabvlLW

1he appearance of Lhe conLrols ln Lhe SysLem paleLLe ls sLandard MS Wlndows look and
feellng and Lhls look ls famlllar for mosL users. 1hese conLrols also change appearance due Lo
changes ln Lhe appearance ln Lhe operaLlon sysLem.

12.1 vl roperLles
ln order Lo make Lhe appearance of Lhe Wlndow LhaL hosLs your appllcaLlon, you should
always make some changes ln Lhe vl roperLles".
?ou flnd Lhe vl roperLles" by rlghL-cllck on Lhe lcon ln Lhe upper rlghL corner of your vl.

83 user lnLerface
1uLorlal: An lnLroducLlon Lo LabvlLW


1he flrsL Lhlng you should change ls Lhe Wlndow LlLle". Pere you may Lype approprlaLe
name of your appllcaLlon or Subvl.
1he nexL you should do ls Lo Lhe CusLomlze" buLLon ln order Lo cusLomlze Lhe Wlndow
appearance.


8elow we see an appllcaLlon wlLh a slmple and neaL user lnLerface and wlLh a CusLomlzed
Wlndows appearance.
86 user lnLerface
1uLorlal: An lnLroducLlon Lo LabvlLW



8elow we see a professlonal appllcaLlon creaLed ln LabvlLW LhaL lmplemenL common Cul
ob[ecLs such as a 1oolbar, a 1ree vlew, a LlsL vlew, eLc..


87 user lnLerface
1uLorlal: An lnLroducLlon Lo LabvlLW

Lxerclses
Lxerc|se: User Interface
CreaLe a ulalog 8ox where you use some of Lhe ConLrols from Lhe SysLem paleLLe. Make Lhe
necessary seLLlngs ln vl roperLles ln order Lo hlde menus, buLLons, creaLe a 1lLle, eLc.
CreaLe a 1esL vl from where you open Lhls ulalog 8ox, enLer some daLa ln Lhe ulalog 8ox,
and Lhen reLrleve Lhese daLa ln Lhe calllng vl.
Lxample:

88

13 loLLlng uaLa
1hls chapLer explalns Lhe baslc concepLs when ploLLlng daLa ln LabvlLW.
LabvlLW offers powerful funcLlonallLy for ploLLlng daLa. ln Lhe Craph paleLLe we have loLs of
useful conLrols for ploLLlng and vlsuallzaLlon of daLa.

1he mosL useful are:
Waveform CharL
Waveform Craph
x? Craph

Lxamp|e:
1hls slmple example creaLes a graph wlLh some random values.
89 loLLlng uaLa
1uLorlal: An lnLroducLlon Lo LabvlLW




1he example below show Lhe baslc dlfference beLween a CharL" and a Craph".
90 loLLlng uaLa
1uLorlal: An lnLroducLlon Lo LabvlLW


?ou use Lhe Craph" lf you wanL Lo ploL a seL of daLa, e.g., an array wlLh daLa, ploL daLa from
a flle, eLc. use Lhe CharL" lf you wanL Lo ploL one daLa polnL aL a Llme, e.g., lnslde a loop,
eLc.
13.1 CusLomlzlng
1he dlfferenL CharL componenLs ln LabvlLW offer a greaL deal of cusLomlzlng.
?ou may cllck on Lhe |ot Legend" ln order Lo seL colors, dlfferenL llne
sLyles, eLc.



91 loLLlng uaLa
1uLorlal: An lnLroducLlon Lo LabvlLW

lf you rlghL-cllck on Lhe Craph/CharL, you may seL properLles such as auLo-scallng, eLc.


lf you selecL roperLles, you geL Lhe followlng dlalog:

92 loLLlng uaLa
1uLorlal: An lnLroducLlon Lo LabvlLW


?ou may also selecL whlch lLems LhaL should be vlslble or noL.


1he Graph a|ette" leLs you zoom ln and ouL on Lhe Craph, eLc.
Lxerclses
Lxerc|se: Graph
CreaLe a vl LhaL reads daLa from a flle and ploL Lhe daLa ln a Craph componenL.

Lxerc|se: Chart
CreaLe a vl where you use uaLa 8lndlng ln order Lo reLrleve daLa from an CC demo.
uaLa 8lndlng ls seL ln Lhe roperLles - uaLa 8lndlng Lab:
93 loLLlng uaLa
1uLorlal: An lnLroducLlon Lo LabvlLW



Lxerc|se: Custom|z|ng
CusLomlze Lhe Craph and Lhe CharL ln Lhe examples above ln order Lo seL colors, llne
Lhlckness, eLc.

94

14 1lps & 1rlcks
1hls chapLer glves you some useful 1lps & 1rlcks regardlng LabvlLW.
14.1 10 funcLlons you need Lo know
abouL
1hese are Lhe 10 mosL useful funcLlons ln LabvlLW, so you could already now learn how Lo
use Lhem and where Lo flnd Lhem!

8u||d Array

1hls example uslng Lhe 8ulld Array funcLlon lnslde a lor loop ln order bulld an array wlLh 10
elemenLs.

Index Array
93 1lps & 1rlcks
1uLorlal: An lnLroducLlon Lo LabvlLW


lL ls always useful Lo flnd a speclflc value ln an array:

1he lndex Array ls exLendlble, so you can drag lL ouL Lo flnd more Lhan one elemenLs:


Array S|ze

llnd Lhe slze of an arblLrary array:


96 1lps & 1rlcks
1uLorlal: An lnLroducLlon Lo LabvlLW

Se|ect

uependlng on Lhe lnpuL daLa, go Lo Lhe Alarm case or Lhe WrlLe uaLa case.

Concatenate Str|ngs

1hls funcLlon concaLenaLe several sLrlngs lnLo on sLrlng:

Search and kep|ace Str|ng
97 1lps & 1rlcks
1uLorlal: An lnLroducLlon Lo LabvlLW


use Lhls when you wanL Lo replace or remove a cerLaln LexL ln a sLrlng.


Match attern

1hls ls Lhe mosL useful funcLlon when lL comes Lo sLrlng manlpulaLlon.


Iormat Into Str|ng
98 1lps & 1rlcks
1uLorlal: An lnLroducLlon Lo LabvlLW


Lxample:

Iract]Lxp Str|ng to Number

1hls funcLlon converLs a sLrlng lnLo a number:

Lxamp|e: Number 1o Iract|ona| Str|ng

99 1lps & 1rlcks
1uLorlal: An lnLroducLlon Lo LabvlLW

Lxample:

14.2 1he 10 mosL useful ShorL-cuLs
1hese are Lhe 10 mosL useful shorL-cuLs ln LabvlLW, so you could already now learn how Lo
use Lhem!
Short-Cut Descr|pt|on
Ctr| + 8 ueleLes all broken wlres ln a vl
Ctr| + . SLops Lhe 8unnlng vl
Ctr| + L 1oggle beLween Lhe lronL anel and 8lock ulagram
1ab Cycles Lhrough Lhe mosL common 1ools (AuLomaLlc 1ool SelecLlon
should be dlsabled!)
Ctr| + Mouse
whee|
Scrolls Lhrough subdlagrams ln Case, LvenL or Sequence sLrucLures
Ctr| + n ulsplays Lhe ConLexL Pelp wlndow
Ctr| + Mouse
Doub|e-c||ck on a
SubVI
Cpens Lhe 8lock ulagram dlrecLly
Ctr| + Arrows
( )
Move fasLer. ?ou flrsL have Lo selecL a Subvl, a luncLlon, Cb[ecL, eLc
Ctr| + W Close Lhe Subvl
Doub|e-c||ck on a
w|re
SelecLs Lhe hole wlre

100

13 Lxample AppllcaLlon
ln Lhls example we wlll go Lhrough an example appllcaLlon. 1he appllcaLlon uses mosL of Lhe
LabvlLW feaLures you have learned ln Lhls 1uLorlal.
1he appllcaLlon ls called Clossary". lL ls a slmple appllcaLlon LhaL learns kld's words ln
Lngllsh. Slnce Lhe appllcaLlon ls for klds, Lhe user lnLerface ls creaLe wlLh a chlldlsh" look
and feel.

1hls ls an example of how Lo creaLe a user-frlendly appllcaLlon ln LabvlLW LhaL uses mosL of
Lhe funcLlonallLy ln LabvlLW, such as SLaLe-machlne prlnclples, readlng and wrlLlng Lo flles,
dlalog boxes, graphlcs and sound effecLs. 8aslc funcLlons for sLrlng and array manlpulaLlon,
and of course whlle loops, case sLrucLures, subvls, eLc. 1he example also uses Lhe ro[ecL
Lxplorer Lo collecL all Lhe flles ln one place and Lo creaLe an execuLable flle of Lhe soluLlon.
llnally lL uses Lhe ro[ecL Lxplorer Lo creaLe a seLup package you can use Lo lnsLall Lhe
appllcaLlon easlly on oLher compuLers.
101 Lxample AppllcaLlon
1uLorlal: An lnLroducLlon Lo LabvlLW

l creaLed Lhls appllcaLlon for my klds ln Lhe rlmary school who had problems wlLh learnlng
Lhelr homework ln Lngllsh.
use Lhe code as an example for creaLlng your own sLunnlng LabvlLW appllcaLlons. 1he code
ls avallable for download aL my blog: hLLp://home.hlL.no/~hansha.
8elow we see Lhe Clossary LlsL:
lf you cllck on Lhe llLLle book symbol ln your appllcaLlon, Lhls wlndow wlll pop up:

Cllck Lls symbol and you can enLer new words:
102 Lxample AppllcaLlon
1uLorlal: An lnLroducLlon Lo LabvlLW



1he appllcaLlon uses Lhe ro[ecL Lxplorer:
103 Lxample AppllcaLlon
1uLorlal: An lnLroducLlon Lo LabvlLW


1hls makes lL easy Lo keep an overvlew of all your flles ln your pro[ecL. ?ou may also use Lhe
ro[ecL Lxplorer Lo creaLe an execuLable flle of your appllcaLlon. ln addlLlon you may also
creaLe an lnsLallaLlon package so you can easlly lnsLall Lhe appllcaLlon on oLher compuLers.
As parL of Lhe lnsLallaLlon Lhe LabvlLW 8un-Llme englne wlll be lnsLalled.
8|ock D|agram:
1he appllcaLlon uses Lhe sLaLe machlne prlnclple, whlch makes lL easy Lo creaLe large
appllcaLlons:
104 Lxample AppllcaLlon
1uLorlal: An lnLroducLlon Lo LabvlLW



103

16 AddlLlonal Lxerclses
1hls chapLer llsLs loLs of addlLlonal exerclses you could Lry ouL ln order Lo lmprove your
LabvlLW skllls.
Lxerc|se: vCard keader
CreaLe an appllcaLlon LhaL reads lnformaLlon from a vCard.
vCard ls a flle formaL sLandard for elecLronlc buslness cards. vCards are ofLen aLLached Lo
e-mall messages, buL can be exchanged ln oLher ways, such as on Lhe World Wlde Web. 1hey
can conLaln name and address lnformaLlon, phone numbers, u8Ls, logos, phoLographs, and
even audlo cllps.
Lxample:
BEGIN:VCARD
VERSION:2.1
N:Gump;Forrest
FN:Forrest Gump
ORG:Bubba Gump Shrimp Co.
TITLE:Shrimp Man
TEL;WORK;VOICE:(111) 555-1212
TEL;HOME;VOICE:(404) 555-1212
ADR;WORK:;;100 Waters Edge;Baytown;LA;30314;United States of America
LABEL;WORK;ENCODING=QUOTED-PRINTABLE:100 Waters Edge=0D=0ABaytown, LA 30314=0D=0AUSA
ADR;HOME:;;42 Plantation St.;Baytown;LA;30314;United States of America
LABEL;HOME;ENCODING=QUOTED-PRINTABLE:42 Plantation St.=0D=0ABaytown, LA 30314=0D=0AUSA
EMAIL;PREF;INTERNET:forrestgump@example.com
REV:20080424T195243Z
END:VCARD
lor more lnformaLlon abouL Lhe vCard formaL, see hLLp://en.wlklpedla.org/wlkl/vCard.
1he appllcaLlon should look someLhlng llke Lhls:

When Lhe user cllck Cpen, Lhen a dlalog box llke Lhls should appear:
106 AddlLlonal Lxerclses
1uLorlal: An lnLroducLlon Lo LabvlLW


kequ|rements:
use Lhe ro[ecL Lxplorer
use Lhe SLaLe Machlne prlnclple
use Lhe LvenL SLrucLure
use SysLem ConLrols
SeL Lhe approprlaLe seLLlngs ln Lhe vl roperLles.
CreaLe a execuLable appllcaLlon (vCard.exe)

Lxerc|se: vCard Wr|te & kead
LxLend Lhe appllcaLlon ln Lhe prevlous example. ?ou should now be able Lo boLh wrlLe and
read vCard flles. 1he appllcaLlon could look someLhlng llke Lhls:
107 AddlLlonal Lxerclses
1uLorlal: An lnLroducLlon Lo LabvlLW


When Lhe user cllcks new, Lhe dlalog box ln Lhe prevlous exerclse appears. 1he user may
enLer a new vCard. lf Lhe user cllcks LdlL, a dlalog box wlLh Lhe selecLed conLacL should
appear.

Lxerc|se: kead]Wr|te from .|n| f||es
8ead/WrlLe from .lnl flles. use Lhe ConflguraLlon llle vls:


Lxerc|se: Act|vek
CreaLe a slmple Web 8rowser uslng AcLlvex and Lhe lnLerneL Lxplorer AcLlvex conLrol
(MlcrosofL Web 8rowser)
use Lhe AcLlvex ConLalner from Lhe ConLalners conLrol paleLLe:
108 AddlLlonal Lxerclses
1uLorlal: An lnLroducLlon Lo LabvlLW


use Lhe AcLlvex funcLlon paleLLe:

1he appllcaLlon could look someLhlng llke Lhls:


109 AddlLlonal Lxerclses
1uLorlal: An lnLroducLlon Lo LabvlLW

Lxerc|se: 1hemes
ln e.g., AS.nL1 we have someLhlng called 1hemes. 1hemes are used Lo change Lhe
appearance of your whole appllcaLlon regardlng Lo color, fonL, plcLures, eLc.
LabvlLW do noL offer such a funcLlonallLy , buL Lry Lo creaLe your own 1heme ConflguraLor,
so you can change Lhe appearance of your vl lnsLanLly.
Pere ls an example of how Wlndows x handles dlfferenL 1hemes:


CreaLe a slmllar 1heme ConflguraLor so you may easlly change Lhe appearance of your vls.

110

17 WhaL's nexL?
17.1 My 8log
lor more lnformaLlon abouL LabvlLW, vlslL my 8log: hLLp://home.hlL.no/~hansha/
17.2 1ralnlng
1hls 1uLorlal ls a parL of a serles wlLh oLher 1uLurlals l have made, such as:
lnLroducLlon Lo LabvlLW
uaLa AcqulslLlon ln LabvlLW
ConLrol and SlmulaLlon ln LabvlLW
LabvlLW MaLhScrlpL
Llnear Algebra ln LabvlLW
uaLalogglng and Supervlsory ConLrol ln LabvlLW
Wlreless uaLa AcqulslLlon ln LabvlLW
lnLermedlaLe 1oplcs ln LabvlLW
Advanced 1oplcs ln LabvlLW
eLc.
1hese 1ralnlng klLs are avallable for download (.pdf flles, source code, addlLlonal resources,
eLc.) from my blog: hLLp://home.hlL.no/~hansha
17.3 AddlLlonal 8esources
?ou flnd loLs of lnformaLlon abouL LabvlLW ln naLlonal lnsLrumenLs web slLe:
www.nl.com
17.4 Lxamples
ln Lhe NI examp|e I|nder (Pelp-llnd Lxamples.) you flnd loLs of useful examples LhaL you
can play wlLh or use as a sLarL when creaLlng your own appllcaLlons.
111 WhaL's nexL?
1uLorlal: An lnLroducLlon Lo LabvlLW


17.3 uocumenLaLlon
As parL of Lhe LabvlLW lnsLallaLlon Lhere exlsL loLs of useful documenLaLlon, such as CeLLlng
SLarLed manuals, user Manuals, eLc.


112 WhaL's nexL?
1uLorlal: An lnLroducLlon Lo LabvlLW

17.6 LabvlLW Wlkl
LabvlLW Wlkl ls Lhe free LabvlLW lnformaLlon resource LhaL anyone can edlL.
hLLp://labvlewwlkl.org/Pome

17.7 LabvlLW on ?ou1ube
1here are loLs of LabvlLW vldeos avallable aL ?ou1ube:

hLLp://www.youLube.com/resulLs?search_query=labvlew&search=Search




113

Culck 8eference

Culck 8eference
1uLorlal: An lnLroducLlon Lo LabvlLW










1e|emark Un|vers|ty Co||ege
Iacu|ty of 1echno|ogy
k[|nes k|ng S6
N-3918 orsgrunn, Norway
www.h|t.no


nans-etter na|vorsen, M.Sc.
1e|emark Un|vers|ty Co||ege
Department of L|ectr|ca| Lng|neer|ng, Informat|on 1echno|ogy and Cybernet|cs

L-ma||: hans.p.ha|vorsenQh|t.no
8|og: http:]]home.h|t.no]~hansha]



Culck 8eference
1uLorlal: An lnLroducLlon Lo LabvlLW

Potrebbero piacerti anche