LabView Academy 3. óra - cluster, for ciklus, while ciklus, DAQ alapok
Adatok LabVIEW Academy - SZE http://labviewacademy.sze.hu/ Horváth Ernő http://www.sze.hu/~herno/ Tanszéki honlap http://it.sze.hu 2
Ellenőrző kérdések In the figure below, what will Result equal when this calculation is executed? a) 55 b) 70 c) 65 d) Indeterminate 3
Ellenőrző kérdések a) Auto-indexing enabled b) Auto-indexing disabled c) Nem eldönthető 4
Ellenőrző kérdések In the figure below, the output of Array Size is: a) a 1-D Array of {2, 3} b) a 1-D Array of {3, 2} c) 2 d) None of the above 5
Ellenőrző kérdések What is the result of the following Array subtraction? 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
Ellenőrző kérdések Which of the following statements is true regarding the execution of the following code? 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
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.
Véges ciklust végző utasítás For 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
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; }; 10
Cluster Controls and Indicators 1. Select a Cluster shell from the Array & Cluster subpalette 2. Place objects inside the shell 11
Creating Cluster Constants 1. Select Cluster Constant shell from the Cluster subpalette 2. Place objects in the Cluster shell 12
Using Clusters to Pass Data to SubVIs Use clusters to pass several values to one terminal Overcomes 28-terminal limit Simplifies wiring 13
Bundle By Name Bundle Cluster Functions - Bundle Create new cluster Modify existing cluster Must have an existing cluster to use this function. 14
Cluster Functions - Unbundle Unbundle Unbundle By Name 15
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
Error Cluster Use 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 & Cluster palette include the components of information shown 17
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 nonzero 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. 18
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
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. 20 Error Cluster
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»All Functions»Time and Dialog palette. Wire the error cluster to the Error In (no error) input. 21
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. 22
Dialog One button (csak a kattintás ténye) Two button (választás)
24 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.
25 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.
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.
29 Error Clusters Use the error cluster controls and indicators to create error inputs and outputs in subvis. The error in and error out clusters include the following components of information: Status Code Source
Errors and Warnings Status = TRUE Status = 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 is Mié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 lefut Mié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
35 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?
36 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.
37 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.
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
39 Breakpoints When you reach a breakpoint during execution, the VI pauses and the Pause button appears red. 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 is Mié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 lefut Mié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
Led: GND / AO0 Fotóellenállás: GND / +5V / AI0 45
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!