Company Events Academic Community Support Solutions Products & Services Contact NI MyNI

Creating Configuration Files

LabVIEW 2010 Help

Edition Date: June 2010

Part Number: 371361G-01

»View Product Info

Use the Configuration File VIs to read and create standard Windows configuration settings (.ini) files and to write platform-specific data, such as paths, in a platform-independent format so that you can use the files these VIs generate across multiple platforms. The Configuration File VIs do not use a standard file format for configuration files. While you can use the Configuration File VIs on any platform to read and write files created by the VIs, you cannot use the Configuration File VIs to create or modify configuration files in a Mac OS X or Linux format.

Refer to the labview\examples\file\config.llb for examples of using the Configuration File VIs. 

Note  The standard extension for Windows configuration settings files is .ini, but the Configuration File VIs work with files with any extension, provided the content is in the correct format.

Using Configuration Settings Files

A standard Windows configuration settings file is a specific format for storing data in a text file. You can programmatically access data within the .ini file easily because it follows a specific format.

For example, consider a configuration settings file with the following contents:

[Data]

Value=7.2

You can use the Configuration File VIs to read this data, as shown in the following block diagram. This VI uses the Read Key VI to read the key named Value from the section called Data. This VI works regardless of how the file changes, provided the file remains in the Windows configuration settings file format.

Windows Configuration Settings File Format

Windows configuration settings files are text files divided into named sections. Brackets enclose each section name. Every section name in a file must be unique. The sections contain key/value pairs separated by an equal sign (=). Within each section, every key name must be unique. The key name represents a configuration preference, and the value name represents the setting for that preference. The following example shows the arrangement of the file:

[Section 1]

key1=value

key2=value

[Section 2]

key1=value

key2=value

Use the following data types with Configuration File VIs for the value portion of the key parameter:

  • String
  • Path
  • Boolean
  • 64-bit double-precision floating-point numeric
  • 32-bit signed integer
  • 32-bit unsigned integer

To use the Configuration File VIs, you must format each line of text in an .ini file correctly. A line must either be empty or contain a section name, a key-value pair, or a comment.

Use the following guidelines to format lines with section names:

  • Include at least one character
  • Do not use a closed bracket as part of the name
  • Do not include unprintable characters
  • Use an open bracket for the first non-whitespace character
  • Use a closed bracket at the end of the line of text
  • Keep all the characters on one line

Use the following guidelines to format lines with key-value pairs:

  • Include pairs on the lines after the section line
  • Include an equal sign after the key name
  • Keep all the characters on one line
  • Use valid key names
    • Include at least one character
    • Do not start with a semicolon
    • Do not include an equal sign
    • Do not start with an open bracket
    • Do not start with a whitespace character
    • Do not end with a whitespace character
    • Do not include unprintable characters
  • Use valid value names
    • Keep the data type consistent
    • Do not start with a whitespace character
    • Do not end with a whitespace character
Note  If values begin or end with whitespace characters, you must put the values in quotation marks. LabVIEW removes the quotation marks when a VI returns the value.

Configuration File VIs ignore lines without section names or value-key pairs during a read operation, and they preserve lines without section names or value-key pairs during a write operation.

When VIs write to a configuration file, they place quotation marks around any string or path data. LabVIEW also supports single quotes around values in .ini files.

The accepted comment notation for configuration files is a semicolon, which can indicate that the text following the semicolon is a comment. A semicolon at the beginning of a line indicates a comment. A semicolon in a section name, numeric value, or Boolean value also indicates a comment. However, a semicolon in a string value name does not indicate a comment.

If you include a semicolon as the first character of a key name, LabVIEW does not return a key name or value because the configuration files do not support a semicolon as the first character of a key name. If you include a semicolon at any other place in the key name besides as the first character, LabVIEW returns the key name with the semicolon.

The following table provides examples of how the Configuration File VIs read section names in .ini files.

Example text in .ini file Section name
[sec1] sec1
[[sec2]] [sec2
[   sec with spaces   ]    sec with spaces   
[seccom] ;comments seccom
[sectext]  sometext sectext

The following table provides examples of how the Configuration File VIs read key-value pairs in .ini files.

Example text in .ini file Key name Value
keyname='mystring' keyname mystring
;keyname="mystring"
keyname="my;string" keyname my;string
keyname = 12.3 ;comm keyname 12.3
key;name="mystring" key;name mystring
key\;name="my;string";more key\;name "my;string";more
key name6=" mystring6" key name6 mystring6
keyname8   =   mystring8 keyname8 mystring8
keyname9  =  "  mystring9  " keyname9   mystring9  
keyname12==mystring12 keyname12 =mystring12
#keyname13 = mystring13 #keyname13 mystring13
abc= abc
abc
Note  Because the Read Key VI is a polymorphic VI, it acts differently in certain instances. For example, for the keyname = 12.3 ;comm key-value pair, the String instance returns a string value of 12.3;comm and the Double instance returns a numeric of 12.3 for the value output.

The Configuration File VIs can read and write raw or escaped string data. The VIs read and write raw data byte-for-byte, without converting the data to ASCII. In converted, or escaped, strings LabVIEW stores any non-displayable text characters in the configuration settings file with the equivalent hexadecimal escape codes, such as \0D for a carriage return. In addition, LabVIEW stores backslash characters in the configuration settings file as double backslashes, such as \\ for \. Set the read raw string? or write raw string? inputs of the Configuration File VIs to TRUE for raw data and to FALSE for escaped data.

LabVIEW stores path data in a platform-independent format, the standard Linux format for paths, in .ini files. The VIs interpret the absolute path /c/temp/data.dat stored in a configuration settings file as follows:

  • (Windows) c:\temp\data.dat
  • (Mac OS X) c:temp:data.dat
  • (Linux) /c/temp/data.dat

The VIs interpret the relative path temp/data.dat as follows:

  • (Windows) temp\data.dat
  • (Mac OS X) :temp:data.dat
  • (Linux) temp/data.dat

 

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
Add Comments 1 2 3 4 5 submit