Functional Global Variable reference

Hi all

I want to update the value of the indicator element in primary VI, I don't want to use the global variable, due to the problem of race condition. So I create a functional global variable to control reference. It is reliable and can avoid the race condition critical?

I have attached two Test VI.

Thanks for your advice.

Personally, I use user events to send data to the main VI and then he can update the indicator.  This generally works very well since most GUI screws using a Structure of the event anyway.

Tags: NI Software

Similar Questions

  • Functional Global Variables: an indicator can be used instead of a shift register?

    It is a simple question, but I can't find an answer to it. The model agreed to a functional Global Variable is to use an uninitialized as in this example shift register:

    ('Référence IN' and ' Reference to "is actually a pile of references.) There is also a "Se Refnum" case, which comes the straight through the tunnels shift register.

    My question is, why can't we do store the indicator data? It is much simpler to use a shift register (IMHO a non obvious way to store global data!):

    The case "Se Refnum" does absolutely nothing. Other functions such as erasure of data can be implemented just as easily. The advantage of the FGV to help avoid race conditions is maintained because you always use the VI to access the data.

    JonP says:


    Not so much, the Inidicator can happily live outside the case structure, together and Clear would be just assign different values.

    If you have only a case structure, the indicator could not live outside of it.  In order to maintain the indicator data, your design requires that it is not written in for a case of Get.  If you have an exterior structure deal that decides on 'Get' or 'set or clear' and (in the case of "Set or clear") contains the terminal of the indicator and a classiquee case that decides on 'Set' or 'clear '.  However, I would consider this a design below using the standard template of the FGV.

    The difficulty with retrieving the value if you want to do a read operation / writing change. But LV provides many ways to retrieve data from an indicator (one you don't mention is the 'Value' property), do you mean that's all "incorrect"?

    Yes (I mean that they are all incorrect).

    You could hack your way around the design to work with a single structure of matter and the terminal of the indicator being outside using a method to read the value of the indicator and through a tunnel to the structure of the case through wiring for the tunnel of writing indicator in the case of 'Get '.  However, who will require a local Variable or value of property node.  As I said, these (I only mentioned the local Variable originally) are not good choices for performance and scalability.  If you are not aware of the functional differences between the terminals, local Variables and nodes of property value, refer to this article (obviously advantages/disadvantages such as redraw objects on the front panel are not relevant here).

    I guess you could say that indicators should only be written, but it is difficult to be pure!

    No, it's not, just use the classic design of the FGV!

  • Impossible to go from baseline of connection via functional Global Variable

    Hello

    I'm working on a project of producer/consumer based, which some parties have access to a MySQL database. After the connection to the database, I want to store the reference to the connection inside of a functional global variable. Then other parts of the project that need to use it can only read in the functional global variable.

    For some reason, the reference of the connection is not valid once it has been read functional global variable. It works fine if I have the reference directly from the connection to the request for enforcement VI wiring.

    I have attached a few screws that show the problem, but you will not be able to run them unless you have a database to connect to and hack you the query a little so he selects in your tables.

    SQL_whole_thing works very well. It connects to the database, returns information he requested by the query, and then disconnects. No problem.

    But if I run DB_Connect.vi (which stores the reference to 'DatabaseID_FGV' FGV), follow-up of SQL_Query.vi (which reads to the FGV reference), then I get an error saying that the reference is not valid.

    Anyone has an idea why this happens?

    Thank you

    Christian.

    PS: You'll need DBID_FGVActions.ctl and database_connectioninfo.ctl, also attached

    Your referance on the SR's "outdated" when implementing this way.  Essentially, this means that data in memory to this referance has changed because the referance was stored.  Just because you have changed the data at this location.  This prevents you from spend a refeance for the "old data" and crashing the calling application since the referance Rassi contains assumptions that are more adequate data.

    Consider upgrading this FGV powered Action.  This would be encapulate all the Actions you want to do to the database (connect, disconnect, fecth, writing etc.) and maintain the current referance on the AEs shift register.  Ben establishes a great deal for just this type of functional encapsulation in his famous nugget.  A must read for every programmer

  • Functional global variables with polymorphic VI

    Hello

    I am keen to build a functional global variable in a polymorphic VI. So, for example in a functional global variable, we have case structure. I want to build separate VI for the structure of the case and make a polymorphic VI.

    Is it possible that I could use a polymorphic VI rather than business structures?

    Thank you!

    You could create a polymorphic VI that serves as a wrapper for the FGV.  The idea is that each instance of the polymorphic VI called FGV with selected appropriate case-sensitive.  Then your API is the polymorphic VI instead of FGV.

  • Functional global variable pending

    Hi all

    I understand, by threads of reading on the forum, that a call to a functional Global Variable will block its execution if the FGV is already consulted one another VI, correct? Is there another way that it would block, apart from those shown?

    The reason for the question is that I have a (non-reentrant) FGV which is read by 8 subVIs simultaneously (they are, in fact, the same vi, but configured for returning) and whose time strangely, access varies based on the number of the subvis running.

    In less than 5 screws are trying to access the FGV, execution is blocked (I guess, because when the FGV is disabled and replaced by a constant there is no problem with running) and access lasts less than 50ms. If this number is between 5 and 8, execution is carried out much faster. My first assumption was that FGV has not been initiated until we call the fifth sub - VI, but I don't know how to check that.

    I can understand that there is something wrong with the FGV, but can't put my finger on. Any ideas?

    Thanks in advance for any help.


  • Functional global variable home (RFGV) is cut off by the controls on the front panel

    Hello

    I though that I had found the ultimate way to dynamically manage memory in a system of Exchange. I read on RFGV here: http://labviewwiki.org/Functional_global_variable and put together a static FGV normal to follow the references for each created instance of memory which I then could easily remember just by name. But now I found that all the RFGV completely stops whenever a front panel with a menu control is used, i.e. 'enum', 'ring' or 'control path. I tried to put in different delivery systems, but not luck. I read about that guy who could have fallen into the same problem: http://forums.ni.com/t5/LabVIEW/Do-I-need-to-use-a-semaphore-when-reading-writing-a-functional/m-p/1... but he got no help what I could see.

    I have not tried semaphores. Don't know what that is. Check my little test code and tell me what I am doing wrong. Or maybe there is no solution in this case I have to abandon the idea of the use of RFGV for anything. Maybe memory held all the VI will be assigned statically.

    Run the code (in LV2009) and watch the 6 LEDS Flash. Then click on anyone of 'enum', 'ring' or 'path' (the file dialog box) and watch off LED when dynamic memory is used to write or read while the continoues to static VI.

    Any suggestions?

    Best regards

    Kai

    If the memories are good, what you're running against is not the user interface thread, but an internal mechanism of LV called the loop of the root, which must run in some things. Specifically, in your case, the method run a VI and showing a menu (a menu real, or a context menu of a ring).

    You can work around this problem (and greatly simplify your code) If you use the call node of the reference instead of the method to execute a VI, but I wouldn't recommend it anyway, since I assume that your code is not what you think it does. In LV memory management can be quite complex if you want to be able to control it, so if you feel you really need, I suggest to start by searching for existing materials on the management of memory in LV

  • global variable functional to read and write data from and to the parallel loops

    Hello!

    Here is the following situation: I have 3 parallel while loops. I have the fire at the same time. The first loop reads the data from GPIB instruments. Second readers PID powered analog output card (software waveform static timed, cc. Update 3 seconds interval) with DAQmx features. The third argument stores the data in the case of certain conditions to the PDM file.

    I create a functional global variable (FGV) with write and read options containing the measured data (30 double CC in cluster). So when I get a new reading of the GPIB loop, I put the new values in the FGV.

    In parallel loops, I read the FGV when necessary. I know that, I just create a race condition, because when one of the loops reads or writes data in the FGV, no other loops can access, while they hold their race until the loop of winner completed his reading or writing on it.

    In my case, it is not a problem of losing data measured, and also a few short drapes in some loops are okey. (data measured, including the temperature values, used in the loop of PID and the loop to save file, the system also has constants for a significant period, is not a problem if the PID loop reads sometimes on values previous to the FGV in case if he won the race)

    What is a "barbarian way" to make such a code? (later, I want to give a good GUI to my code, so probably I would have to use some sort of event management,...)

    If you recommend something more elegant, please give me some links where I can learn more.

    I started to read and learn to try to expand my little knowledge in LabView, but to me, it seems I can find examples really pro and documents (http://expressionflow.com/2007/10/01/labview-queued-state-machine-architecture/ , http://forums.ni.com/t5/LabVIEW/Community-Nugget-2009-03-13-An-Event-based-messageing-framework/m-p/... ) and really simple, but not in the "middle range". This forum and other sources of NEITHER are really good, but I want to swim in a huge "info-ocean", without guidance...

    I'm after course 1 Core and Core 2, do you know that some free educational material that is based on these? (to say something 'intermediary'...)

    Thank you very much!

    I would use queues instead of a FGV in this particular case.

    A driving force that would provide a signal saying that the data is ready, you can change your FGV readme...  And maybe have an array of clusters to hold values more waiting to be read, etc...  Things get complicated...

    A queue however will do nicely.  You may have an understanding of producer/consumer.  You will need to do maybe not this 3rd loop.  If install you a state machine, which has (among other States): wait for the data (that is where the queue is read), writing to a file, disk PID.

    Your state of inactivity would be the "waiting for data".

    The PID is dependent on the data?  Otherwise it must operate its own, and Yes, you may have a loop for it.  Should run at a different rate from the loop reading data, you may have a different queue or other means for transmitting data to this loop.

    Another tip would be to define the State of PID as the default state and check for new data at regular intervals, thus reducing to 2 loops (producer / consumer).  The new data would be shared on the wires using a shift register.

    There are many tricks.  However, I would not recommend using a basic FGV as your solution.  An Action Engine, would be okay if it includes a mechanism to flag what data has been read (ie index, etc) or once the data has been read, it is deleted from the AE. 

    There are many ways to implement a solution, you just have to pick the right one that will avoid loosing data.

  • How to create a Global Variable through the Project Explorer

    Hello world!

    I know how to create a global variable (in a vi through the range of functions...).

    but I'm missing a way to create one via the Project Explorer.

    It's a missing feature or just this documentation (and the intuition of myself) are missing?

    It would be very convenient.

    THX for your time and hope that answers.

    jwscs

    Right click on my computer > new > new... > select Global Variable.

    EDIT: although I agree with Gerd (he probably wondering why you need so we can recommend a better way ), I rarely use them in easy to write once - read many applications such as security levels overall program at initialization (VER) to read later, but NOT modified.  I know it would be better to make a good class, functional Global Variable (FGV) or a motor Action (AE) but globals ARE practical and safe IF used wisely.

  • 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).

  • Global variable generatning Ref script

    Hi all!

    I want to create a script for:
    -create a new vi (its OK)

    -create a global variable reference to a global variable of vi-s exist. -J' I need some help for this.

    I think I need to load the global_variables_vi to the new vi and look for the variables and then create them.

    pls help

    Rather than specify the style (Global Variable), specify the path to the globa. VI.

  • static reference with the global variable

    Hi, I used a static reference to a Subvi where I change a global variable before (3-4 years ago) and do not remember how I did it.

    It was something like these attachments, but now I'm using LabView 2013 instead of LV 8.6.

    The change in the overall operating system sees only not in the main vi (looks like the invoke node run vi does not work with globals).

    In addition the vi close with the invoke node close vi but not if I put the custom in the Subvi properties to automatically close.

    dkfire wrote:

    Why not call the sub vi as usual, just with the setting to display the front panel, when it is called?

    Use the connector pane to transfer the value of the sub vi Ok button when done.

    That's what I recommend.  If this is not possible for some reason, then you will need to use a flat Structure of the sequence to force the reading of the global variable after the Subvi is complete.

  • How to change a global variable in a function?

    Hello

    I want to change a globalvariable in a function, as a first step I made in this way:

    class Global_output_class
    
    GlobalDim("Correlation_Status,fail_part,End_Exp")
    dim pouet
    
    Correlation_Status = 12
    Call Correlation()
    pouet = Correlation_Status
    
    Function Correlation()
      Dim Global_output_class_sub
      Set Global_output_class_sub = new Global_output_class
    
      Correlation_Status = 1
      fail_part = 2
      End_Exp = 3
    
      Global_output_class_sub.CorrelationStatus = Correlation_Status
      Global_output_class_sub.failpart = fail_part
      Global_output_class_sub.EndExp = End_Exp
      set Correlation = Global_output_class_sub
    End function
    

    In this case: correlation_status receives a value of 12, then I go to my correlationn() function where it became 1

    Then he comes out of the Sub-function and takes the previous value of the program (12) (I hate that)

    To solve the problem I did it this way:

    class Global_output_class
    public CorrelationStatus
    public failpart
    public EndExp
    end class 
    
    GlobalDim("Correlation_Status,fail_part,End_Exp")
    
    Correlation_Status = 12
    Set Global_Output = Correlation()
    Correlation_Status = Global_Output.CorrelationStatus
    fail_part = Global_Output.failpart
    End_Exp = Global_Output.EndExp
    pouet = Correlation_Status
    
    Function Correlation()
      Dim Global_output_class_sub
      Set Global_output_class_sub = new Global_output_class
    
      Correlation_Status = 1
      fail_part = 2
      End_Exp = 3
    
      Global_output_class_sub.CorrelationStatus = Correlation_Status
      Global_output_class_sub.failpart = fail_part
      Global_output_class_sub.EndExp = End_Exp
      set Correlation = Global_output_class_sub
    End function
    

    This way my global value are copied in themselves after leaving the subprogramme

    I had a lot of variables, is there an easier way for the global variable in a function of change keep the value after you leave the service?

    Thanks for the help,

    Fred

    Hi Fred,.

    It is possible to use a global variable defined, but the best way is to use a function call (or procedure call) with parameters. Please first find the right solution for a function call with parameter and the suboptimal way with a comprehensive valiable:

    dim oParameter
    set oParameter = new cGlobal_output_class
    
    oParameter.Correlation_Status = 12
    
    msgbox "Correlation_Status before Call Correlation: " & oParameter.Correlation_Status
    Call Correlation(oParameter)
    msgbox "Correlation_Status after Call Correlation: " & oParameter.Correlation_Status
    
    '-------------------------------------------------------------------------------
    Function Correlation(oPara)
      msgbox "Correlation_Status in the FUNCTION before change: " & oPara.Correlation_Status
      oPara.Correlation_Status = 1
      oPara.fail_part = 2
      oPara.End_Exp = 3
      msgbox "Correlation_Status in the FUNCTION after change: " & oPara.Correlation_Status
    End function
    
    '-------------------------------------------------------------------------------
    class cGlobal_output_class
      dim Correlation_Status,fail_part,End_Exp
    end class
    
    call GlobalDim("oPouet")
    
    dim oPouet
    set oPouet = new cGlobal_output_class
    
    oPouet.Correlation_Status = 12
    
    msgbox "Correlation_Status before Call Correlation: " & oPouet.Correlation_Status
    Call Correlation()
    msgbox "Correlation_Status before Call Correlation: " & oPouet.Correlation_Status
    
    '-------------------------------------------------------------------------------
    Function Correlation()
      msgbox "Correlation_Status in the FUNCTION before change: " & oPouet.Correlation_Status
      oPouet.Correlation_Status = 1
      oPouet.fail_part = 2
      oPouet.End_Exp = 3
      msgbox "Correlation_Status in the FUNCTION after change: " & oPouet.Correlation_Status
    End function
    
    '-------------------------------------------------------------------------------
    class cGlobal_output_class
      dim Correlation_Status,fail_part,End_Exp
    end class
    

    Greetings

    Walter

  • Global Variables are preferable to the Globals functional - so there! :-)

    I feel a little controversial today so forgive the brutal title of this post

    I've never used global variables because I was under the misconception that they are somehow 'bad '. That's all I've heard since I started learning the LabVIEW. Review the code in the nets upconvert and downconvert. The ugliest code uses globals and some of the most beautiful code does not work. This means that bad programmers use global variables and globals are so bad programming practice. This is not true. Globals are just easy to use for newbies to use them. ' Not initialized what? I can't find those on the pallette? »

    I think I always wondered unconsciously that globals are bad. They are not bad, it is their use that may be bad. This is true for anything in life.

    The first and the most obvious problem with global variables is racing conditions. But this is not strictly the overall causing the race condition. This is the data stream is not defined.

    But the same is true if functional a global being misused. In the example below there is nothing to enforce data streams.

    You must run the data flow with a thread of error for example.

    Globals do not have a thread of error but not fear - the man of the sequence is here!

    You only need the sequence if the global is directly on your drawing. These two structures of single image sequence could be replaced by a NumericWrite.vi and a NumericRead.vi containing nothing but overall, a command or the indicator respectively and the terminals of the error. Put it online and it is good as gold. Or you might have a Subvi containing nothing but a frame two cases selected by an enumeration containing the elements 'Get' and 'Set '. Now, it looks like a duck and quacks like a duck. Don't you worry by the overhead of the structure of the case either. If the enum is a constant, it will be unfolded.

    Another problem with globals, it's that they are, well, global. Is not different from a functional overall, so it isn't really a problem anyway. Globals and globals functional it is easily taken by placing them in a library and define the scope of the access. Not to mention that libraries give you namespaces and "namespaces are one honking great idea - do several of these!" *

    The real reason to use a global rather than a functional overall is that they are about twice as fast.

    Until this morning I would have recommended to use a more functional global overall. But I changed my mind. Someone can it change back?

    * The Zen of Python


  • Multiple copies of the functional global using vi references

    I have several producers acquisition in a global operation (a functional overall by the producer). These functional overall are identical except for the name. He would work to have only one functional global VI and get a separate reference for each producer? The corresponding consumer would have also used the appropriate reference to consume the data.

    The functional global contains an array of data that must be analyzed by the consumer. It is possible that the data table does not contain a complete set of data on a unique "store" by the producer operation. Of course, the consumer, is written to search for a complete data record before completing the processing of the file.

    Les__Bartel wrote:

    TST wrote:

    No matter that there is a better way, the answer to the question is Yes. The FGV must be reentrant and the reference you open must be re-entrant too and then you can use the CBR node to run the specific copy of the FGV.

    I thought that a reentrant vi would not maintain the State of the shift register not initialized by one call to the other.

    A reentrant VI will maintain the State of its shift uninitialized registers.  However, you must be very careful, how to do this.  You first need to make sure that it is set to allocate Clones.  What will happen in this situation, it is that each different place call you this sub - VI each will be a different clone.  This means that each call will have its own data.  The problem with this is that you cannot share the data between multiple instances and therefore multiple loops.  If you don't believe me, go play with mean it Point by Point VI.

    So what happens if you assign shared clones?  A big freakin mess '.  You will have no control over which clone called where, and there will be a major data corruption.

    This is why FGVs are almost always not reentrant.

  • Global variable problem using as reference file

    Hi all

    This code is trivial, but illustrates the problem that I have.  I want to open a file with vi a, dynamically open vi B, pass the reference file in vi B, vi B to close, and then close the fiel with A vi.  VI B is designed for SAMPLES continuously and add it to the file.  Unfortunately I can't implement this solution because it seems that global variables do not work for the file references (!).  Thank you!

    You have a race condition in this image.  The global variable refnum to could be read the file write before the opened file has been fortunate to write a valid file for the other reference copy refnum of global variable.  You should have a thread open to write it directly.  If you want to store it in the global variable as well, then branching off there this direct wiring.

Maybe you are looking for

  • move the subscription / phone number to a different account/Skype-name

    Hello I have 2 Skype numbers connected to my account. It's not optimal because I wish to convey two different mobile numbers and this is not possible. If I want to spend a number of a new Skype account, which will result in 2 different account, each

  • Equium P200 built in camera does not work

    Hello I just bought this laptop with Vista. What I've noticed, is: construction has closed without driver and software, I do not see everything on the toshiba site.Has anyone else had this problem and can anyone give some advice where to find drivers

  • Satellite A350 - webcam always shows black screen

    Hi folks - I know there were a lot of messages on the web cam works do not. I reinstalled the driver several times, I've adjusted and readjust the settings but the webcam still shows a black screen. If I try to record video - I get a failure to rende

  • I forgot the password (model) in my hp slate tablet 7

    How do I open or reuse my tablet. My son put a pattenr on it. then he forgot the model and click the 'forgotten password' option. then on the screen it displays "enter the email address and password. so I type my email add and password, but it diddnt

  • Suspicious activity of router, pirate bank account. Can you help me?

    My bank account hacked, and apparently it happened yesterday. It is that there are several purchases using steam (a PC game platform), and that my credit card has been used and so assume that my credit card information has been stolen, or that someon