Quantcast
Channel: LabVIEW topics
Viewing all articles
Browse latest Browse all 69091

Why do LabVIEW Example Projects use Global Variables?

$
0
0

I'm puzzled.  I've been to enough talks by good LabVIEW programmers (including some who work for NI) and have come away with the impression that Global Variables should, in general, be avoided, with Functional Global Variables (a.k.a. VI Globals) usually preferred for "local memory".

 

I've been studying some of the Example Projects distributed with LabVIEW 2012 and 2013, in particular the Real-Time Acquisition project, and am struck by the use of Global Variables, where I would be inclined to use an FGV instead.  For examples, to stop all of the loops on the RT Target, the Global "All RT Loop Stop" is set; Configuration "constants" (such as TimeOuts, Network Streme names, Log Folder names) are kept as Globals; the Network Streme endpoints are saved in Globals.

 

[Note -- there's a funny spelling to the second word of Network Streme, above -- when I tried to post with the correct spelling, I got an error message saying that word is "not permitted in this community".  I apologize for the infraction, but I must confess I don't understand what is wrong with using the correct spelling of that word ...]

 

Why use Globals in these instances, instead of writing a bunch of VIGs to hold these data?  Note that almost all of these Globals are "Read Mainly" (written once when a resource is acquired, for example) or "Read Only" (treated as though they were a constant).  Indeed, the Read-Only variables could be written as a sub-VI with only an output terminal, acting as a (visible, because of the icon) Constant.

 

I can see some advantages to this latter approach.  For one, VIGs can have Error terminals, which enforce Data Flow (I just spotted a "data-flow" bug in some code I'm developing that is based on this Template, namely reading configuration data from an XML file into a Global and, in the same VI, wiring that Global to a "use-me" terminal, but with no guarantee that I'll read the Global after I write it).

 

There is, I suppose, an issue of "speed" -- perhaps Global Variables are "faster" than VIGs (particularly if the VIG "sits" on an Error Line).  My thought, though, is that this difference is likely to be trivial, particularly as these VIGs (or Globals) tend to get "occasional" calls (except for the "All Loop Stop" flag that gets called once per loop).

 

Are there other arguments or considerations that make a Global Variable a better choice than a VIG?  Is there a reason that the LabVIEW Developers put them in these Getting Started with LabVIEW Projects?

 

BS


Viewing all articles
Browse latest Browse all 69091

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>