Example Code

Programmatically saving and loading values of all front panel controls

Code and Documents

Attachment

Overview

This VI demonstrates how to save data of controls on the front panel into a configuration file then load the configuration file into the front panel

 

 

Description

This VI uses an the "Ctrl Val.Get All (Deprecated)" invoke node method to save the values of all of the controls on the front panel to a config file (no matter how many controls are present). This is especially useful if a customer wants to save control values when they are deploying an executable to a target machine as the "Make Current Values Default" action cannot be set during run-time.

 

 

Requirements

LabVIEW 2012 (or compatible)

 


Steps to Implement or Execute Code
1. Modify the values of controls
2. Click on Save
3. Modify the control values again
4. Click on Load and check how values are restored in the controls
5. Click on Stop

 

 

Additional Notes or References

 

Block Diagram

BD Load.PNG

BD Timeout.PNG

 

Front Panel

 

FP.PNG

 

*This document has been updated to meet the current required format for the NI Code Exchange**

 

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
Todd S.
NI Employee (retired)
on

Great stuff, thanks for posting!

Todd S.
LabVIEW Community Manager
National Instruments
metoo
Member
Member
on

Could you post this in 8.0?

Thanks

Lars_L
NI Employee (retired)
on

Sure. There you go!

EdgarB
Member
Member
on

I've got a problem with this VI in reading files.

Your example is working fine, but if I transfer it to my VI (with a little more controls), it reports the data to be corrupt or truncated.

I guess that's maybe because of some controls inside of tabs? How can this problem be fixed? Any idea anybody? 😕

Ben.k
Member
Member
on

I had this problem, too. The data string is not the same after loading it again. I could fix this by deactivating EOL-converting in the context menus of the "Write to text file" AND "Load from text file" functions.

Dr. Tallman
Member
Member
on

Is there any way these files can be read and edited outside of LabView?. Or translated within LabView?

bcharles
Member
Member
on

Does this save the controls/settings associated with plots and graphs? I have an executable that has a graph in it. On one machine I would like to configure it to show plots 0,1,2 and another plots 1,3,5. Wondering if by adding this code to my code and automatically updating the config file at the end of use then loading it upon launching the application I can customize the application on different machines.

kdmcmullan
Member
Member
on

Has anyone got a recursive version of this?

Allen Bradley
Member
Member
on

The program works fine for me and I can add and remove controls but when I move it to my application where I need to use it, i am getting an error when unflattening. It might be an issue with how it flattens the data but I can't get it to work. help!

Gurdas
Active Participant
Active Participant
on

I am probably seeing the same error as @Allen_Bradley. And the solution is to uncheck the "Convert EOL" option for the 'Write to Text File' and the 'Read from Text File' functions in the code. That option is accesed by right-clicking the Write and Read functions in the code. This is what @Ben.k is referring to in a previous comment. This issue is also mentioned at: http://forums.ni.com/t5/LabVIEW/Unflatten-variant-from-string-got-error-122/m-p/3174711

More details:

I am using LabVIEW 2016. In my VI, I created two event cases and dropped the code Save and Load code. When I run my VI, I am able to create a .INI file and it seems to have all my controls (followed by cryptic binary values). However, when I try to load the saved .INI file, I am getting an error in the unflatten part. The exact error messge is:

"

Error 122 occurred at Unflatten From String in myVIname

Possible reason(s):

LabVIEW: The resource you are attempting to open was created in a more recent version of LabVIEW and is incompatible with this version

"

Gurdas Sandhu, Ph.D.
ORISE Research Fellow at US EPA