Loading Front Panel Data from the Last Run

Updated Aug 9, 2018

Reported In

Software

  • LabVIEW Full

Issue Details

I want to save all of my controls/indicators to a file so that I can reload them when the VI is executed again

How can I save new default front panel values after every iteration of my VI?

How do I save all of my controls/indicators to a configuration (.ini) file so that they can be viewed after closing my VI and reloaded upon reopening my VI?

Solution

The Configuration VIs found under Functions»Programming»File I/O»Configuration File VIs can be used to write the values of controls and indicators to a config file.

These files are organized as a set of sections, specified by section headers, each with its own associated key-value pairs. Follow the steps below to write the values of your Front Panel controls to a config file:
 

  1. Obtain references to both the config file you would like to write to, or create, and your Front Panel controls.

    • For the config file reference, use Strip Path and Build Path, in conjunction with the current VI's path.

    • For the Front Panel controls reference, you can use Property Nodes to get a reference to the Front Panel itself and then to the controls within the Front Panel.2. Create/open your config file using Open Config Data vi. This VI prepares a config file for read/write operations.

  2. For each control on your Front Panel, extract its name and value using a Property Node and convert this information to the proper format.

    • Before writing the data to file, we must first convert the variant type returned by the Value property to its corresponding data type. Use Get Type Information vi (Functions»Programming»Cluster, Class, & Variant»Variant»Data Type Parsing) to determine the data type and feed the type output into a case structure to conditionally handle each data type present in your Front Panel controls.

    • Within each case, you can use Variant to Data to convert the Value variant to its corresponding data type. Keep in mind that you will need to fill in cases for all of the data types you wish to store (but not all possible data types). See the Related Links section to learn more about using variants in LabVIEW.

  3. Once you have the control's value in the proper format, use Write Key vi to write the control's value to the Controls section of the config file under the key specified by the Label. Text property. This is the name of the control on your Front Panel.

  4. After completing steps 3 and 4 for each control, close the config file reference using Close Config Data vi. It is also good practice to include some type of error handling to manage any errors encountered during program execution. In this example, we have used Simple Error Handler vi.

Upon reopening your VI, this process can be reused to preload your controls with the values saved to your config file. Substitute Write Key vi with Read Key vi, using the name of the control (key) and appropriate section to obtain the saved value of the control. You can then write this value to the control using a Property Node.

Note: There are two shipping examples in the LabVIEW Example Finder called Read Configuration Settings File vi  and Write Configuration Settings File vi that can be used to learn more about using the Configuration File VIs. The LabVIEW Example Finder can be found in LabVIEW by selecting Help»Find Examples...

Additional Information

There are alternatives to store configuration data from a VI. Let's say you want to store a cluster containing several parameters for an aquisition task, and you want to persist different sets of those parameters. In that case, you could aslso see value in using an XML file over ini. Other configuration file options include:
  • JSON (JavaScript Object Notation)
  • CSV (Comma Separated Values)
  • Binary (Raw data streamed to Disk)
You can use LabVIEW built-in functions to implement configuration data storage with any of those file types.

WAS THIS ARTICLE HELPFUL?

Not Helpful