LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to Set multiple Global Variables without using Controls or Indicators

I have to set many Global Variables (i.e. declare and initialize them) in a subVI in order to pass them to various other subVI's. The only way I know how to do it in LabView is to create a Globals.vi on which you create a control or indicator for EACH Global Variable. That's fine if you have only a few variables. But I have close to a hundred Global Variables (which come from a configuration file for a large program) and clearly it is impractical and cumbersome to create a control for each global variable. In Agilent Vee, there is a simple function called "Set Variable" that sets the data value of a global variable. Then in other module, you simply use the "Get Variable" function to get back the v
ariable and its value.

In LabView you can use the "Invoke Node / Set Control Value" and "Get Control Value" properties to achieve the same thing. But as mentioned above, you need to create a control for each global variable and that is a big pain in my case, with many global variables. Furthermore, the global variables are read from a Configuration Text File to this VI. Is there a way to do it without using the control? Thank you in advance for any help.
0 Kudos
Message 1 of 6
(4,150 Views)
Hundreds of globals? First of all, don't use globals, use functional globals; read about them on:

http://zone.ni.com/devzone/conceptd.nsf/webmain/82E60E34E609C22A862569F8007E3F4A?opendocument

One thing is determinism, functional globals also reduce the memory usa, and you can add more functionality to the global.

With that said, have you considered using a structure instead of individual variables; if you organize related variables in a cluster (or if they are of the same type; in an array...) you can simplify the code and read/write/preset all of them in one operation...

Mads
0 Kudos
Message 2 of 6
(4,150 Views)
In LabVIEW you can have constants on the diagram - no controls required. There are Boolean constants on the Boolean palette and a numeric constant on the Numeric Palette. You can change the representation of the numeric by right clicking on it and selecting representation. Another way to create constants is to right click on your global, VI input, or VI output, and select Create>Constant.
0 Kudos
Message 3 of 6
(4,150 Views)
Thanks for your answer but this question is not about creating constants. It is about creating a large number of global variables that can be passed to other VIs. The global variables, and their values, are read from a configuration text file into the VI. Thanks anyway.
0 Kudos
Message 4 of 6
(4,150 Views)
You could use the Configuration File as a global data storage that can be indexed with a string key. Instead of reading all keys to set the globals and then read the globals elsewhere in the app, just use Read Key with the key name when you need a global value. Make the Config file refnum global and few VIs that wrap the Read Key VI and convert to data. You would have then a kind of Set Variable and Get Variable.

Now I've suggested that only to show what is possible with LabVIEW when one have some imagination. Otherwise
if your global data is written once and read thereafter then the use of Global VI is justified and recommended (even with hundreds of them). To read and write the Global VI from/to ini file, use the Variant Config tool at http://OpenG
.org. There are VIs to read/write the whole front panel of the Global VI in a single VI call.


LabVIEW, C'est LabVIEW

0 Kudos
Message 5 of 6
(4,150 Views)
Actually you could create the same sort of facility in LV. All you have to do is create a LV2-style global that behaves as follows:

To write a value to it, you supply a value name and the value. These pieces of data are save internally in seperate arrays.

To read a value, you supply a value name. The VI looks up this name in the value name array to return an index into the value array. Output the value you find.

Frankly though, it sounds like what you really need is not hundreds of globals, but a good way to manage configuration data.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 6 of 6
(4,150 Views)