Local variables, global variables, and functional global variables

Publisher:一条属马的龙Latest update time:2015-08-04 Source: vihome Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Variables are used to store data and can be used for data sharing and exchange within a program or even between different programs. In LabVIEW, every time a local variable or global variable instance is created, it is a copy of the original data. That is to say, when too many local variables or global variables are used in a program, even if these variables are not written, LabVIEW will still occupy enough memory to create copies of these variables.
In fact, in the actual use of variables, programmers only use them to read and write a certain part of the memory space, and at the same time, only one section of program code will access the space represented by the variable (this process is very fast). Therefore, if a variable needs to be used in large quantities and repeatedly in a program, there is no need to use local variables and global variables. However, if only a small amount of data is exchanged or a control is assigned, local variables are still needed.

1.1 Local variables

Local variables in LabVIEW cannot exist alone in the program, they must be attached to a control (Control or Indicator). As shown in Figure 1, select Functions>>Programming>>Structures>>Local Variable in the function palette of LabVIEW. download

Local variables, global variables and functional global variables - statemice - Change



Local variables, global variables and functional global variables - statemice - Change



Local variables, global variables and functional global variables - statemice - Change



Local variables, global variables and functional global variables - statemice - Change



Local variables, global variables and functional global variables - statemice - Change








Local variables, global variables and functional global variables - statemice - Change



Local variables, global variables and functional global variables - statemice - Change







Local variables, global variables and functional global variables - statemice - Change








Local variables, global variables and functional global variables - statemice - Change
), the front panel of a new VI is shown in Figure 10, and the back panel is shown in Figure 11. The program uses a while loop that runs only once, in order to use a shift register to save the value of the variable. An enumeration control is used to represent the operation (read or write) of the global variable, and the corresponding instructions are responded to in different case structures. Figure 10 Front panel of functional global variable Figure 11 Back panel of functional global variable Create a new VI to call the above VI (called functional global variable), as shown in Figure 12, it can be seen that the correct value can be output. Figure 12 Use functional global variable Since each time the variable is read and written, it is taken from the shift register in the while loop, the problem of data copying can be avoided (of course, the global functional variable VI cannot be set to be reentrant and overloadable). Since the "error cluster" terminal is added to the functional global variable VI, the use of ErrorIn and ErrorOut can well avoid the "race risk" problem. In theory, functional global variables can completely replace traditional global variables. Due to the addition of "error cluster" and shift register, repeated copying of data is avoided. At the same time, the use of enumeration type controls (which can be set as Type Def. controls) can make the entire program structure clearer and more concise, thus achieving the purpose of modular program design.

Local variables, global variables and functional global variables - statemice - Change

Local variables, global variables and functional global variables - statemice - Change



Local variables, global variables and functional global variables - statemice - Change



Reference address:Local variables, global variables, and functional global variables

Previous article:Developing Custom LabVIEW Plug-ins
Next article:Use of Tree Control

Latest Test Measurement Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号