LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Saving Globals programmatically

Can someone advice me how to change the value stored in the global variable,
make it default and save this change from another VI?

Thanks
Ladislav
0 Kudos
Message 1 of 9
(2,738 Views)
You can save the globals to a .INI file and when the VI loads again, read the
values from the .INI file.

Ladislav CZAP wrote:

> Can someone advice me how to change the value stored in the global variable,
> make it default and save this change from another VI?
>
> Thanks
> Ladislav



--
Ori Idan
O. T. Idan LTD. National Instruments Alliance member in ISRAEL
Email: ori@otidan.co.il
Home page: http://www.actcom.co.il/~otidan
Tel: +972-6-6262353 Fax: +972-6-6262405
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Things should be made as simple as possible but not simpler
Albert Einstein
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
0 Kudos
Message 2 of 9
(2,738 Views)
same question in fact!! I also thought it would be very nice to put data you want to save in a global,
make the current values defauld (with the aplication control/ property or invoke nodes) and then save the
file (using save the pannel only). However, it never worked. I phoned the help desk and they said it was not possible to do this.
0 Kudos
Message 3 of 9
(2,738 Views)
casimir wrote:
>
> same question in fact!! I also thought it would be very nice to put
> data you want to save in a global,
> make the current values defauld (with the aplication control/ property
> or invoke nodes) and then save the
> file (using save the pannel only). However, it never worked. I phoned
> the help desk and they said it was not possible to do this.

Casimir,
There are a number of ways to deal with the "save front-panel
defaults" issue. It has been addressed in at least one LTR article. In
addition, I worked out a solution and have posted it on my web site. Go
to www.originalcode.com, then Example Code, Utilities, and Program
Downloads, then look for the Save Defaults program. There is a Word
document with it that explains how
it works and also discusses some of
the other ways to do this. If you want to use this for your case, you
will need to work with it a bit. It is currently designed to save the
front-panel defaults of a top-level VI. You will have to alter it to
try to save global variable values as defaults. I would be curious if
you get it to work well for you.

Regards,
Dave Thomson

-------------------------------------------------------------
David Thomson 303-499-1973 (voice and fax)
Original Code Consulting dthomson@originalcode.com
www.originalcode.com
National Instruments Alliance Program Member
-------------------------------------------------------------
Research Scientist 303-497-3470 (voice)
NOAA Aeronomy Laboratory 303-497-5373 (fax)
Boulder, Colorado dthomson@al.noaa.gov
-------------------------------------------------------------
0 Kudos
Message 4 of 9
(2,738 Views)
Hi David,

Thanks for your reply. I can now save my globals and front panels in the same way.I only made a minor change to your vi's, i pass the path of the vi to save to the save defaults vi.

I only ran into an other problem. I wanted to save both the global a vi is using and it's front panel. I made the default saver vi reentrant and called the save defaults vi twice. However, using the vi server method "run vi" and making the "wait until done" fals, it does not seem possible to call a reentrant vi twice and run the vi parallel.

I also tested this in an other way: I made a vi that waits 1 sec and increments an indicator of a global. This "wait.vi" is reentrant and creates a reference to itself to prevent it from closing. I then made a "top.
vi" which contains a for loop that executes 4 times and in which I open a reference to the wait.vi and use the server method "run vi" with the "wait until done" fals (because I want the wait.vi to run parallel.)
However, the global is incremented only once!!

Do you have any coment?
0 Kudos
Message 5 of 9
(2,738 Views)
This discussion has come around here a few times. I think that NI needs to clarify the explanation of "reentrant". A reentrant VI can be called in parallel from two DIFFERENT VIs. You can not call it twice from the same VI. LabVIEW checks its memory to see if the VI you are calling is already loaded. If it finds the VI, then it uses it and does not load it again.

Rob
0 Kudos
Message 6 of 9
(2,738 Views)
Are you sure about this? My experience has been that a reentrant vi can be
sited in a vi multiple times, and each instance will maintain its own data,
just as one would expect.

"Rob Cole" wrote in message
news:506500000005000000FB480000-1003545641000@exchange.ni.com...
> This discussion has come around here a few times. I think that NI
> needs to clarify the explanation of "reentrant". A reentrant VI can be
> called in parallel from two DIFFERENT VIs. You can not call it twice
> from the same VI. LabVIEW checks its memory to see if the VI you are
> calling is already loaded. If it finds the VI, then it uses it and
> does not load it again.
>
> Rob
0 Kudos
Message 8 of 9
(2,738 Views)
Ignore this comment. I reread the thread and realized that the respondant
was discussing calling the vi with the vi server.

"D D"
wrote in message
news:E4hB7.13154$Yd2.4089188372@newssvr16.news.prodigy.com...
> Are you sure about this? My experience has been that a reentrant vi can
be
> sited in a vi multiple times, and each instance will maintain its own
data,
> just as one would expect.
>
> "Rob Cole" wrote in message
> news:506500000005000000FB480000-1003545641000@exchange.ni.com...
> > This discussion has come around here a few times. I think that NI
> > needs to clarify the explanation of "reentrant". A reentrant VI can be
> > called in parallel from two DIFFERENT VIs. You can not call it twice

> > from the same VI. LabVIEW checks its memory to see if the VI you are
> > calling is already loaded. If it finds the VI, then it uses it and
> > does not load it again.
> >
> > Rob
>
>
0 Kudos
Message 9 of 9
(2,738 Views)
casimir,

the VI is reentrant only if you open a strict def for calling by reference.
If you open generic references to use the Run method, only one instance of
the VI is created. In the test you made with the for loop, check the error
cluster outgoing the Invoke Run Method node; you will see that only the
first iteration succeeds and other iterations return an error because the
instance of the VI is already running.

That being said, you can achieve what you want by saving the VI as a
template with the .vit extension. Doing so, every new open reference will
load a different copy of the VI in memory (different name) that can run
independantly of each other.

Jean-Pierre Drolet


LabVIEW, C'est LabVIEW

0 Kudos
Message 7 of 9
(2,738 Views)