III. Implementarea unui VI

Slides:



Advertisements
Similar presentations
A. Virtual Instruments (VIs)
Advertisements

Previously… We created a simulated temperature reader which alerts if too hot or too cold… Download the solved practice to keep in sync: Thermostat.vi.
LabVIEW is a graphical programming development environment for data acquisition and control, data analysis, and data presentation. With LabVIEW you can.
Lesson 2 Navigating LabVIEW
Based on LabVIEW 2011 Student Edition
Diego Torres LabVIEW Student Ambassador Fall 2011 ITESM CQ
Welcome! Workshop 2 of 7.
Loops in LabVIEW (while,for and case)
Floyd, Digital Fundamentals, 10 th ed EET 2259 Unit 5 Loops  Read Bishop, Sections 5.1 and 5.2.  Lab #5 and Homework #5 due next week.  Exam #1 next.
CS320n –Visual Programming LabVIEW Foundations. Visual ProgrammingLabVIEW Foundations2 What We Will Do Today Hand back and review the midterm Look at.
Loops A.About While Loops B.About For Loops C.About Case structures D.Sequence Structures E.Formula Node You Will Learn:
1 Lesson 5 Clusters TOPICS Introduction to Clusters Cluster Functions Error Clusters.
CS320n –Visual Programming LabVIEW Control Structures.
Introduction to LabVIEW Seth Price Department of Chemical Engineering New Mexico Tech Rev. 10/5/14.
Lecture 13LabVIEW and GPIB LabVIEW (National Instruments) –Graphical program language –Widely used in academia (lab) and industry (R&D) General Purpose.
Infinity-project.org Engineering education for today’s classroom The Infinity Project SM LabVIEW for The Infinity Project.
Workshop 3 of 7 Welcome!. Today's Topics Review of Workshop 2 Loops While For Auto-indexing Shift registers Case Structure.
V1: HMFR, V2: MFNB, 2007 LabView Seminar University of Puerto Rico Mayagüez Campus.
Virtual Instrumentation With LabVIEW. Course Goals Understand the components of a Virtual Instrument Introduce LabVIEW and common LabVIEW functions Create.
Virtual Instrumentation With LabVIEW. Front Panel Controls = Inputs Indicators = Outputs LabVIEW Programs Are Called Virtual Instruments (VIs) Block Diagram.
LabVIEW an Introduction
Each VI has 2 Windows Front Panel User Interface (UI) –Controls = Inputs –Indicators = Outputs Block Diagram Graphical Code –Data travels on wires from.
Design of Bio-Medical Virtual Instrumentation Tutorial 3.
LabView instrumentoinnissa, 55492, 3op Labview in instrumentation Lecturer: Heikki Ojala, room C204a
Creating, Editing, & Debugging a VI A.How to Create VIs B.How to Edit VIs C.How to Debug VIs You Will Learn:
Digital Electronics and Computer Interfacing Tim Mewes 4. LabVIEW - Advanced.
CS320n –Visual Programming
Virtual Instrumentation With LabVIEW. Front Panel Controls = Inputs Indicators = Outputs Block Diagram Accompanying “program” for front panel Components.
CS320n –Visual Programming More LabVIEW Foundations.
Floyd, Digital Fundamentals, 10 th ed EET 2259 Unit 9 Arrays  Read Bishop, Sections 6.1 to 6.3.  Homework #9 and Lab #9 due next week.  Quiz #5 next.
Digital Electronics and Computer Interfacing Tim Mewes 2. LabVIEW Basics part II.
MEH108 - Intro. To Engineering Applications KOU Electronics and Communications Engineering.
Week 3 Data Structures and Common Tools. Common Tools in Labview Automatic Tool Selector Using the Operating Tool Using the Positioning Tool to Select.
Workshop 5 of 7 Welcome!. Today's Topics Review from Workshop 4 Modularity & subVIs Documentation File Input/Output Introduction.
Week 3 Labview exercises
EET 2259 Unit 13 Strings and File I/O
Quiz Which types of folders are available in a LabVIEW Project?
LabVIEW Core 1 Key messages for the instructor:
Course Learning Map Lesson # Lesson Title Lesson 3 Lesson 2 Lesson 1
EE 200 Design Tools Laboratory 14
EET 2259 Unit 5 Loops Read Bishop, Sections 5.1 and 5.2.
EET 2259 Unit 3 Editing and Debugging VIs
ACTIVITATEA 1 -,, PROFESOR IT LA PAPI’’
III. Tablouri (Arrays) și Clustere
Funcţii Excel definite de utilizator (FDU) în VBA
Course Learning Map Lesson # Lesson Title Lesson 3 Lesson 2 Lesson 1
Introduction to LabVIEW
Structura pipeline a unui procesor MIPS
Paxos Made Simple Autor: Puşcaş Radu George
CONVERSII INTRE SISTEME DE NUMERATIE
F. Diagrama Bloc Diagrama Bloc (DB) reprezintă programul propriu-zis dezvoltat în mediul LabVIEW şi conţine codul sursă al instrumentului virtual. O DB.
Tipuri structurate Tipul tablou
הודעות ריענון מהיר והרחבות כתיבה לקובץ Low-Level דגימת אות Low-Level
Formatarea paragrafului
Funcții C/C++ continuare
Forms (Formulare).
A great way to create a channel of communication
EET 2259 Unit 5 Loops Read Bishop, Sections 5.1 and 5.2.
Chapter 7 Additional Control Structures
Bazele Tehnologiei Informaţiei Curs 3
Realizarea prezentarilor cu Microsoft PowerPoint
Crearea unei aplicatii Windows Forms simple
Aplicaţii specializate pentru realizarea unei prezentări – PowerPoint
Structures- case, sequence, formula node
CST-115 Introduction to Computer Programming
EET 2259 Unit 9 Arrays Read Bishop, Sections 6.1 to 6.3.
Introduction to LabVIEW
EET 2259 Unit 13 Strings and File I/O
EET 2259 Unit 7 Case Structures; Sequence Structures
EET 2259 Unit 5 Loops Read Bishop, Sections 5.1 and 5.2.
Presentation transcript:

III. Implementarea unui VI În acest capitol este prezentat modul de implementare a codurilor în LabVIEW. Astfel, acest capitol cuprinde: proiectarea interfeței utilizator (PF); alegerea între diferitele tipuri de date; utilizarea buclelor în LabVIEW (bucla While și bucla For) adăugarea unor întârzieri (timing) între iterațiile buclelor; luarea deciziilor într-un VI, utilizând funcția Select și structura Case; structura secvențială (Sequence) și nodul Formulă.

Topics A. Front Panel Design B. LabVIEW Data Types C. While Loops D. For Loops E. Timing a VI F. Iterative Data Transfer. Regiștrii de transfer (deplasare) G. Plotting Data H. Luarea deciziilor într-un VI. I. Structura secvențială (Sequence) J. Nodul Formulă (Formula Node)

A. Front Panel Design În faza de proiectare a unui VI, trebuiesc mai întâi identificate intrarile și ieșirile VI-ului respectiv. Această identificare duce practic la proiectarea ferestrei panoului frontal. Intrările VI-ului se numest Controale (C), iar ieșirile Indicatoare (I). Putem afișa rezultatele unei aplicații cu ajutorul diferitelor tipuri de indicatoare, cum ar fi grafice, diagrame, sau LED-uri. De asemenea, ieșirile pot fi salvate într-un fișier.

Alegerea Controalelor și Indicatoarelor Atunci când alegem C și I din PF, trebuie să ne asigurăm că acestea sunt adecvate pentru activitatea pe care dorim să o efectuăm. De exemplu, atunci când dorim să modificăm frecvența unui semnal vom alege un C de tip cadran (Dial), iar atunci când dorim să afișăm temperatura, vom alege un I de tip termometru.

Asigurați-vă de etichetarea clară a controalelor și indicatoarelor Asigurați-vă de etichetarea clară a controalelor și indicatoarelor. Etichetarea ajută utilizatorii să identifice scopul fiecărui C și I. De asemenea, o etichetare clară a C și I din PF, ne va ajuta la realizarea DB, deoarece etichetele din PF vor apărea și la terminalele corespunzătoare în DB.

You can hide and view items on controls and indicators You can hide and view items on controls and indicators. For example, in Figure 2.1, you can see both the caption (legenda) and the label (eticheta). However, you only need to see the caption. To hide the label, right-click the control and select Visible Items»Label as shown in Figure 2.1. Figure 2.1. Hiding a Front Panel Label

B. LabVIEW Data Types Many different data types exist for data. You already learned about numeric, Boolean, and string data types in Lesson, Navigating LabVIEW. Other data types include the enumerated data type, dynamic data, and others. Even within numeric data types, there are different data types, such as whole numbers or fractional numbers. Terminals The block diagram terminals visually communicate to the user some information about the data type they represent.

For example, in Figure 2.2, Height (cm) is a double-precision, floating-point numeric. This is indicated by the color of the terminal, orange, and by the text shown on the terminal, DBL. Figure 2.2. Terminal Data Type Example

Tipuri de date utilizate în LabVIEW Numerice Intreg cu semn - Signed integers (8-16-32-64 biti) Intreg fara semn - Unsigned integers (8-16-32-64 biti) Virgula mobila - Floating point ( single, double, extended) Numar complex in virgula mobila - Complex floating point ( single, double, extended) Booleane String-uri Formă de undă - Waveform Cale - Path Enumerare - Enum Cluster Numeric Diverse tipuri Mixed data Matrice - Array 1D 2D

Toate tipurile de date enumerate mai sus pot fi utilizate si plasate pe Diagrama Bloc. Fiecare tip de data are o reprezentare grafica sub forma de Icoană sau de Terminal. Reprezentarea sub forma de Icoană este mai sugestiva însă are o dimensiune mai mare, pe când reprezentarea sub forma de Terminal este mai restrânsă si ocupa mai putin loc în cadrul aplicatiei schitate în Diagrama Bloc.

Tipuri de date numerice

Tipuri de date numerice (continuare)

Moduri de reprezentare a valorilor numerice Meniurile proprii ale elementelor de tip control sau de tip indicatoar numeric contin o optiune specifica, Representation, cu ajutorul careia se specifica modul in care valoarea numerica respectiva este stocata in memorie. Figure 2.3. Numeric Representation

In submeniul Representation, utilizatorul are la dispozitie 12 optiuni: pe prima linie: optiuni pentru numere reale pe a doua linie: optiuni pentru numere intregi pe a treia linie: optiuni pentru numere naturale pe a patra linie: optiuni pentru numere complexe Intre diversele optiuni de pe o linie, diferenta consta in numarul de octeti (bytes) alocati in memorie pentru stocarea valorii respective:

 EXT (extended) = numar real cu precizie extinsa (16 octeti)  DBL (double) = numar real cu precizie dubla (8 octeti)  SGL (single) = numar real cu precizie simpla (4 octeti)  I32 (long) = numar intreg pe 4 octeti  I16 (word) = numar intreg pe 2 octeti  I8 (byte) = numar intreg pe 1 octet  U32 (unsigned long) = numar natural pe 4 octeti  U16 (unsigned word) = numar natural pe 2 octeti  U8 (unsigned byte) = numar natural pe 1 octet  CXT (complex extended) = numar complex cu precizie extinsa (32 octeti)  CDB (complex double) = numar complex cu precizie dubla (16 octeti)  CSG (complex single) = numar complex cu precizie simpla (8 octeti)

În calculatoare sunt utilizate două tipuri de reprezentări binare ale numerelor reale: - reprezentarea în virgulă fixă şi - reprezentarea în virgulă flotantă (mobilă). Reprezentarea în virgulă fixă este o reprezentare care pune în evidenţă semnul, partea întreagă şi partea fracţionară a numărului. Dimensiunile locaţiei de memorie în care se reprezintă un număr în virgulă fixă este prefixată: 8, 16, 32 sau 64 de biţi. Principalul dezavantaj al reprezentării în virgulă fixă este faptul că, dacă un număr nu mai încape în spaţiul de biţi rezervat, se pierd cifrele cele mai semnificative! Reprezentarea în virgulă flotantă este astfel concepută, încât, la depăşire, se pierd cifrele cel mai puţin semnificative!

Numarul de octeti alocati pentru stocare se reflecta in intervalul de valori în care poate exista valoarea respectiva sau în precizia acesteia:

Atunci când se leagă date numerice de reprezentări diferite la intrările aceleiaşi funcţii, LabVIEW furnizează rezultatul de tipul cel mai lung. Dacă ambele intrări au acelaşi număr de biţi dar sunt de reprezentări diferite (de ex. U32 şi I32), LabVIEW furnizează rezultatul fără semn. In exemplul din figura următoare, adunarea dintre un număr real în reprezentare dublă precizie (8 octeţi) și un număr întreg cu semn pe 4 octeţi I32 dă un rezultat corespunzător numărului mai lung, deci real dublă precizie. Această operaţie se numeşte constrângere, iar operandul constrâns este marcat printr-un punct la intrarea în funcţie.

Apariția operaţiei de constrângere

Alte tipuri de date în LabVIEW

Functiile numerice ale mediului LabVIEW.

Functiile trigonometrice ale mediului LabVIEW.

Functiile logaritmice ale mediului LabVIEW.

Constante numerice aditionale ale mediului LabVIEW.

Variabile locale  De multe ori avem nevoie sa utilizam in multe locuri aceeasi variabila. Pentru a nu supraâncărca diagrama bloc cu linii de legatura, se poate defini o variabila locală care va putea fi plasată în toate locurile în care avem nevoie de ea. Plasarea variabilei se face alegând din grupul: Functions->Programming->Structures->Local-Variable. Dupa plasarea ei, cu click dreapta pe variabila->Select Item, putem alege controlul atașat acestei variabile. 

Sa presupunem ca dorim ca valoarea de intrare Ui să o afișăm în trei indicatoare. 

Meniuri proprii specifice elementelor booleene Elementele de control booleene dispun in meniul propriu de optiunea suplimentara Mechanical Action, aceasta permițând stabilirea modului in care elementul se comporta la apasarea butonului mouse-ului de catre utilizator.

>>> Switch When Pressed modifica valoarea logica a elementului atunci cand se apasa butonul mouse-ului, iar valoarea ramane modificata si dupa eliberarea butonului; >>> Switch When Released modifica valoarea logica a elementului atunci cand se elibereaza butonul mouse-ului (dupa ce in prealabil a fost apasat), iar valoarea ramane modificata si dupa eliberare; >>> Switch Until Released modifica valoarea logica a elementului atunci cand se apasa butonul mouse-ului, iar dupa eliberarea butonului valoarea elementului redevine cea dinaintea apasarii;

>>> Latch When Pressed modifica valoarea logica a elementului atunci cand se apasa butonul mouse-ului, dar aceasta modificare dureaza doar pana cand valoarea logica este transmisa in diagrama bloc pe fluxul de date. Imediat ce valoarea elementului a fost transmisa, acesta revine la valoarea dinaintea apasarii, chiar daca utilizatorul continua sa tina butonul mouse-ului apasat. >>> Latch When Released modifica valoarea logica a elementului atunci cand se elibereaza butonul mouse-ului (dupa ce in prealabil a fost apasat), dar această modificare dureaza doar pana cand valoarea logica este transmisa in diagrama pe fluxul de date. Dupa ce valoarea a fost transmisa, elementul revine la valoarea initiala. >>> Latch Until Released modifica valoarea logica a elementului atunci cand se apasa butonul mouse-ului, iar modificarea se pastreaza atat timp cat utilizatorul tine butonul apasat. Dupa ce utilizatorul elibereaza butonul, elementul revine la valoarea initiala doar in momentul in care se realizeaza o transmitere a valorii pe fluxul de date.

Aplicație Dispuneti pe panou un element boolean de control de tipul Vertical Toggle Switch si un element indicator de tipul Round LED. In diagrama bloc, conectati intre ele terminalele celor doua elemente. Pentru fiecare optiune Mechanical Option a elementului de control, efectuati o rulare continua (butonul Run Continuously) si observati modul in care se comporta comutatorul si modul in care valoarea sa logica este transmisa elementului Round LED.

Functiile logice ale mediului LabVIEW.

Functiile pentru realizarea comparatiilor ale mediului LabVIEW.

Strings A string is a sequence of displayable or non-displayable ASCII characters. Strings provide a platform-independent format for information and data. Some of the more common applications of strings include the following: Creating simple text messages. Controlling instruments by sending text commands to the instrument and returning data values in the form of either ASCII or binary strings which you then convert to numeric values. Storing numeric data to disk. To store numeric data in an ASCII file, you must first convert numeric data to strings before writing the data to a disk file.

Atentionarea sau întrebarea utilizatorului prin intermediul unei cutii de dialog. Funcţiile pentru valorile alfanumerice sunt grupate în subpaleta String a paletei de Funcții. Mai frecvent utilizate sunt cele pentru transformarea caracterelor în majuscule (To Upper Case), pentru transformarea caracterelor în minuscule (To Lower Case), de calculare a lungimii unui şir de caractere (String Length), de compunere a unui şir din două şiruri distincte (Concatenate String), de identificare şi înlocuire a unui şir în cadrul altuia (Search and Replace String) etc. De asemenea, subpaleta String conţine un element String Constant utilizat pentru introducerea în diagramă a valorilor alfanumerice constante.

Enums An enum (enumerated control, constant or indicator) is a combination of data types. An enum represents a pair of values, a string and a numeric, where the enum can be one of a list of values. For example, if you created an enum type called Month, the possible value pairs for a Month variable are January-0, February-1, and so on through December-11. Figure 2.5 shows an example of these data pairs in the Properties dialog box for an enumerated control. Enums are useful because it is easier to manipulate numbers on the block diagram than strings. Figure 2.6 shows the Month enumerated control, the selection of a data pair in the enumerated control, and the corresponding block diagram terminal.

Figure 2.5. Properties for the Month Enumerated Control

Figure 2.6. Month Enumerated Control

Dynamic The dynamic data type stores the information generated or acquired by an Express VI. The dynamic data type appears as a dark blue terminal, shown at left. Most Express VIs accept and/or return the dynamic data type. You can wire the dynamic data type to any indicator or input that accepts numeric, waveform, or Boolean data. Wire the dynamic data type to an indicator that can best present the data. Indicators include graphs, charts,or numeric indicators. Most other VIs and functions in LabVIEW do not accept the dynamic data type. To use a built-in VI or function to analyze or process the data the dynamic data type includes, you must convert the dynamic data type.

Most other VIs and functions in LabVIEW do not accept the dynamic data type. To use a built-in VI or function to analyze or process the data the dynamic data type includes, you must convert the dynamic data type. Use the Convert from Dynamic Data Express VI to convert the dynamic data type to numeric, Boolean, waveform, and array data types for use with other VIs and functions.

When you place the Convert from Dynamic Data Express VI on the block diagram, the Configure Convert from Dynamic Data dialog box appears. The Configure Convert from Dynamic Data dialog box displays options that let you specify how you want to format the data that the Convert from Dynamic Data Express VI returns. When you wire a dynamic data type to an array indicator, LabVIEW automatically adds the Convert from Dynamic Data Express VI to the block diagram. Double-click the Convert from Dynamic Data Express VI to open the Configure Convert from Dynamic Data dialog box to control how the data appears in the array.

C. While Loops Similar comportarii unei bucle Do sau a unei bucle Repeat-Until (=repetă până când) în cadrul limbajelor de programare bazate pe text, o buclă While execută o subdiagramă atâta timp cât este îndeplinită o condiție. The following illustration shows a While Loop in LabVIEW, a flowchart equivalent of the While Loop functionality, and a pseudo code example of the functionality of the While Loop.

Figure 2.7. While Loop

The While Loop is located on the Structures palette The While Loop is located on the Structures palette. Select the While Loop from the palette then use the cursor to drag a selection rectangle around the section of the block diagram you want to repeat. When you release the mouse button, a While Loop boundary encloses the section you selected. Add block diagram objects to the While Loop by dragging and dropping them inside the While Loop.

2. Înlănțuirea codului a fi repetat 1. Selectare buclă While 2. Înlănțuirea codului a fi repetat 3. Adăugarea de noduri suplimentare și apoi realizarea legăturilor Bucla “WHILE” permite execuţia subdiagramei din interiorul său, atât timp cât o condiţie dată este adevărată ( sau falsă ). “i” are semnificaţia de contor al ciclului în vreme ce terminalul din dreapta jos reprezintă condiţia de execuţie a ciclului (se execută atât timp cât variabila conectată la acest terminal are valoarea “TRUE”). Terminalul “iterație” conține numărul de executări ale buclei (pornește de la zero). In exemplul de mai sus bucla While se execută până ce valoarea de ieşire de la butonul de stop este TRUE. Do (Execută diagrama din interiorul buclei) While Condition is TRUE Terminal iterație Terminal condiționare

A While loop repeats the sub diagram inside it until the conditional terminal, an input terminal, receives a particular Boolean value. The Boolean value depends on the continuation behavior of the While Loop. Right-click the conditional terminal and select Stop if True or Continue if True from the shortcut menu. You also can wire an error cluster to the conditional terminal, right-click the terminal, and select Stop on Error or Continue while Error from the shortcut menu. The While Loop always executes at least once. Below we see an empty While loop:

Selectarea condițiilor buclei Clic dreapta în terminalul condiționare pentru definirea opririi buclei Pe marginile buclei se pot crea regiștri de deplasare care transferă datele de la o iterație la următoarea Terminal iterație Terminal condiționare

Structure Tunnels Tunnels feed data into and out of structures. The tunnel is a block that appears on the border; the color of the block is related to the data type wired to the tunnel. When a tunnel passes data into a loop, the loop executes only after data arrive at the tunnel. Data pass out of a loop after the loop terminates.

Exemple de bucle While În diagrama bloc din figură, bucla While este executată până când ieșirea funcției de multiplicare este mai mare sau egală cu 5, iar controlul Enable este Adevărat (True). Funcția ȘI (AND) returnează la ieșire valoarea True doar dacă cele două intrări sunt True. Altfel ieșirea este False. You can change the behavior and appearance of the conditional terminal by right-clicking the terminal or the border of the While Loop and selecting Continue if True.

This example run until either the user clicks the stop button or number of iterations is greater than 10.

VI-ul din figura de mai jos generează numere aleatoare, până când numărul generat corespunde cu numărul specificat. Terminalul iteratie înregistrează numărul de numere aleatoare generate, până când apare numărul specificat.

Using While Loops for Error Handling You can wire an error cluster to the conditional terminal of a While Loop or a For Loop with a conditional terminal to stop the iteration of the loop. If you wire the error cluster to the conditional terminal, only the TRUE or FALSE value of the status parameter of the error cluster passes to the terminal. If an error occurs, the loop stops. In a For Loop with a conditional terminal, you also must wire a value to the count terminal or auto-index an input array to set a maximum number of iterations. The For Loop executes until an error occurs or until the number of set iterations completes.

Figure 2.8. Stopping a While Loop If you wire an error cluster to the conditional terminal, the shortcut menu items Stop if True and Continue if True change to Stop on Error and Continue while Error. In Figure 2.8, the error cluster and a stop button are used together to determine when to stop the loop. This is the recommended method for stopping most loops. Figure 2.8. Stopping a While Loop

D. For Loops A For Loop, shown as follows, executes a subdiagram a set number of times. Figure 2.9 shows a For Loop in LabVIEW, a flowchart equivalent of the For Loop functionality, and a pseudo code example of the functionality of the For Loop. The For Loop is located on the Structures palette. You also can place a While Loop on the block diagram, right-click the border of the While Loop, and select Replace with For Loop from the shortcut menu to change a While Loop to a For Loop. The count terminal is an input terminal whose value indicates how many times to repeat the subdiagram.

Figure 2.9. For Loop

Terminalul de numărare (terminal de intrare) Terminal iterație (terminal de ieșire)

Terminalul de numărare arată de câte ori se se va executa bucla. Bucla For are două terminale: terminalul de numărare N (un terminal de intrare) şi terminalul de iterație i (un terminal de ieşire). Terminalul de numărare arată de câte ori se se va executa bucla. Terminalul de iteraţie arată iterația curentă. Pe marginile buclei For, la fel ca și pe marginile buclei While se pot crea regiștri de deplasare care transferă datele de la o iterație la următoarea. Exemplul de mai sus arată o buclă For ce generează 100 de numere aleatoare şi afişează punctele pe un înregistrator. In interiorul buclei se mai afla si un terminal iterație (notat cu i) care genereaza o valoare numar natural reprezentând indicele iteratiei aflate in curs de executie. Indicii iteratiilor sunt numerotati incepând de la valoarea 0, astfel incât ultima iteratie executata de catre bucla For va avea indicele N-1.

The iteration count for the For Loop always starts at zero. The For Loop differs from the While Loop in that the For Loop executes a set number of times. A While Loop stops executing the subdiagram only if the value at the conditional terminal exists. The For Loop in Figure 2.10 generates a random number every second for 100 seconds and displays the random numbers in a numeric indicator. Figure 2.10. For Loop Example

Adding a Conditional Terminal to a For Loop If necessary, you can add a conditional terminal to configure a For Loop to stop when a Boolean condition or an error occurs. A For Loop with a conditional terminal executes until the condition occurs or until all iterations are complete, whichever happens first. For Loops you configure for a conditional exit have a red glyph in the count terminal as well as a conditional terminal in the lower right corner. After you configure the For Loop to exit conditionally, the loop appears similar to Figure 2.11. The following For Loop generates a random number every second until 100 seconds has passed or the user clicks the stop button.

Figure 2.11. For Loop Configured for a Conditional Exit To add a conditional terminal to a For Loop, right-click on the For Loop border and select Conditional Terminal from the shortcut menu (Fig.2.12). Then wire the conditional terminal and the count terminal. Figure 2.11. For Loop Configured for a Conditional Exit

Figure 2.12. Adding a Conditional Terminal to a For Loop

Numeric Conversion LabVIEW can represent numeric data types as signed or unsigned integers, floating-point numeric values, or complex numeric values, as discussed in the LabVIEW Data Types section of this lesson. Normally, when you wire different representation types to the inputs of a function, the function returns an output in the larger or wider format. If you use a signed integer with an unsigned integer, it will coerce to the unsigned integer. If you use an unsigned integer with a floating point, it will coerce to the floating point. If you use a floating point number with a complex number, it will coerce to the complex number.

If you use two numbers of the same type with different bit widths, LabVIEW will coerce to the larger of the two bit widths. For example, if you wire a DBL and an I32 to a Multiply function, the result is a DBL, as shown in Figure 2.13. LabVIEW coerces the 32-bit signed integer because it uses fewer bits than the double-precision, floating-point numeric value. The lower input of the Multiply function shows a red dot, called a coercion dot, that indicates LabVIEW coerced the data.

Figure 2.13. Numeric Conversion Example However, the For Loop count terminal works in the opposite manner. If you wire a double-precision, floating-point numeric value to the 32-bit count terminal, LabVIEW coerces the larger numeric value to a 32-bit signed integer. Although the conversion is contrary to normal conversion standards, it is necessary, because a For Loop can only execute an integer number of times.

Figure 2.14. Coercion on a For Loop For better performance, avoid coercion by using matching data types or programmatically converting to matching data types, as shown in Figure 2.15.

Figure 2.15. Avoiding Coercion By Using Matching Data Types