50
LabView Academy 3. óra - cluster, for ciklus, while ciklus, DAQ alapok

Labview Academy - Széchenyi István Egyetemherno/labview/prezentaciok/Lva.03.cluster.for.while.pdf · LabView Academy 3. óra - cluster, for ciklus, while ciklus, DAQ alapok

Embed Size (px)

Citation preview

LabView Academy3. óra - cluster, for ciklus, while ciklus, DAQ alapok

Adatok

LabVIEW Academy - SZEhttp://labviewacademy.sze.hu/

Horváth Ernőhttp://www.sze.hu/~herno/

Tanszéki honlaphttp://it.sze.hu

2

Ellenőrző kérdések

a) 55 b) 70 c) 65 d) Indeterminate

3

In the figure below, what will Result equal when this calculation is executed?

a) Auto-indexing enabled

b) Auto-indexing disabled

c) Nem eldönthető

4

Ellenőrző kérdések

Ellenőrző kérdések

a) a 1-D Array of {2, 3} b) a 1-D Array of {3, 2} c) 2 d) None of the above

5

In the figure below, the output of Array Size is:

Ellenőrző kérdések

a) 1-D Array of {-25, 25, 50}b) 1-D Array of {-25, 25}c) 2-D Array of {{-25, -50, -50} , {50, 25, 25}}d) 1-D Array of {75, -50, 25}

6

What is the result of the following Array subtraction?

Ellenőrző kérdések

a) The loop will iterate 51 times. b) The loop will iterate 50 times. c) The loop will iterate 49 times. d) A For Loop that has a 50 wired to the count terminal will

perform the same operation.

7

Which of the following statements is true regarding the execution of the following code?

While

• Feltételtől függő számú ciklust végző utasítás

• Addig ismétli az általa bekeretezett blokk diagramot, ameddig a benne lévő feltétel igaz értékű.

• Ciklusszámláló: i (Iteration Terminal) 0-ról indul, az ismétlések számát (iterációt ) adja meg.

• Ciklusfeltétel (működésére feltétel adható meg)

• Feltétel kapcsolódási ponthoz egy logikai típusú adatot kell huzaloznunk.

For

• Véges ciklust végző utasítás

• Ciklusszámláló: i (Iteration Terminal) 0-tól indul, N-1-ig fut és arról tájékoztat, hogy hányadszor fut le a ciklus.

• Ciklusok száma: N (Count Terminal)

• A blokk diagram egy részét egy N-szer végrehajtja

10

Clusters• Data structure that groups data together

• Data may be of different types

• Analogous to struct in C or a record in Pascal

• Elements must be either all controls or all indicators

• Thought of as wires bundled into a cable C nyelven hasonló adatszerkezet:

struct Pont{

int x;

int y;

int z;

double d;

};

11

1. Select a Cluster shell from the Array & Clustersubpalette

Cluster Controls and Indicators2. Place objects inside the shell

12

Creating Cluster Constants

1. Select Cluster Constantshell from the Clustersubpalette

2. Place objects in the Cluster shell

13

Using Clusters to Pass Data to SubVIs

Use clusters to pass several values to one terminal

Overcomes 28-terminal limit

Simplifies wiring

14

Cluster Functions - Bundle

Bu

nd

leB

un

dle

B

y N

ame

Create new cluster Modify existing cluster

Must have an existing cluster to use this function.

15

Cluster Functions - Unbundle

Unbundle Unbundle By Name

Error Handling

– You cannot predict every problem a user can encounter.

– Without a mechanism to check for errors, you know only that the VI does not work properly.

– Error handling tells you why and where errors occur.

• Automatic error handling

• Manual error handling

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

17

Error ClusterUse the error in and error out clusters in each VI you use or build to handle errors in the VI.

The error clusters located on the Controls»Array & Clusterpalette include the components of information shown

18

Error Cluster Details• Status is a Boolean value that reports

TRUE if an error occurred. Most VIs, functions, and structures that accept Boolean data also recognize this parameter.

• Code is a signed 32-bit integer that identifies the error numerically. A non-zero error code coupled with a status of FALSE signals a warning rather than a fatal error.

• Source is a string that identifies where the error occurred.

Hibaellenőrzés és hibakezelés

• Hibaellenőrzés: Van-e hiba, hol van hiba?

• Hibakezelés:– Kezdjünk is vele valamit!

– Automatikus hibakezelés

– Manuális hibakezelés

• Egy hibavezetékre fűzzük fel a csomópontokat– Időzítésre is jó (adatfolyam)

19

20

Error Handling with Clusters

• LabVIEW does not handle errors automatically. In LabVIEW, you can make these error handling decisions on the block diagram of the VI.

• Error handling in LabVIEW follows the dataflow model. Just as data flow through a VI, so can error information.

• Wire the error information from the beginning of the VI to the end.

Error Cluster

21

Simple Error Handler

Use the Simple Error Handler to handle the error at the end of the execution flow.

The Simple Error Handler is located on the Functions»AllFunctions»Time and Dialog palette. Wire the error cluster to the Error In (no error) input.

22

Using While Loops for Error Handling

You can wire an error cluster to the conditional terminal of a While Loop to stop the iteration of the While Loop.

Only the TRUE or FALSE value of the status parameter of the error cluster is passed to the terminal.

When an error occurs, the While Loop stops.

Dialog

• One button (csak a kattintás ténye)

• Two button (választás)

Automatic Error Handling

– By default, LabVIEW automatically handles any known error when a VI runs by:

• Suspending execution.

• Highlighting the subVI or function where the error occurred.

• Displaying the Error list window.

– Automatic error handling is:

• Acceptable for quick prototypes.

• Not recommended for professional application development.

• Not included in LabVIEW-built executables.

24

Manual Error Handling– You control when dialog boxes appear.

– Propagate errors by wiring the error out cluster to error in cluster of next node to execute.

– Terminate the error chain with a call to Simple Error Handler VI.

25

Disable Automatic Error Handling– Options Dialog Box

• Block Diagram page – Uncheck

» Enable automatic error handling in new VIs

» Enable automatic error handling dialogs

– Other suggested changes• Front Panel page

– Set Control Style for New VIs to Silver style

• Block Diagram page – Uncheck

» Place front panel terminals as icons

– Configure Block Diagram Cleanup to customize your block diagram

Merge Errors

– Propagate errors along wires.

– Merge errors from different wire paths.

Merge Errors Function– Merge Errors function returns the first error

found. If no error is found, it returns the first warning.

– The Merge Errors function does not concatenate errors.

Error Clusters– Use the error cluster controls and indicators to

create error inputs and outputs in subVIs.

29

• The error in and error out clusters include the following components of information:

− Status

− Code

− Source

Errors and Warnings

Status = TRUEStatus = FALSE

Code = Non-zero

Error Warning

Errors and Warnings Recommendations

– Report errors and warnings with the Simple Error Handler VI

• Modify Type of Dialog to detect warnings.

– Call the Simple Error Handler VI from the top-level VI.

– Avoid error dialogs in subVIs.

Melyik esetben While és mikor For ciklus?

For

• Ha előre tudjuk, hogy egy feladatot pl. 50-szer kell elvégeznünk.

• Általában a tömb műveletek

• Lefuthat 0-szor isMiért? Mert a feltétel (ami az N-be van kötve) futás előtt kiértékelődik, ha az 0, akkor gyakorlatilag le se fut.

While

• Érdemes használni, ha egy felhasználói beavatkozásig vagy egy bizonyos érték eléréséig várunk.

• Legalább egyszer lefutMiért? Mert a feltétel kiértékelődése az első futáskor történik meg; aztán persze minden további esetben, ha van.

32

Shift regiszter

• Az előző iterációból érkező adatot használhatjuk fel segítségével

• Ha 2szer fut le:Result = (( Initial * 3 ) * 3 )

33

Milyen eredmény jelenik meg az indikátoron?

• A ciklus 4x fut le

• Futása:

•i = 0 Indikátor = 2

•i = 1 Indikátor = 4

•i = 2 Indikátor = 8

•i = 3 Indikátor = 16

• Shift regiszter

34

Debugging Techniques

What to look for if a VI produces unexpected data or behavior:

– Are there any unwired or hidden subVIs?

– Is the default data correct?

– Does the VI pass undefined data?

– Are numeric representations correct?

– Are node executed in the correct order?

35

Execution Highlighting

– Use execution highlighting to watch the data flow through the block diagram.

– If the VI runs more slowly than expected, confirm that you turned off execution highlighting in subVIs.

36

Single-Stepping

– Single-step through the VI to view each action of the VI on the block diagram.

– Suspend the execution of a subVI to edit values of controls and indicators, to control the number of times it runs, or to go back to the beginning of the execution of the subVI.

• Open subVI and select Operate»Suspend When Called from the shortcut menu.

37

Probes– Use the Probe tool to observe intermediate data

values and check the error output of VIs and functions, especially those performing I/O.

– Specify to retain the values in the wires so that you can probe wires for data after execution.

38

Breakpoints

– When you reach a breakpoint during execution, the VI pauses and the Pausebutton appears red.

39

• You can take the following actions at a breakpoint:− Single-step through execution using the single-stepping buttons.

− Probe wires to check intermediate values.

− Change values of front panel controls.

− Click the Pause button to continue running to the next breakpoint or until the VI finishes running.

Melyik esetben While és mikor For ciklus?

For

• Ha előre tudjuk, hogy egy feladatot pl. 50-szer kell elvégeznünk.

• Általában a tömb műveletek

• Lefuthat 0-szor isMiért? Mert a feltétel (ami az N-be van kötve) futás előtt kiértékelődik, ha az 0, akkor gyakorlatilag le se fut.

While

• Érdemes használni, ha egy felhasználói beavatkozásig vagy egy bizonyos érték eléréséig várunk.

• Legalább egyszer lefutMiért? Mert a feltétel kiértékelődése az első futáskor történik meg; aztán persze minden további esetben, ha van.

40

Shift regiszter

• Az előző iterációból érkező adatot használhatjuk fel segítségével

• Ha 2szer fut le:Result = (( Initial * 3 ) * 3 )

41

Milyen eredmény jelenik meg az indikátoron?

• A ciklus 4x fut le

• Futása:

•i = 0 Indikátor = 2

•i = 1 Indikátor = 4

•i = 2 Indikátor = 8

•i = 3 Indikátor = 16

• Shift regiszter

42

Elektrotechnikai tudnivalók

Light-emitting diode (LED) félvezető anyagból készült fényforrás.

43

Elektrotechnikai tudnivalók

A fotóellenállás (photoresistor) egy berendezés, amely a fényhullámokra elektromos választ ad.

44

45

Led: GND / AO0Fotóellenállás: GND / +5V / AI0

pelda_cluster01.vi

Olvassunk be analóg jeleket lebegőpontos számként adatgyűjtő kártyáról. A felhasználó adhasson meg egész értékeket, majd ezeket egy klaszterré (cluster) összefoglalva jelezzük ki diagramon (chart) és számértékként.

46

pelda_cluster01.vi

47

pelda_cluster01.vi

48

pelda_cluster02.vi

Fejlesszük tovább az előző példa hibakezelését.

Amennyiben a mérőkártyáról hiba érkezik (pl. USB kábel kihúzásából eredően) a program álljon le, és indikátoron jelezze a hiba kódját, forrását.

49

Köszönöm a figyelmet!