Implementing Configuration Files for Computer Based Data Acquisition Systems

Publish Date: Nov 20, 2018 | 14 Ratings | 3.79 out of 5 | Print | 7 Customer Reviews | Submit your review

Overview

Configuration files manage configuration information for computer-based systems. Unlike conventional configuration GUIs, configuration files provide a portable and flexible method to manage configuration information.

Table of Contents

  1. Background
  2. Developing a Configuration File Format
  3. Configuration Tools
  4. Configuration Application Examples
  5. The Configuration Property Editor
  6. Conclusion

1. Background

Written By Craig Claassen | National Instruments

Configuration is an important element of computer based measurement and automation systems. For simple systems, often you implement the entire application including system configuration with custom code. However, as application complexity and the need for reuse increases, you must put more thought into managing system configuration information. You also must devise a method to generate, store, access, and manage configuration data. Starting from scratch can be a costly endevour.

You can reduce software development costs with a set of generic, reusable tools that can handle configuration management for various system types. This document presents a set of basic LabVIEW tools to quickly and easily generate, maintain, and access configuration data. In addition to these tools, the document discusses a platform-independent and human-readable file format for storing the data. You can use the tools' configuration platform for numerous system types.

Back to Top

2. Developing a Configuration File Format

Configuration File Format

In the previous document Considerations for Managing Data Acquisition System Configuration Information, we discussed various configuration file formats that store the configuration information for use at run-time in our data acquisition system. You may recall formats such as databases, spreadsheets, and XML limit us in areas like platform independence. We recommended the configuration settings file (.ini file format). Over the next several document sections we discuss how to utilize the .ini file format to store configurations that range from simple to complex. 

INI files are ASCII encoded and consist of sections and keys. In LabVIEW 7.1 or earlier, refer to the LabVIEW User Manual for more information about INI files. In LabVIEW 8.0 or later, refer to the LabVIEW Help topic Creating Configuration Files. 

Figure 1 shows an INI file with various configuration information contained within the sections and keys. Notice the .cfg extension, which denotes the file's configuration purpose. Despite the different file extension, .cfg files follow the same format rules as .ini files.

Figure 1. INI file used for configuration


Initially, the INI file structure seems limiting and flat. In subsequent sections, however, we work within this basic format to create a flexible method to handle complex system configurations.

Configuration Data Organization

In the previous document, Considerations for Managing Data Acquisition System Configuration Information, we discussed various pieces of information the system developer may want to include in the configuration file. For large, complex systems, there you may have to account for a large number of variables that make up the complete configuration for the system under development. Coming up with a logical way to organize the configuration information is important. Logically organized variables help ensure you include all the necessary information to properly configure the various pieces of the system. It also makes it easier for other developers to understand the configuration for future modification.

Generally, we view pieces of the system as they fit into the system as a whole to establish a hierarchy. We use this heirarchy to structure the configuration.

To help clarify the configuration concepts used in this document, we apply a configuration to an example system. A hardware chassis (with an embedded controller) that contains two data acquisition modules comprises this example system. 

We use several pieces of information to properly control the system. The chassis has an associated IP address and the two modules each have enabled information and sample rate information. The chassis is the highest level in our hierarchy. Below the chassis, we have ipaddress, module1 and module2. Lastly, we locate enabled and samplerate under each of the modules. We can refer to each level in the hierarchy as properties of the system configuration.

Figure 2 shows the hierarchy of the system configuration with each of the properties listed.


Figure 2. Hierarchy of the system configuration

Like the typical computer file system, the system configuration architecture can expand as we add more configuration properties without the need modify existing properties already been included in the configuration. Properties can behave similar to both typical computer directories or files.

A property may have a value (string, integer, Boolean, etc.) associated with it, much like a file contains data. A property also may contain other subproperties, much like a directory in the file system contains a file or multiple files. This applies at any given level.

We also access any property in the system configuration by identifying a path to that particular property using dot notation. For example, chassis.module2.enabled points to the enabled property of module2. The path for each property within the configuration is unique so that any given path will never return more than one property value.

Configuration Data and Configuration Files

You do not need to completely understand the configuration file is formatting in order to use it. The tools presented later in this document take care of formatting details. However, we give a brief overview of the formatting so you have a basic understanding of the configuration file structure. 

In order to support the various hierarchical levels within a given configuration, any property with subproperties has its entire path stored as a section. For instance, the property module2 has the path chassis.module2. The configuration file stores the path as a section. The configuration file stores any properties with an associated value rather than subproperties as keys underneath their parent property. For example, we can locate the the enabled property under module2 under the chassis.module2 section as the key enabled.

Since configuration file properties may consist of several different data types (string, integer, Boolean, or float), we designate the data type within the configuration file. Since INI files are ASCII encoded, every piece of information within the configuration file is stored as an ASCII character. We have no way of knowing what the datatype of a specific key.

In Figure 1, each key has the data type for a particular property concatenated to property name. For example, the ipaddress property contains _STR at the end of the property name to indicate a string data type.

Note that "." and "_" are special characters used in the section and key names for our special implementation of an INI file. Because of this, we cannot use these characters as part of a property name. The tools we discuss in subsequent sections automatically apply these special characters in the appropriate way to properly handle all formatting when we write the configuration to a file.

Back to Top

3. Configuration Tools

In the previous section, we discussed a hierarchical method to organize configuration data, format the hierarchy, and reference properties for storage in a standard file format. Later, we discuss how to implement the example configuration file. First, however, we need to introduce a set of LabVIEW tools to assist in generating, saving, loading, and editing configuration files. This way you can easily incorporate our configuration strategies in your LabVIEW application.

Configuration Tool Library

At the document end, you will find a link to examples that include a library of files that for use within LabVIEW to manipulate configuration files. You may want to install these files before proceeding, as much of the subsequent documentation will reference the examples to explain the functionality of the tools. The documentation accompanying the examples explains how to install the various VIs in their correct locations. You can access the main VIs to edit the configuration in the Functions pallette by navigating to User Libraries>>Configuration Tool.

Figure 3 shows the Configuration Tool pallette.

 


Figure 3. Configuration Tool pallette


You will manage the configuration using the manageConfig VI in the Configuration Tool pallette. This polymorphic VI contains the entire API used to interface with the configuration (for more information on polymorphic VIs, refer to the LabVIEW Help). Click the polymorphic VI selector located directly below the VI on the diagram to access the various functions within the API.

The flow of a program using these tools is simple. First, you initialize the configuration. Then your can load an existing configuration or proceed directly to adding, modifying, getting, or deleting properties within the configuration. You then save the configuration back to a file and close the reference to the configuration.

Figure 4 shows a basic block diagram for the program flow.

Figure 4: Block diagram for configuration application


The following section outlines each of the instances in the Configuration Tool API.

 

Init Config: This instance opens a reference to local LabVIEW memory and stores a local copy of the configuration. We use it in every application. The instance outputs a configuration reference (config ref) that passes to other VIs that access the configuration associated with this reference. It can open multiple configurations simultaneously using multiple calls to this instance. Each call generates a unique reference for a particular configuration.

Load Config: This instance loads a particular configuration from a file into local memory. Pass the config ref generated by the Init Config instance to the Load Config instance. Once you load the configuration with this instance, subsequent VIs can get, set, add, and delete configuration properties.

Add Property: The manageConfig polymorphic VI contains Add Property instances for multiple data types. These include string (STR), 32-bit signed integer (I32), 32-bit unsigned integer (U32), 64-bit floating point value (DBL), and Boolean (BOOL).

Choose the correct data type for the property you would like to add and enter the dot-notation property path, the actual value of the property and the config ref. The instance call automatically verifies the entire path to the property exists. If it does not exist, the instance automatically adds the necessary parent properties to map the entire path.

You will also notice the Raw data type option to add a value to the local copy of the configuration. The Raw data type is a cluster of three strings: property path, data type and value. This represents how we actually store data in local memory. The other Add Property instances automatically handle this formatting, making them more ideal choices, if possible.

Get Property: The manageConfig polymorphic VI also contains Get Property instances for multiple data types. They return whether the property is found and the value of that property. Besides the STR, I32, U32, DBL, BOOL and Raw data types, two other variations of the Raw data type appear. The All data type returns an array of Raw-formatted data for each property within the entire configuration. The Subproperties data type outputs an array of Raw-formatted subproperties of the specified property in the hierarchy of the configuration.

Remember Raw data contains strings of the path, data type, and value. Again, you should use the standard functions, if possible, for most applications.

Set Property: The Set Property instances allows you to update the value of an existing property in the current loaded configuration. Again, your options include the standard data types (STR, I32, U32, DBL and BOOL) along with the Raw type. You also have one addtional instance, New Path, raw. This mode functions like Raw with the added ability to change the name and/or property path for a particular property. This mode allows you to update property paths for any subproperties that may exist under the particular property of interest.

You must update the paths of each of the subproperties accordingly if you modify the name and/or path of the parent property. The old property path input should contain the original path of the property before the name or path change. The property data should contain the new path you want to apply to this property and all of its subproperties.

Delete Property: The Delete Property instance deletes a specific property and all of its associated subproperties. Pass in the property path, along with the config ref, to this function to perform the operation. The Delete All Properties instance deletes every property in the configuration and only requires the config ref to perform the operation.

Save Config: The Save Config instance allows you to store a copy of the configuration to file. The function automatically converts the properties for storage in the configuration format discussed earlier. If the file exists, it will automatically overwrite the file with the current configuration information. If you would like to prevent this overwriting, you should programmatically check to see if the file exists before calling the Save Config instance. Simply pass the config ref to this function to save the desired configuration to file.

Close Config VI: The final instance for the manageConfig polymorphic VI is Close Config. Once you manipulate the configuration and store it back to a file, you must close the reference to LabVIEW memory used to store the local copy of the configuration. Pass the config ref to this instance to close the appropriate configuration.


Back to Top

4. Configuration Application Examples

Now that we discussed the individual tools in the Configuration Tool library, we turn to implementing several applications using this set of tools. We based the subsequent example applications on the configuration discussed earlier. You can find the example files at the end of this document.

Generating and Saving Configuration Files

We will discuss the Generate & Save Configuration VI  example first. The VI programmatically generates configuration information and saves it to a file.

Figure 5 shows the block diagram for this example. 

Figure 5: Generate & Save Configuration VI block diagram


The Generate & Save Configuration VI initializes the configuration, adds the properties, saves the configuration to file, and closes the configuration reference.
 
See below for a more detailed description of the LabVIEW code using the manageConfig polymorphic VI.


1. Initialize Configuration - The Init Config instance initializes the configuration by setting aside local LabVIEW memory for temporary storage of the configuration data.

Figure 5.1: Initialize Configuration


2. Add Properties to the Configuration - Add each new property to the configuration using the Add Property instance. Pass the desired path, including the property name, along with the value you would like to store.
 
Figure 5.2: Add Properties to the Configuration
 
3. Save the Configuration - After adding each property, call the Save Config instance to store the configuration to file. You now have a configuration file that you can transport to the appropriate system(s).
 
Figure 5.3: Save the Configuration
 

4. Close the Configuration - Once you save the configuration to file, clear the LabVIEW resources with the Close Config instance.

Figure 5.4: Close the Configuration

The Generate & Save Configuration VI creates the configuration file system.cfg shown in Figure 1 at the beginning of this document.
 
Note, however, the configuration file shown in Figure 2 shows eight different properties in the configuration. Of these eight, five of the properties have values. The three properties chassis, module1, and module2 are parent properties and do not have associated values.
 
The Generate & Save Configuration VI only explicitly adds the properties with associated values. The tools automatically check the entire path, including the existance of the parent properties for each newly added subproperty. Even though we do not explicitly add chassis, module1, and module2 to the configuration, the tools automatically add these properties to ensure a complete configuration file.


Loading Configuration Files and Getting Properties

Once you generate a configuration file, you will need to load the file and get various properties from the configuration. The Load Configuration & Get Properties VI  accommplishes this task.
 
Figure 6 shows the block diagram for this example.

Figure 6: Load Configuration & Get Properties VI block diagram



The Load Configuration & Get Properties VI initializes the configuration, loads the configuration from file, gets the requested properties from the configuration, and closes the configuration reference.

See below for a more detailed description of the LabVIEW code using the manageConfig polymorphic VI.

1. Initialize Configuration - The Init Config instance initializes the configuration by setting aside local LabVIEW memory for temporary storage of the configuration data.

Figure 6.1: Initialize Configuration

2. Load Configuration - The Load Config instance loads the desired configuration file into local memory. We can now query the file to add, get, or set properties.

Figure 6.2: Load Configuration

3. Get Properties - Pass the property path and data type to the Get Property instance for each property you would like to retrieve.

Figure 6.3: Get Properties

4. Close the Configuration - Once you query the configuration, clear the LabVIEW resources with the Close Config instance.

Figure 6.4: Close the Configuration

Editing Configuration Files

Finally, we will discuss editing configuration files using the Editing Existing Configuration VI.

Figure 7 shows the block diagram for this example.

 
Figure 7: Editing Existing Configuration VI block diagram

The Editing Existing Configuration VI initializes the configuration, loads the configuration from file, gets the requested properties from the configuration, sets the properties to a new value, saves the configuration back to file, and closes the reference to the configuration.

See below for a more detailed description of the LabVIEW code using the manageConfig polymorphic VI.

1. Initialize Configuration - The Init Config instance initializes the configuration by setting aside local LabVIEW memory for temporary storage of the configuration data.

Figure 7.1: Initialize Configuration

2. Load Configuration - The Load Config instance loads the desired configuration file into local memory. We can now query the file to add, get, or set properties.

Figure 7.2: Load Configuration
 
 
3. Get Properties - Pass the property path and data type to the Get Property instance for each property you would like to retrieve. Note, for this particular example you do not need to get the properties before you set the properties to a new value in the next step. We simply use the Get Property instance to see the present value for the respective property.
 
 
Figure 7.3: Get Properties
 
 
4. Set Properties - The Set Property instance allows you to edit property values. Enter the path and choose the data type for the new value we want to assign to a particular property.

Figure 7.4: Set Properties

5. Save the Configuration - After editing the desired properties, call the Save Config instance to store the configuration to file.

Figure 7.5: Save the Configuration
 
 

6. Close the Configuration -  Once you save the configuration to file, clear the LabVIEW resources with the Close Config instance.

Figure 7.6: Close the Configuration
 

Back to Top

5. The Configuration Property Editor

In the previous document, Considerations for Managing Data Acquisition System Configuration Information, we discussed  three different levels of configuration editors, interfaces used to manipulate configuration data. We can make most basic edits using a simple text editor such as Notepad. We can also use a fully functional configuration GUI, often seen in the deployed application to assist the end user with managing the configuration. Lastly, we have a hybrid between the simple text editor and the fully functional GUI editor.

This type of editor gives enough functionality to easily manipulate the configuration without the addtional GUI interface. An engineer developing the entire system would most likely use this type of editor. We included an intermediate editor called ConfigEditor with the example code. You can downloaded it here. For installation instructions, please refer to the Readme documentation included with the example.

Once you install the editord, you can access it from LabVIEW by navigating to Tools>>Configuration Property Editor.

Figure 8 shows the basic interface of the Configuration Property Editor with the system.cfg configuration file loaded.

Figure 8: Configuration Property Editor

The Configuration Property Editor allows you to interactively build a configuration file without having to create this file by hand or programmatically. We built the Configuration Property Editor using the Configuration Tool Library discussed in previous sections. The source code for the editor is well documented.

The editor delivers very basic functionality to easily generate and maintain configuration files. We encourage you to add functionality or change the existing functionality of the editor, if needed. We will highlight the main features of the Configuration Property Editor. For an in-depth explanation of all of the functionality included with the interface, refer to the online help included with the Configuration Property Editor.

Using the Configuration Property Editor to generate and edit a configuration

In the Configuration Property Editor, you can find options in the File menu you to create new configurations, open existing configurations, and to save configurations to specific locations. Also, options in the Edit menu allow you to edit a specific property. When you select an Edit menu item, a window opens allowing you to edit the data type and initial value of a property. You can also specify whether or not a property should contain subproperties.

Figure 9: Property Data Editor Window
 

The main interface uses a tree control to represent the hierarchy of the configuration and to display the data type and value associated with each property. You can expand or collapse various branches of the tree to browse amidst properties and associated subproperties. Right-click a given property to edit, delete, or add subproperties.

Using the Configuration Property Editor to assist in writing code to utilize configuration files

In addition to generating and maintaining configuration files with the Configuration Property Editor, you can also open the editor and load a configuration file while building your application.  When building code dependent on the configuration, you can quickly scan through the configuration information and extract path and data type information. This may aid in the development process.

See Figure 10 for an example of a developer workspace.

Figure 10: Using the Configuration Property Editor to assist in building an application.

Ensuring correct property paths is a common obstacle. To help alleviate this issue, highlight the path in the Property Path window of the Configuration Property Editor and copy it to the Windows clipboard. Then go to the block diagram and paste the entire path into the string constant. This helps avoid misspellings and syntax errors. Keeping the Configuration Property Editor open while building the code also allows for on-the-fly access to configuration data.

Back to Top

6. Conclusion

Configuration management is an important piece of any computer based system. Having a set of generic configuration management tools, along with a platform independent configuration file structure allows the system developer to more easily generate, maintain, and utilize configuration data within the system under development. This document showcased a set of reusable tools and the benefits of a flexible configuration file structure.

You can download the configuration tools here.

 

Back to Top

Customer Reviews
7 Reviews | Submit your review

Does not install on 64-bit LabVIEW system  - Oct 13, 2016

When attempting to install on LabVIEW 2016 Full Development System 64-bit version, received error that LabVIEW 8.2 or higher is required. Checked with LabVIEW technical support. Did install on 32-bit LabVIEW OK.

vi's contain broken wires  - Oct 30, 2008

The example VI's contain broken wires when opened in LabView 8.6

Intermediate editor   - Mar 20, 2008

The ConfigTool installs the Configuration Property Editor too, and the link is in the "Conclusion" part of the document

  - Mar 19, 2008

There are also other free configuration tools available. OpenG (OpenG.org) and Moore Good Ideas (http://www.mooregoodideas.com/ReadWriteAnything.htm) both have tools that allow clusters and arrays to be written to configuration files. In fact, the palette screenshot shown above shows the author had the OpenG tools installed. There are probably other ini file tools out there as well. Disclaimer: I work for a company mentioned above, Moore Good Ideas.

  - Feb 23, 2006

http://zone.ni.com/devzone/cda/tut/p/id/3154 should be the correct link... the other link that is on the page doesn'quite match up

  - Dec 20, 2005

The docs says "An intermediate editor called "ConfigEditor" is included with example code linked at the end of this document", but no such link exists. Where can I find the example code?

What about support for complicated data types?  - Dec 15, 2005

It is sound very interesting. The only thing to add here is straight forward cluster and array support. That would be really generic package and much more useable. Writing key by key is quite difficult task, especially during development stage.

View more reviews

Bookmark & Share



Ratings

Rate this document

Answered Your Question?
Yes No

Submit