このコンテンツは設定された言語で表示できません。

このコンテンツは表示可能な別の言語で表示されています。 お使いのブラウザに翻訳機能がある場合はご利用ください。

Loading Front Panel Data from the Previous Run of LabVIEW VI

Updated Feb 26, 2019

Reported In

Software

  • LabVIEW

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?

Solution

Note: This example uses VIs from the OpenG Libraries, which can be downloaded using VI Package Manager .

In order to programmatically load front panel data from a previous run of a VI, you will need to implement two pieces of code. The first piece detailed here writes the front panel data to a configuration file at the end of your VI's execution. The second piece loads the values from that configuration file at the beginning of the VI's execution.
 

Writing Front Panel Values to a Configuration File:

  1. Use the Strip Path and Build Path functions, in conjunction with the Current VI's Path to obtain a reference to the configuration file you would like to write to or create and then open that reference using the Open Config Data VI.
  2. Obtain references to the front panel controls using Property Nodes. First use a VI Server Reference and a property node to obtain a reference to the front panel, and then use an additional property node to get an array of references to the front panel controls.
  3. Index this array of references through a For Loop. For each control, extract its name and value using a property node. Use the Get Type Information VI to programmatically retrieve the data type of the control.
  4. Use the data type as the case selector for a Case Structure. In each case, use the Variant to Data function to  format the data appropriately and the Write Key VI to write it to the configuration file.
  5. After the For Loop, close the reference to the configuration file using the Close Config Data VI.
  6. It is also good practice to include some type of error handling to manage any errors encountered during program execution. This example uses the Simple Error Handler VI.

You will want to make sure this code executes at the very end of your program to ensure the values recorded are those on the front panel at the end of the VI's run.
 

Loading Front Panel Values from a Configuration File

There are two small changes we can make to the code in order to load the front panel values from the configuration file into the VI.
  1. In each case of the For Loop, change the Write Key VI to a Read Key VI. As this VI is polymorphic, ensure the data type selected for the VI matches the data type of the case.
  2. Add an additional property node to each case of the For Loop. Wire the control reference to the reference input of this new property node. Right-click on it and select Change to Write. Wire the data output of the Read Key VI to the input of the Value property.

You will want to make sure this code executes at the very beginning of your program to ensure the values are loaded before any other code executes.


 

Additional Information

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 configuration file. These files are organized as a set of sections, specified by section headers, each with its own associated key-value pairs.There are two shipping examples in the LabVIEW Example Finder called Read Configuration Settings File  and Write Configuration Settings File 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...

There are also alternatives to store configuration data from a VI. For instance, if you want to store a cluster containing several parameters for an acquisition task, and you want to persist different sets of those parameters, there could be value in using an XML file over a .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 the above file types.

WAS THIS ARTICLE HELPFUL?

Not Helpful