LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

global variables odd behaviour in projects

Hopefully someone out there has some insight into an odd problem I have come across with global variables and VIs in projects. The problem is somewhat tricky to contextualise so please bear with me while I attempt to explain it clearly.

 

I have written a number of VIs that act in a subordinate manner to some VIs that were supplied with an instrument that we purchased. The Manufactureres VIs can't really be played with, without fear of messing up the functionality of the instrument that they control. The manufacturers VIs contain global variables that provide system information. My VIs access these global variables and perform various functions when the right conditions are met. My VIs cannot influence the Manufacturers VIs, mine are merely watching the global variables (mainly arrays) for the right values. My VIs have been organised in a single project (in an attempt to keep things neat and ordered). This imperfect set-up was working fine until recently. So with the context provided, the problem:

 

It seems that if I launch my VIs through the project, the data from these global variables are coming back as null. If I find the VIs directly through the hard-disk folder structure and launch it, the globals are accessed fine and return the expected data. If I launch the VI through the project, close the VI (not project), then try to launch the VI from the hard-disk then it also does not work. Basically if the VI has been opened through the project and the project remains open then the VI will not work regardless of how I access it. If the project is open, and the VI not launched through it but through the hard-disk, then all is fine. I hope that is clear.

 

The set-up has been working fine for months. The only thing that might have changed things recently is that I have started looking into building executables (so that I don't have to give access to the VIs directly to our students) - the executable also gives the same problem. At the moment this is non-critical (as I can successfully run the VIs by launching from the hard-disk folder), but it would be nice to get to the bottom of it so that I can create executables without this issue.

 

I anyone out there has any thoughts, they would be most welcome.

 

0 Kudos
Message 1 of 21
(3,295 Views)

Although didnt read the question but I also faced same problem earlier. Replace global with local. This solved mine

--------------------------------------------------------------------------------------------------------
Kudos are always welcome if you got solution to some extent.

I need my difficulties because they are necessary to enjoy my success.
--Ranjeet
0 Kudos
Message 2 of 21
(3,287 Views)

Even though it's called global variable, these are only valid within a certain scope or context. You can have 2 instances of the same global variable, once within the project, once outside, and they don't interfere with each other, they are running in independent application scopes and thus have independent values.

So you always have to be careful in which context you use global variables and run your VIs.

Either have the manufacturer VIs run within the context of your project as well (recommended) or have everything running in the Main application instance. Btw, in the lower left corner of a VI you can switch the context it runs in (unless it is in the main application instance).

 

0 Kudos
Message 3 of 21
(3,277 Views)

Thanks for the advice Ranjeet, but I'm a little confused. As I explained the globals are part of a software suite that I have little ability to control - they are not part of my VIs. Given this, I thought that I couldn't change the globals to locals (as far as my understanding goes locals have to be defined within your VI). If I have misunderstood please let me know. Thanks again for your input.

0 Kudos
Message 4 of 21
(3,276 Views)

Thanks Dan. That seems to explain where the problem is rooted. I guess I'll have to think about what the most practical solution will be - I can't run the Manufacturer's VIs under my project, but I could potentially move mine out of it's project and into their structure (it's a mess of projects, libraries and random files), somewhere.

0 Kudos
Message 5 of 21
(3,271 Views)

What you could try is to access the gloabal variable through VI server. Open an application reference to the manufacturer project and access the global variable through this.

 

 

0 Kudos
Message 6 of 21
(3,264 Views)

No What I mean is where you writing to global variable there you update local variable and use to all the subVIs

--------------------------------------------------------------------------------------------------------
Kudos are always welcome if you got solution to some extent.

I need my difficulties because they are necessary to enjoy my success.
--Ranjeet
0 Kudos
Message 7 of 21
(3,260 Views)

@p.desai wrote:

I can't run the Manufacturer's VIs under my project


Why not?  You can run multiple VIs in the same project.  And they will all have the same application context as well.

 

What are you going to do when you build this project into an executable?  Are you going to have a single EXE or multiple?  If you have to use multiple, then global variables won't work.


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
0 Kudos
Message 8 of 21
(3,257 Views)

@Ranjeet_Singh wrote:

Although didnt read the question but I also faced same problem earlier. Replace global with local. This solved mine


Although I didn't read your response, I'm sure you're wrong.

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

Message 9 of 21
(3,237 Views)

A local variable is called "local" because its scope is local to the vi that it is in, and it is directly connected to a control/indicator in that vi. It won't work with sub-vi's or more importantly, vi's running in parallel to the vi they exist in.

Putnam
Certified LabVIEW Developer

Senior Test Engineer North Shore Technology, Inc.
Currently using LV 2012-LabVIEW 2018, RT8.5


LabVIEW Champion



0 Kudos
Message 10 of 21
(3,232 Views)