LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use global variables in common VIs for multi projects?

Solved!
Go to solution

Hi,

I've developed a control application with a modular structure, where I need to use many subvi's in multiple projects. The subvi's themselves don't need to be altered between projects, but they do use refer to global variables that will need to change for each project. In effect the global variables are part of an individual project configuration, such as setpoints, so the subvi's need to refer to the same global variable name, but this must be located in a different file for each project. Is there any way that the references to the global variable can be made to be a project related reference, and not a file reference? Or is there any other way of organising subvi's for reuse that gets around this?

Many thanks for your help.

0 Kudos
Message 1 of 9
(4,184 Views)

Make whatever controls you have in your global into typedefs and put them in your universal subVI library.  Instead of having your subVIs depend on the global, just bring the data in, via the typedefs you just made.  Make master copy of the global in that same library for convenience.  Every time you make a new project, just make a copy of that global and place it in the new project.That way, each project can have it's own global, yet the subVIs remain independent.

 

You might consider placing all the controls in your global into one typedef'd cluster.  That way, if you ever need to change that global - and you probably will, at some point - make changes to that cluster and everyone gets updated.  The good thing is that everyone gets updated.  The bad thing is everyone gets updated.  The reason I say this is potentially bad is that if you make that change to the library, you will have to release a new version of every project that uses that library.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 2 of 9
(4,172 Views)

Hi Bill, Thanks very much for looking into my problem. However creating typedef does not solve the problem. The problem is labview creating conflict. Our global variable is in a while loop of subvi which is used for multiple projects, therefore we don't want to change the global variable name, but global's content is different for different projects. Labview does not use global vi in the particular project rather look for other places, causing conflict. I am sure this is not an uncommon problem. Can you suggest a way around the problem please? As we cannot bring data into while loop via wire, will queue be good way? Or using class structure? Would it be overkill? Thanks for your help.

0 Kudos
Message 3 of 9
(4,120 Views)
Solution
Accepted by topic author Noriker

A Class Structure is still just using a wire.  So OOP will not help the situation.

 

Alternatives to Global Variables include Action Engines, Notifiers, Data Value Reference (DVR).  The one you might want to look into (assuming LabVIEW 2016 or newer) is the Tag Channel.  Channels are a different way to use references (at least, that is how I view them).


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 4 of 9
(4,118 Views)

Thank you! I think FGV might work and will try it. I have never heard of tag channel but I'll have a go and let you know the outcome.

0 Kudos
Message 5 of 9
(4,110 Views)

@Noriker wrote:

Hi,

I've developed a control application with a modular structure, where I need to use many subvi's in multiple projects. The subvi's themselves don't need to be altered between projects, but they do use refer to global variables that will need to change for each project. In effect the global variables are part of an individual project configuration, such as setpoints, so the subvi's need to refer to the same global variable name, but this must be located in a different file for each project. Is there any way that the references to the global variable can be made to be a project related reference, and not a file reference? Or is there any other way of organising subvi's for reuse that gets around this?

Many thanks for your help.


Really, the only way I see this happening is by decoupling the global from the subVI.  It shouldn't be that difficult to convert the subVI from using the global directly to having a terminal with a cluster with the same data structure as the global.  (And that's where the typedef comes in.  As the global changes, the clusters automatically adapt.)

 

Because the subVI now accepts data from a control hooked to the connector pane instead of directly from the global, it can accept data from anything - including a local copy of the "template" global.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 6 of 9
(4,100 Views)

Hi, functional global variable works best for our application. Thank you very much for your advice. I would like to accept your comments as a solution, but I cannot find the way to do it. 

0 Kudos
Message 7 of 9
(4,065 Views)

Hi Noriker, how exactly did you realize this with the FGV? The goal was to call up different paths for configuration files depending on the Project?

 

Many thanks for your help.

0 Kudos
Message 8 of 9
(3,957 Views)

Hi, FGV is a vi and contains no value, therefore it won't cause conflict included in different projects. Project specific values are treated as input/output of FGV (ie write/read). We actually used CVT table. Hope this helps.

0 Kudos
Message 9 of 9
(3,928 Views)