LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to confirm that global variables are resident in memory before using

When I start my application the global.vi variables don't appear to be set prior to use.  If I stop the application and then restart, the variables are present. Is there anyway to ensure the variables are in memory prior to use?
 
Thanks,
Mike
0 Kudos
Message 1 of 8
(4,011 Views)
Hello Mike, I think that the only solution is to put a custom InitializeMyGlobals.vi  (or an equivalent code block) at the very beginning of your main.
This vi or block must execute before everything else could use the global variables. Of course this is not needed if the application is compiled to an exe.

Paolo

Message Edited by pincpanter on 07-20-2005 05:27 PM

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 2 of 8
(4,003 Views)

The globals will be in memory if they are in your calling programs, as long as LabVIEW isn't shutdown. The first time the program is run, after loading from disk, the global's values will be whatever they were set to as a default when they were last saved to disk. When you have run the program and stopped it, they will then retain the values they acquired during the run, as long as you don't close out LabVIEW, but they won't retain these values for the next "new" run (after closing LabVIEW) unless you specifically go to the global's vi, do a "set current values as default", then save the changed to disk. Another way is to read all their values at the end of the program's run (as it is being shutdown) and write these values to a file, then have those values read in at the next startup and written to the globals in some "global_init.vi" as the previous writer said.

P.M.

 

Putnam
Certified LabVIEW Developer

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


LabVIEW Champion



0 Kudos
Message 3 of 8
(3,991 Views)
It's important that you understand - the global variables aren't "set" or "not set". They hold whatever value you put into them. If you don't put anything in them, they remain in their default value (which you can set by selecting right clicking and selecting Data Operations>>Make Current Value Default. Like pincpanter said, you have to initialize them at the beginning of your program.
 
In general, you should be careful when using global variables, because it's very easy to create race conditions.

___________________
Try to take over the world!
0 Kudos
Message 4 of 8
(3,990 Views)

I am using the global variables as calibration constants that are only read in the program.  The values of the global variables are set by manually setting the value and then selecting Data Options, Use current value as Default option.  The problem is that the first time I run the program the global variables are 0.  If I stop the program and then rerun the program the variables are at the correct values.  I checked this by setting a break point with probes on a few of the variables. 

Any ideas?

 

Mike

0 Kudos
Message 5 of 8
(3,976 Views)
If you are using globals as a constant, that means that you aren't writing to them from a vi, and that should not cause any race condition.  So it is OK to use Globals in this manner.  I've used globals as constants before and never had problems.  Here is the correct procedure.  Open the global vi.  Change the value in the global variable to your new calibration constant.  Right click and select Data Operations - Make Current Value Default.  Then save the global vi.  Open it again and make sure the new changes are there.  Then when you open a vi that accesses the global, the new default value should be there.  From what you are saying, opening the first time has zeros and then opening it again has the right values, this does not make any sense unless something in your vi is writing to the globals, which it should not be doing.  Perhaps you can zip up the globals vi and the vi that accesses the globals and we can look at it.
- tbob

Inventor of the WORM Global
0 Kudos
Message 6 of 8
(3,973 Views)
I'm not sure what the problem was, but this is what I found. 
 
I know that I used the Data Operations pulldown to set the default values as these did get set on the second execution of the program.  There was one variable that was set properly with four others that first came up as zero.  When I looked at the four variables I saw that the  indicator and Data Range tab showed the default as zero, but the correct number for the fifith!  I went in and set the Data Operations Default value and it now works!   I also noticed that the value displayed in the Data Range indicator does not follow the Format/Precision settings i.e. a value of 0.123456 is displayed as 0.1235. 
 
Regards,
Mike
0 Kudos
Message 7 of 8
(3,964 Views)
Like tbob said, this doesn't sound right - if you set the values as default, they should have been loaded when the global VI was loaded into memory, i.e. when you opened a VI using one of its globals. The only way it should have had the values on your second run is if you did write values into them during your first run. Are you absolutely sure that you're not writing into them anywhere? If so, I still suggest you post the code (although you say it's working fine now, so I don't think we will have anything to see).

___________________
Try to take over the world!
0 Kudos
Message 8 of 8
(3,946 Views)