2. A. Clustere (Grupuri)
• Sunt structuri de date care grupează datele împreună
• Datele pot fi de tipuri diferite (numerice, Booleene, stringuri, e.t.c.)
• Elementele trebuie să fie, fie toate controale, fie toate indicatoare
• Analog cu o legătură de fire dintr-un cablu
• Fiecare fir din cablu reprezintă un element al clusterului
• Deoarece un cluster are un singur fir (de intrare sau de ieșire) chiar dacă acesta
transportă multiple valori de diferite date, clusterele reduc firele și numărul de terminale
conector pe care un subVI le necesită. Figura de mai jos ilustrează conceptul de
grupare, respectiv degrupare, a elementelor de date într-un cluster.
3. Cluster Controls and Indicators
1. Select a Cluster shell 2. Place objects inside the shell
from the Array &
Cluster subpalette
3
4. Creating Cluster Constants
1. Select Cluster
Constant shell from the
Cluster subpalette
2. Place objects in the Cluster shell
5. Cluster Order
• Elements have a logical order (start with 0)
• To change order, right-click the border and select Reorder
Controls in Cluster...
5
6. Utilizarea Clusterelor pentru transferul
datelor în SubVI-uri
Unul dintre avantajele
clusterelor este acela că
acestea pot fi utilizate pentru
gruparea datelor la intrarea și
respectiv ieșirea subVI-urilor.
Clusterele reduc astfel
numărul de fire într-o
diagramă.
6
7. B. Funcții Cluster
• Aceste funcții se găsesc în subpaleta Cluster, Class & Variant a paletei
Functions>>Programming
8. Funcţia Bundle
• Grupează mai multe componente, realizând
un grup, sau înlocuieşte una sau mai multe
componente ale unui grup existent.
• Gruparea elementelor se realizează în ordinea acestora în cadrul grupului. Prima componentă conectată la funcţia Bundle este componenta cu index-ul 0, urmează componenta cu index-ul 1, s.a.m.d.
Numărul de intrări poate fi modificat fie prin selectarea Add Input din meniul contextual al intrării fie utilizând unealta de poziţionare / redimensionare din caseta Tools.
9. • O altă exemplificare a utilităţii funcţiei Bundle este prezentată în
figura de mai jos.
• Constanta numerică (setată la valoarea 0) defineşte punctul de
origine real iar prin controlul numeric se impune valoarea de
incrementare. Funcţia Bundle reuneşte datele numerice permiţând
reprezentarea grafică.
10. • Funcţia Bundle poate fi utilizată și pentru înlocuirea unor componente
ale unui grup (cluster) deja existent. În acest caz, grupul trebuie
conectat la intrarea cluster a funcţiei.
• În cadrul aplicaţiei de mai jos, funcţia bundle permite înlocuirea valorii
numerice corespunzatoare controlului Knob şi respectiv a controlului
Numeric 2, cu valorile numerice corespunzătoare controalelor
knob_input, respectiv Numeric 2_input.
11. Funcţia Bundle by Name
• Funcţia Bundle by Name este folosită doar pentru înlocuirea unei componente
dintr-un grup existent. Modul de lucru este asemănător cu cel prezentat anterior.
Cluster-ul existent se conectează la intrarea specificată a funcţiei (input cluster). În
ordinea logică a construcţiei se introduce controlul care va înlocui o componentă.
Componenta de înlocuit se va identifica după numele reprezentat prin eticheta
asociată. Numărul posibilităţilor de înlocuire se pot vizualiza din meniul contextual
al intrării funcţiei prin selectarea opţiunii Select Item.
12. Funcțiile Unbundle și Unbundle by Name
• Descompunerea (degruparea) grupurilor (clusterelor) în
componente, se realizează cu ajutorul a două funcţii, Unbundle
şi Unbundle by Name.
13. C. Error Clusters
•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
• Error cluster contains the following information:
– Boolean to report whether error occurred
– Integer to report a specific error code
– String to give information about the error
14. 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.
15. Error Handling with Clusters
• You can make error handling decisions on the block diagram
• 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 information is passed from one subVI to the next
• If an error occurs in one subVI, all subsequent subVIs are not executed in the usual
manner
• Error Clusters contain all error conditions
• Automatic Error Handling
Error Cluster
16. 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.
17. 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.
19. Summary
• Clusters group data elements of mixed types. A cluster cannot
contain a mixture of controls and indicators.
• To create a cluster control or indicator, select a cluster on the
Controls»Array & Cluster palette, place it on the front panel, and
drag controls or indicators into the cluster shell.
• Use the Cluster functions located on the Functions»All
Functions»Cluster palette to create and manipulate clusters.
• Error checking tells you why and where errors occur.
• The error cluster reports the status, code and source of the error.
• Use the error cluster controls and indicators to create error inputs
and outputs in subVIs.
Editor's Notes
Clusters group like or unlike components together. Equivalent to a record in Pascal or a struct in C. Cluster components may be of different data types. Examples: Error information—Grouping a Boolean error flag, a numeric error code, and an error source string to specify the exact error. User information—Grouping a string indicating a user’s name and an ID number specifying their security code. All elements of a cluster must be either controls or indicators. You cannot have a string control and a Boolean indicator. Clusters can be thought of as grouping individual wires (data objects) together into a cable (cluster).
Demonstrate how to create a cluster front panel object by choosing Cluster from the Array & Cluster palette. This option gives you a shell (similar to the array shell when creating arrays). You can size the cluster shell when you drop it. right-click inside the shell and add objects of any type. Note: You can have a cluster inside of a cluster. The cluster becomes a control or an indicator cluster based on the first object you place inside the cluster. Create a cluster constant on the block diagram by choosing Cluster Constant from the Cluster palette. This gives you an empty cluster shell. You can size the cluster when you drop it. Put other constants inside the shell. Note: You cannot place terminals for front panel objects in a cluster constant on the block diagram, nor can you place “special” constants like the Tab or Empty String constant within a block diagram cluster shell.
You create a cluster constant on the block diagram by selecting a cluster constant on the Functions»All Functions»Cluster palette, placing it on the block diagram, and dragging a constant into the cluster shell. If you have a cluster control or indicator on the front panel and you want to create a cluster constant containing the same elements on the block diagram, you can either drag that cluster from the front panel to the block diagram or right-click the cluster on the front panel and select Create»Constant from the shortcut menu.
Elements are assigned an order based on the order in which they are added to the cluster. For example, if you have two Booleans and you want to update one of them, you need to know which is which. You can change the order of the elements by popping up on the edge of the cluster and choosing Cluster Order. A small number appears next to each object. You can then change the order. (Hint: Click on each object in the order in which you want the cluster order. This will renumber the objects as desired.) Demonstrate how to create a cluster with two Booleans, a numeric control, an array, and a string. Show that if you change one object to an indicator, all objects are changed to indicators. Modify the cluster order. Emphasize how to easily make clusters using the Create Constant/Control/Indicator options on the block diagram, and by copying/pasting clusters on the front panel. This will save the students significant time when working on the exercises, and prevent possible bad wires due to incorrect cluster order.
One advantage of clusters is that you can use them to group information together to pass into and out of subVIs. Clusters overcome the limit of 28 terminals for passing data between VIs. If you have a great deal of information to pass, group it into logical units using clusters, pass a single cluster into the subVI, and then unbundle the cluster in the subVI. Clusters can reduce the number of wires in diagrams, so there are fewer wires going into and out of the subVIs. Explain the diagram on the slide.
Bundle function — Forms a cluster containing the given objects (explain the example). Bundle by Name function—Updates specific cluster object values (the object must have an owned label). Note: You must have an existing cluster wired into the middle terminal of the function to use Bundle By Name.
Error clusters are a powerful means of handling errors. The LabVIEW DAQ VIs, File I/O functions, networking VIs, and many other VI’s use this method to pass error information between nodes. The error cluster contains the following elements: status , a Boolean which is set to True if an error occurs. code , a numeric which is set to a code number corresponding to the error that occurred. source , a string which identifies the VI in which the error occurred. When you perform any kind of I/O, consider the possibility that errors will occur. Almost all I/O functions return error information. Include error checking in VIs, especially for I/O operations such as file, serial, instrumentation, data acquisition, and communication operations, and provide a mechanism to handle errors appropriately. Checking for errors in VIs can help you identify the following problems: You initialized communications incorrectly or wrote improper data to an external device. An external device lost power, is broken, or is not working properly. You upgraded the operating system software, which changed the path to a file or the functionality of a VI or library. You might notice a problem in a VI or a system program. When you perform any kind of I/O, consider the possibility that errors will occur. Almost all I/O functions return error information. Include error checking in VIs, especially for I/O operations such as file, serial, instrumentation, data acquisition, and communication operations, and provide a mechanism to handle errors appropriately. Checking for errors in VIs can help you identify the following problems: You initialized communications incorrectly or wrote improper data to an external device. An external device lost power, is broken, or is not working properly. You upgraded the operating system software, which changed the path to a file or the functionality of a VI or library. You might notice a problem in a VI or a system program.
The error clusters located on the Controls»Array & Cluster palette include the components of information shown.
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. Include an error handler VI at the end of the VI to determine if the VI ran without errors. Use the error in and error out clusters in each VI you use or build to pass error information through the VI. As the VI runs, LabVIEW tests for errors at each execution node. If LabVIEW does not find any errors, the node executes normally. If LabVIEW detects an error, the node passes the error to the next node without executing. The next node does the same thing, and so on. Use the Simple Error Handler, shown in the following example, to handle the error at the end of the execution flow. The Simple Error Handler is located on the Functions»All Functions»Time & Dialog palette. Wire the error cluster to the Error In (no error) input.
As the VI runs, LabVIEW tests for errors at each execution node. If LabVIEW does not find any errors, the node executes normally. If LabVIEW detects an error, the node passes the error to the next node without executing. The next node does the same thing, and so on. Many students will ask what the difference between the Simple Error Handler and the General Error Handler are. Have them investigate by looking at the block diagram of the Simple Error Handler. They will see that it calls the General Error Handler. Explain that the Simple Error Handler can recognize all of LabVIEW’s built in error functions, but if they want to create their own errors for their code, that they can use the General Error Handler. If they want more information, tell them that it is not covered in the scope of this course but that information is in the Help >> VI, Function, & How-To Help… under the index of “error codes, defining custom”.
You can wire an error cluster to the conditional terminal of a While Loop to stop the iteration of the While Loop. When you wire the error cluster to the conditional terminal, 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. When an error cluster is wired to the conditional terminal, the shortcut menu items Stop if True and Continue if True change to Stop on Error and Continue while Error. I would demo how to use error codes for a more effective approach by using the unbundle by name function to get the status and use an OR function so that a stop button OR an error would stop the loop.
Estimated Completion Time: 20 minutes. Create a VI that takes the square root of a number. If the number is greater than or equal to zero, the VI should return its square root, and generate no error. If the number is less than zero, the VI should return the value -9999.90, and insert an error into the error cluster. Use a Case structure from the and the Greater or Equal To 0? function from the numeric palette to determine whether the VI will compute the square root or generate the error. The “False” case shown above is the error case. Use a Bundle By Name function from the cluster palette to insert a Boolean, Numeric, and String Constant into the Status, Code, and Source cluster items, respectively. The values of the constants should be True, 5008 (an arbitrary user defined error code), and “Square Root.vi” (the name of the VI that generated the error). Wire the new cluster into the Error Out indicator, and a constant value of -9999.90 to the Square Root indicator. The True case, not shown, should merely wire the error in control directly through the case to the error out indicator. The Square Root Input should be wired to the Square Root function from the numeric palette, and the result should be wired out of the case into the Square Root indicator. Point out that this VI could be easily configured as a subVI for a larger piece of code, and troubleshooting and debugging is much easier when errors clusters are properly used.
Do not immediately display this slide. Suggested questions for class participation: What is the difference between an array and a cluster? What items are contained in the error cluster?