LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Save and load global variables

Hi all
 
I've got the following problem:
At the moment I'm working with a spectroscope. I have to extract some peaks, which are produced when the ligth is refracted by different materials. And I've got two references saved as global variables to compare with: one is a dark reference (without any light & materials) and one only with the light.
 
But when I'm restarting my system at the moment, I have to store both references again (because they're just saved within the vi's).
Is there a possibility to save this variables in a .txt or .xls-file, where they can be easily load from after restarting the program?
 
Thanks in advance
 
Dave
0 Kudos
Message 1 of 12
(7,743 Views)
Dave,

Look at the Configuration File VIs. They are designed for exactly this type of application.

You may also want to think about keeping the data in a shift register or Action Engine rather than globals. Direct wiring of data is always preferable to other means of getting data to various parts of the program. Globals may lead to race conditions (perhaps not an issue in your case since you rarely change the values) and break the dataflow pardigm of LabVIEW.

Lynn
Message 2 of 12
(7,734 Views)
Hi Dave,

two (easy) methods:
1) Use the Config file functions in the File palette, they are made just for this purpose!
2) Save the values using the text or spreadsheet file functions using your own file format...
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 3 of 12
(7,733 Views)
I would say that the easiest way to do that is to use .ini files. You can find specific fonctions to read and write these files in the File I/O=>Config File VIs library. It's really easy and fast.
CLA, CTA, LV Champion
View Cyril Gambini's profile on LinkedIn
This post is made under CC BY 4.0 DEED licensing
Message 4 of 12
(7,734 Views)
Ok, I could do it with the spreadsheet file functions...


But anyway,  thanks to all of you!
Dave
0 Kudos
Message 5 of 12
(7,710 Views)
Since your files are "waveforms" and likely to be somewhat large, you may want to consider one of the binary formats (HWS or TDMS).  They will read and write much faster and HWS even has compression.  TDMS is available from the LVM read/write express VIs in LV 8.2.  HWS is on the driver CD next to the computer based instruments.  If you have one of the computer based instrument drivers installed, you probably already have it.  It became available at LV 7.1.
0 Kudos
Message 6 of 12
(7,687 Views)
On Jul 12, 8:10 am, Reepicheep <x...@no.email> wrote:
> Hi all
> &nbsp;
> I've got the following problem:
> At the moment I'm working with a spectroscope. I have to extract some peaks, which are produced when the ligth is refracted by different materials. And I've got two references saved as global variables to compare with: one is a dark reference (without any light &amp; materials) and one only with the light.
> &nbsp;
> But when I'm restarting my system at the moment, I have to store both references again (because they're just saved within the vi's).
> Is there a possibility to save this variables in a .txt or .xls-file, where they can be easily&nbsp;load from after restarting the program?
> &nbsp;
> Thanks in advance
> &nbsp;
> Dave

If the variables are not written at any moment during the software
execution, you can wire the global variables to those values as
constant at the begining of the program.

0 Kudos
Message 7 of 12
(7,672 Views)
You could use spreadsheets or a text file but the easiest would be to use a small Jet database. There would be less reformatting to do, the database engine itself is free (bundled inside Windows) and I can send you the code to do it. In addition if these reference values should change over time the database would be able to store historical values as well as timestamps of when they changed. In terms of formatting you simply flatten the structure (whatever it might be) to a string for insertion and then unflatten it when you read it back. In the long run a lot easier than doing it with Excel.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 8 of 12
(7,672 Views)
If you do this, be aware that "flatten to string" is a very brittle operation.  You have to know, a priori, what the data type is before you can read it.  If you lose your reader/writer code, the data becomes almost useless.  ASCII, TDMS, and HWS are all "self-describing" files.  You can find browse them without knowing their contents ahead of time.
0 Kudos
Message 9 of 12
(7,634 Views)
While it is true that you have to know ahead of time what the datatype of the flattened data is, I don't agree that it's "useless" without the LV-based reader code. I routinely store flattened strings to Oracle blobs precisely because it is so easy for other applications to read and recover the data. The format for flattened data is well-documented and easy to code in other environments such as Java.

Mke...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 10 of 12
(7,625 Views)