Why LabVIEW example projects using Global Variables?

I'm puzzled.  I've been pretty good programmers LabVIEW talks (including some who work for the OR) and came away with the impression that Global Variables should, as a general rule, be avoided, with functional Global Variables (alias VI Globals) generally preferred for "local memory".

I have studied some of the example distributed with LabVIEW, 2012 and 2013, in particular the proposed acquisition in real time and am struck by the use of Global Variables, where I'd be inclined to use instead a FGV.  For examples, to stop all the loops on the RT target, the overall "All the RT loop Stop" is defined; 'Constants' of configuration (such as timeouts, Streme network names, the names of the journal folder) are kept as Globals; Streme network endpoints are stored in Globals.

[Note - there is a weird spelling of the second word of the network Streme, above - when I tried to post with the correct spelling, I got an error message saying this word is 'not allowed in this community".]  I apologize for the offense, but I must confess that I do not understand what the problem with the help of the spelling of this word...]

Why use Globals in these cases, rather than write a bunch of VIGs to hold these data?  Note that almost all these Globals are 'Read' essentially (written once when a resource is acquired, for example) or "Read Only" (treated as if they were a constant).  Indeed, read-only variables can be written as a Subvi with only an output terminal, acting as a (visible, due to the icon) constant.

I can see advantages to this approach.  On the one hand, VIGs can have error bounds who run the data flow (I just spotted a bug "data flow" in code, I am developing that is based on this model, to read configuration data to an XML file in a world and in the same VI, Global wiring to a "use - me" terminal, but with no guarantee that I'll read the overall after I write it).

It is, I suppose, a matter of 'speed' - perhaps Global Variables are 'faster' than VIGs (especially if the VIG 'sits' on an error line).  My thought, however, is that this difference is likely to be trivial, especially as these VIGs (or Globals) tend to become "occasional" calls (with the exception of the indicator 'all the loop Stop' which is called once per line).

Are there other arguments or considerations that make a Variable global to a better choice than a VIG?  Is there a reason that LabVIEW developers put in these start-up of projects LabVIEW?

BS

I have to ask, how do you use functional Global Variables?  Like just a Get and Set?  If so, you can use a global variable.

Yes, globals are faster and use much less overhead.  At the summits of CLA in recent years, we talked about using globals.  The most common use is for Write-Once-Read Many and writing-never-Read Many with configuration data.  It's a good idea to use globals with the constants that can change on you.  It turns out that the world will have the same performance as a constant in this case.  This is done so that you don't have 1 place to edit the 'constant '.

The rule on "Globals are evil" actually goes back several years when NEITHER had the huge "people of the country are bad" vendata.  But NEITHER explains well how to do things properly.  So I found people, instead of using local variables, using the value property node.  It's even worse because the property causes thread swaps and kills your performance.  It wasn't until I shouted to people to use wires and shift registers I have seen improvements in the way in which people wrote their code.  So people are always riffling in the use of globals and decided to use FGVs with the EEG and fixed rather cases.  But this does not solve the problem of the conditions of race with critical data and you cause an additional burden.

So from my experience, I use globals all the time for configuration data.  Yes, you must be careful about the race conditions.  But as long as you understand that it is a common and useful practice.

I would not use a global variable for data that are constantly changing (use registers to offset or Action motor) and/or processes that have critical sections of code (use a motor of Action).

NOTE: I use the definition of Mercer to FGV (a Get/Set only) and motor Action (many cases which specifically affect the data).

Tags: NI Software

Similar Questions

  • Using global variables in a device custom

    Hello world

    I have problems with the passing of data through my device customized using global variables. I want to allow a user to select a RIO device address when you set up the system definition file. This is recorded in a global variable using the hand Page VI. I would later use this RIO device address in RT driver to deploy a bitfile. I can hard-code, but it is much more convenient to use a global.

    When I try to store the address of the global variable, it updates the value temporarily (I confirmed that the structure of the event recognizes the change of value). When I click the node of the tree to define system linked to the Main Page VI and then click on it again, the hand Page VI runs again. I wrote the code to repopulate the address of device of RIO with the last value stored in the global variable, but it is empty. I've included the VI global variables in my build, so I can't imagine why it can reset this value.

    Any help would be appreciated!

    Thank you

    Mitch

    Have you tried to use the custom device properties to store this value instead of GVs?

    Configuration VI, you can set this property, and if I'm not mistaken, you can read these properties on the RT driver.

  • Using global variables

    Dear all.

    I created a global variable in the Init as an attachment.

    variables.JPG

    --------------------------------- Code ---------------------------------

    var total = 0;

    .

    .

    .

    .

    function Xxx() {}

    Total = total + 10

    App.Alert (total);     = > 10

    }

    ---------------------------------------------------------------------------

    When I call Xxx(), alert to function Xxx() 10;

    in the click event of the button on the next page, I tried to call total variable (global variable).

    --------------------------------- Code ---------------------------------

    App.Alert (total);       = > error?

    App.Alert (init.total);  = > 0

    ---------------------------------------------------------------------------

    How can I use global variable?

    To get the value of the Init variable, you would use Init.value

    Paul

  • Why the continuous measurement and Logging in LabVIEW 2012 Project uses strings instead of Enums and orders from the queue?

    Hello!

    I noticed that the continuous measurement and a project in LabVIEW 2012 Logging using chains instead of enums and orders from the queue. I wonder if there is a good reason for it?

    Kind regards

    Anguel

    First, string vs enum debate is probably the version of LabVIEW vim vs emacs. There are good arguments on both sides, and I doubt that there is always a "winner".

    A brief summary of our reasoning for the current state of the project examples:

    1. We used enums for the state machine because it is self-contained. A state machine will never tell himself to enter a State, he does not know. Knowing (as the programmer) all possible States with the help of an enum allows you to enlist the compiler in order to help us avoid mistakes to change the time (because you can't quite out an enum and LabVIEW can be said if you are not covering all cases to a structure of the case, etc..).

      Enums provide greater protection and rigidity by ensuring all withdrew at the time of publishing. This is often the 'default' recommendation that we do.

    2. We used strings for messages in queue manager because the producer of message and the message handler could be independent processes that are reused or traded. Channels avoid the need for the compiler to be able to connect the orders and push this responsibility to the programmer. This allows you to develop some sub-components independently as long as you agree to a series of channel commands that you can manage - you need not to share a file 'messages.ctl' or 'states.ctl '. It is conceivable a loop of message management a message it does not, how you can decide to either silently ignore it or will trigger an error (as we do in the model). The strings make it also easier if you want to swap the queues of LabVIEW outside by a TCP implementation for network vacilitate or intra-Processuse communication where the other end may or may not be written in LabVIEW.

      Channels to provide more flexibility (that is, you can add new commands to an existing via plugins system, you can pass parameters as part of the string, etc.) at the expense of pushing her potential errors at run time and to put more responsibility on the programmer.

    3. The actor's gifts frame a 3rd option - using classes such as messages. For me, it combines many of the advantages of these two enumerations (strictly typed, change errors) and strings (flexible and scalable), but with the disadvantage of being somewhat less transparent (you understand OO, be comfortable to navigate through a multitude of screws, legacy of understanding, etc.).

    I don't know there are other reasons, others to the breast OR had or seen as we validated models and examples of projects in-house, but here are my reasons. We know that we can not design for each situation there - our goal is to get useful models against new users to make them aware of what well thought LabVIEW programs are similar to experienced users know their applications better and I hope they do not hesitate to change what we provide or create their own designs, when they feel it's necessary. (On a side note, please share what you come up with - a community of experts sharing models would be really useful to us all LabVIEW users).

    Best regards

    Simon

  • Cannot use Global Variable in the Structure of the event

    I'm using LabVIEW 2009.

    In my LabView project, I have a global Boolean variable called EStop. I can read and write the global variable. If I double click on the global variable, it takes me to EStop.vi which includes a text button. EStop.vi is part of my project.

    In one of my report, I have a Structure of the event. If I go to one of the event handlers in this case Structure and right click and select Add event, I get a list of possible events. But this list does not EStop or an EStop events.

    I would like to add an event to EStop case: changed value.

    Why I can not add to a case of events events that include events on Global Variables as value changed?

    How can I add EStop: event changed my structure of the event value.


  • Using global variables in all scripts

    Hello

    I have a SOAP client which runs the runScript method.

    SOAP requests to three, one after the other, call runScript and run a jsx on the server.

    Can I have some session-level variables / global whereby I can access via scripts?

    For example, during the execution of the first script, I put a variable. And even once during the second and third queries SOAP, I use the variable (defined in the 1st script) in the 2nd and 3rd scripts.

    How can I get the above?

    I would really appreciate some help on this.

    You can use the #targetengine or insertLabel methods.

    Incapacitated, I would say, of #targetengine, "session01" is the specific session will be exist until InDesign is running, which is not desirable. Those who will destroy only when you exit your application. I don't think that there is no collection for rescue here.

    However, insertLabel and extractLabel can be used on specific DOM objects, according to your need, including the app object.

    If you want to share variables between scripts on a document so that you can store variables on the document object:

    doc.insertLabel ("name", "value");

    So, once the document is closed all the labels are gone. You can choose according to your requirement, you want application-level globals (then use app.insertLabel), level of the document (then doc.insertLabel), spread of level, etc.

  • Popup JavaScript does not work using global variables?

    I have a menu region "References" which contains links to several pages pop up indicating the access codes of valid data filtered for the location of the user. I tried to make this work in another page by changing the references page to global variables variables / application, but it does not work. Can anyone suggest a work around? Here is the code I use:

    Target URL in link
    javascript:callEmpPopup('P1050_ORG_ID')
    JavaScript
      function callMyPopup (formItem1,formRow1) {
        var formVal1 = document.getElementById(formItem1).value;
        var formVal2 = 1;
        var url;
      url = 'f?p=&APP_ID.:1056:&APP_SESSION.::::P1056_FACTORY_ID,P1056_ROW:' + formVal1 + ',' + formVal2;
      w = open(url,"winLov","Scrollbars=1,resizable=1,width=1000,height=600");
      if (w.opener == null)
      w.opener = self;
      w.focus();
      }

    Blair:

    Use a "Hidden" type page element defined on page 0 instead of a part of the application.

    CITY

  • How to use global variables from a dll in another (not multi-threaded)

    With LabWindows/CVI. I try to be compatible with legacy code, so this isn't the best way to do things, but it saves me some headaches.

    I have a project/.dll called "GlobalBlock" that contains some parameters used widely throughout the program. The entire program consists of several DLLs, for the purpose of encapsulation.

    GlobalBlock.c contains:

    menu_sdef G_setprefs = struct
    {
    ... stuff

    };

    sys_fileheader_sdef Level1Version = struct
    {
    ... more

    };

    struct G_sys_flags sys_flags_sdef;

    In the dll that owns the variable, use the _export on this qualifier. This will ensure that it is placed in the list of the interface dll. In the application (dll or other) that wants to make reference to that variable, use the qualifier _import on it. This tells the system to use the associated import library that comes with the dll in order to resolve references running.

    JR

  • Why can I not use the variable system building blocks in a user variable?

    Using FrameMaker 11... I would like to make a short variable which includes simply all year-round - not months, no date (e.g., "2016").  It is for a page of bibliographic information in my documents, which would also quickly forget.  I want to just make sure that the year on this page is current (and auto update, if necessary, when I build the book).

    I just had to re - PDF and re - publish a document for this reason (and our release process is anything but 'speedy').

    You can change the definition of one of the... Date system variables so that the year of release. For example, to change the definition of The Date of change (Short) in <$year>.

  • How can I create and use global variables in busy border?

    to preserve the previous value while being used between parent and child symbol?

    For some reason, you actually have to call the function inside of another symbol (and not the bodies as before). New version of the same exercise with the following structure where each rectangle and the associated text is encapsulated in an object symbol :

    To make the accessible service for another symbol, you add SYM (the parameter of substr() is also adapted to the new id)

    Stage.compositionReady event handler:

    Total = 0;

    //-----------------------------------------

    SymincrementByInstanceNum = function (eClick)

    {

    Console.log (eClick.target.getAttribute ("id"));

    => "Stage_object2_yellowRect2_RoundRect" for example

    var num = eClick.target.getAttribute("id").substr (12, 1);

    Total += parseInt (num);

    SYM. $("total") .html ('total' + total);

    }

    Each of the object.yellowRect.Click event handler becomes:

    sym.getComposition () .getStage ().incrementByInstanceNum (e);

    The link given above has been updated and now includes the second version.

    Gil

  • use global variables

    Hello

    I have 3 steps in my application. I opened the first step, enter some data and move on to the second stage. then I type in some other data and switch to the third stage. Now, I want to display the data of the first stage in the third phase.

    Of course I could pass the data through the second and third stage...

    Is there something like a varaible overall for the whole application, that I can use on each stage?

    Thanks hibbert

    There are several ways to do so. I personally find using a singleton class that contains the required state very useful more as a hub to send events around to have. You can do a quick search on the forum of samples.

  • Digital control system, using limits of entry of data with global variables

    Hello!

    I have a Subvi with several digital control sliders. These control framerate, the pixel clock and exposure of a camera and their change in max/min/increment whenever one of them is changed - they are interdependent and get their information from the camera continuously during execution.

    I'm trying to remote control this VI, but during the passage of a value using global variables, it doesn't "stick".

    Example:

    The value for exposure is 237,48 Ms. different values are constrained to the nearest value. So if I pick 240,00 ms at the Subvi, he should know that this is not a valid value and change to Mrs. 237,48.

    But it is not do and I don't know why. When I enter the values manually, it works fine.

    Any suggestions?

    The limits on the controls that apply when their control from the front and is not passing values via the connector pane.

    You should use something like "line and force" within the VI to validate the values are within the range (maybe constrain data or return an error).

  • Can I use the timestamp to a global variable that is published to network to reduce network traffic?

    I would use a couple of network-has published the global variables that will contain large groups of data.  I want to host them on a device, but read them in several - consider a distributed control system.  The data will be updated very rarely, but when that happens, I want that all my GUI to know quickly.  I have all the GUI, simply read data 4 x per second (which would be fast enough), but I was wondering if there is a more elegant solution (always using global variables).  If I read only the timestamp 4 x per second each of the HMI, compare to the last reading and then interrogate the integer variable if timestamps are different, which will require fewer resources that just enter the integer variable each time?  In other words, the read timestamp uses the same amount of resources as the reading of the entire variable?

    With really simple code, assuming that the cluster "Data" is big enough, made...

    .. .get me no benefit on...

    mark3545 wrote:

    Which means that they are already doing what I want anyway, no?  If the reader is updated when it changes the writer, I can survey as often I want without increased traffic, correct?

    That is right.

  • Singleton vs normal/global variable

    Hi just been looking intot he singleton pattern. WHY should I use this template to contain the variables accessible to other sovereign wealth funds throughout the project when I can just keep in the film container and access as you wish.

    Is there an advantage as optimization, security, usability etc...

    I'll post a question re: how to access a varibale in a mc parent except if answered here too as it is in the same category.

    It is better to go to a varibale in the parent uses

    1 MovieClip (parent.parent) .variableTargeted

    OR

    import com.parentAsDocument;

    Then navigate to the variable

    Thanks in advance

    (btw. I've never seen this in tutorials anywhere - and I've read for years - I missing something here or is - something advanced programmers don't know because they read advanced books?)

    If I need to use global variables - I'll probably use public static properties (variables) and methods in a special class that is designed to provide the values of these variables (or the features of the static methods) for the entire application. Any object making the reference to this class will be able to read/write these values.

    You are already familiar with static properties. For example when you add event listeners you write:

    mc.addEventListener (Event.ENTER_FRAME, handler);

    ENTER_FRAME is a static variable (and also a constant) which is accessible to ANY other object in the application around the WORLD.

    On the issue of container, I think you're talking about higher-level (timeline or document class) code. If my impressions are correct - no, I would never declare static properties or methods for the use of the application to scale. As I said, I would create a class special and this feature delegation to the and then tap other classes if necessary top.

    Frankly, I would never use timeline for anything unless someone puts a gun against my head (or hands a lot of money). In fact I avoid using IDE Flash quite like a plague. I mean that for one purpose - timeline coding is treacherous (and, oddly, more complicated than the use of the class) and encourage people is not to think of OBJECT-oriented way. The main disadvantage is that developers often assume that the chronology provides a kind of guarantees and the decorum and thus developers spend hurt little time thinking about the architecture of application in a more abstract way.

    I highly suggest if you consider excel programming skills to give up the chronology of coding as soon as possible (including the use of the Flash altogether) and move toward Flash Builder or any other environment. Benefits are awsome and you will never want to go back to the timeline.

    If you want to me - I'll give you a more concrete example of how I would approach implementation of the static aspects of the classes.

  • Problem of global variables

    I have subVI´s of multiples that send data to the VI main when are called using global variables. Then the main VI must send these data to an another subVI´s called by an another VI main to show in its facades. It works perfectly when all SIX are executed in the LabVIEW environment, but when it's in main VI´s generation aplication, it's as if the global variables do not work because the data are always zero... I can´t find the cause of the error, I checked the construction features and there is nothing about the global variables, only the VI that located them in the summary project dependencies.

    What could be the error?

    You can use shared variables, you cannot use global variables. Shared variables can be local (on a PC) or network.

Maybe you are looking for