A cluster is a data structure similar to an array that is used to group data. There are important differences between clusters and arrays. One important difference is that a cluster can contain different data types, while an array can only contain the same data type. For example, an array can contain 10 numeric indicators, but a cluster can contain a numeric control, a switch, and a string control.
Although the elements of clusters and arrays are stored in order, it is best to access the elements of a cluster by releasing some or all of them at the same time, rather than accessing one element at a time by index. Another difference between clusters and arrays is that clusters have a fixed size.
Clusters are often used to group related data elements that appear on a block diagram. Because clusters are represented by a single wire on a block diagram, using clusters has a positive effect on reducing wire clutter and the number of connector terminals required for subVIs. You can think of a cluster as a bundle of wires, with each wire in the cable representing a different element of the cluster. On a block diagram, you can connect sub-terminals of a cluster only if the clusters have the same type, the same number of elements, and the same order of elements. When applied to clusters, polymorphism only requires that the clusters have the same order and the same number of elements.
Next, I will introduce the creation of clusters. The cluster creation box is located in the front panel under Controls → New → Arrays, Matrices and Clusters → Clusters, as shown in the figure:
Then you can add various types of controls to the cluster frame. For example, now you want to create a student record, including the student's name, student number, gender and age. This requires placing two string input controls, a numeric control and a Boolean control in the cluster shell in sequence. As shown in the figure:
Similar to the creation of arrays, clusters can also be created from the flowchart. First, place a cluster shell on the flowchart, and then place constants of various data types in the cluster shell. As shown in the figure:
The size of objects within a cluster can be adjusted. Right-click the cluster border and select various adjustment operations from the pop-up shortcut menu, as shown in the figure:
Select Adjust to Match Size to reduce the cluster border. The following figure shows the result after adjustment:
The arrangement of elements in a cluster structure is based on the order in which they are placed, which has nothing to do with the position of the elements in the cluster. The first element placed in a cluster is numbered 0, the second element is numbered 1, and so on. If an element is deleted, the numbers are automatically adjusted again. The order of clusters is very important, as it directly affects the port order of the "Bundle" and "Contact Bundle" functions that will be introduced later. If you want to connect a cluster to another cluster, the order and type of the two clusters must be the same.
If you want to change the order of elements in a cluster, you can right-click the border of the cluster structure and select "Reorder Controls in Cluster" in the pop-up shortcut menu, as shown in the figure:
At this time, the mouse will become a handle arrow with a "#" sign, the black frame indicates the newly set arrangement number, and the white frame indicates the original arrangement number. You can change the "Click to Set" content on the title bar, and then click the cluster element to set a new number. After setting, click the " " button on the toolbar to confirm the change. If you want to restore the original setting value, click " " to cancel the setting.
b) Cluster functions
The template of the cluster function is as follows:
The most important cluster functions are the "bundle" function that constructs a packed cluster, and the "unbundle" function that extracts elements from a cluster. They operate according to the order of cluster members, which also shows the importance of the order of members within the cluster.
Cluster function examples:
- Create a cluster, unpack the cluster, and pack the cluster again
The purpose of this example is to learn to use two basic functions of clusters, as shown in the figure: First, place a cluster shell on the front panel and change the label content to "Input Cluster"
In the cluster shell, put the string control "Name", the Boolean control "Sex", the numeric input control "Pay" and the string control "Address" in turn, and use these cluster elements to form the salary record of an employee in a company. As shown in the figure:
Switch to the flowchart and place an "Unbundle" cluster unpacking function. When the function is first placed, it has only two output ports on the right. When the input port is connected to the "Input Cluster" terminal, the right port will automatically increase to the number of cluster elements. The order of the ports from top to bottom corresponds to the order of placement of the elements in the cluster, and the data type also corresponds to the data type of the cluster element. As shown in the figure:
Similarly, place a "bundle" packed cluster function, use the positioning tool to increase the number of input ports to 4, and connect them to the 4 unpacked cluster elements in turn, indicating that they are packed again to generate a new cluster. Create a cluster display at the output port and change the label to "Output Cluster", as shown in the figure:
- Replacing a Cluster Member
The purpose of this example is to learn how to use the Bundle by Name function to replace certain elements within a cluster.
- Create a new VI, create a cluster shell on the front panel, and add a numeric input control, a Boolean control, and a string input control to the cluster, as shown in the figure:
- Open the flowchart and select the "Bundle by Name" function. Its function is to replace the value of the cluster member by name. When the function is first placed, it has only one input port on the left. After connecting the "Input Cluster" port of the function to the created cluster terminal, the left port will display the name and value of the first element in the cluster. Click it with the operation tool to select other cluster members. As shown in the figure:
- Create an input control on the front panel, change the label to "Enter a number", and connect it to the "Value" port in the flowchart to indicate that it will be used to replace the cluster element. As shown in the figure:
- Create an output cluster after the "Bundle by Name" function. Once completed, you can run the program, as shown in the figure:
- Plug and Play Cluster Array
The purpose of this example is to learn how to use the Index and Bundle Cluster Array function in conjunction with the Cluster Array function to create a cluster array.
- Create a new VI, open the block diagram, and place this function. When it is first placed, it has only one input port. Use the positioning tool to drag it to have three input ports.
- Place three array shells on the block diagram, then add string constants, numeric constants, and Boolean constants to create three arrays, as shown in the figure:
Then assign them the values shown in the figure, as shown in the figure:
Then connect the wires and create a display control, as shown in the figure:
Run, the result is as shown below:
Description: This function takes values from the three input arrays in sequence. The data with the same index value is gathered into a cluster, and all the clusters form a one-dimensional array. The length of the concatenated array is equal to the shortest one among all the input arrays, and the redundant data is discarded.
- Creating an array of arrays
This example seems to be impossible to implement, because in the study of arrays, we already know that the members of an array cannot be arrays. Here we will learn to treat a one-dimensional array as a cluster, and then create an array of clusters, because each member of a cluster array is a cluster (i.e. a one-dimensional array), thus achieving the purpose of creating an "array of arrays".
- First, create a new VI, open the flowchart, and place a "Create Cluster Array" function. The function of this function is to create an array of clusters. Each member of the cluster array is a cluster. When it is first placed in the flowchart, the function has only one input port. Use the positioning tool to drag its border so that it has three input ports.
- Create three numeric arrays on the program flowchart and assign values to them respectively. Set the length of the first and third arrays to 5, and the length of the second array to 4. Create a cluster display at the output port of the "Create Cluster Array" function and change the label content of the cluster display to "Array of Arrays", as shown in the figure:
- Run the program and you can see the results on the front panel, as shown in the figure:
Error Cluster
The Error cluster is a very important cluster. Many controls have two cluster ports, "Error In" and "Error Out". Generally speaking, when an error occurs in a VI and it cannot run, you can create a display control at the "Error Out" terminal of the error control, so that the program can continue to run. As shown in the figure, this is the Error cluster:
The more important application of the Error cluster is that it can control the order in which controls are executed, and can also control the termination of a loop through the Error cluster. As shown in the figure:
When an error occurs in the signal generation, the loop can be stopped.
Previous article:The main data storage methods of LabVIEW
Next article:Labview string and file I/O
Recommended ReadingLatest update time:2024-11-16 13:56
- Popular Resources
- Popular amplifiers
- Intelligent computing systems (Chen Yunji, Li Ling, Li Wei, Guo Qi, Du Zidong)
- 100 Examples of Microcontroller C Language Applications (with CD-ROM, 3rd Edition) (Wang Huiliang, Wang Dongfeng, Dong Guanqiang)
- Arduino Nano collects temperature and humidity data through LabVIEW and DHT11
- Modern Testing Technology and System Integration (Liu Junhua)
- Keysight Technologies Helps Samsung Electronics Successfully Validate FiRa® 2.0 Safe Distance Measurement Test Case
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Seizing the Opportunities in the Chinese Application Market: NI's Challenges and Answers
- Tektronix Launches Breakthrough Power Measurement Tools to Accelerate Innovation as Global Electrification Accelerates
- Not all oscilloscopes are created equal: Why ADCs and low noise floor matter
- Enable TekHSI high-speed interface function to accelerate the remote transmission of waveform data
- How to measure the quality of soft start thyristor
- How to use a multimeter to judge whether a soft starter is good or bad
- What are the advantages and disadvantages of non-contact temperature sensors?
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Review summary: Anxinke NB-IoT development board EC-01F-Kit
- Open Source Tutorial | Design of Smart Ecological Fish Tank
- Please tell me what type of inductor this is
- Feedback coefficient expression calculation
- I am a newcomer to the switching power supply industry and need to learn how to calculate the counter-transformer. Do you have any good experience or t...
- Elimination of low frequency signals
- Where can I find the German patent number?
- EK140 Burning Guide
- Two small questions about the lithium battery charging chip bq2407x
- Operating System Timeline and Family Tree