DIAdem Help

Example 1: Text File with Metadata

  • Updated2024-09-12
  • 4 minute(s) read

Example 1: Text File with Metadata

The following file shows you how to create a DataPlugin to read the text file DataPluginExample1.ex1. This text file contains only metadata. Refer to DataPluginExample1.vbs to open the DataPlugin script file.

 

Data Format Description

The first line of the file to be read contains the name of the measurement.

The next line contains the description of an implicit channel, consisting of the channel name, the first channel value, the step width between the channel values, and the number of channel values. The entries are separated by semicolons. The numbers have a point as the separator for thousands.

The channel description is followed by a list of names and values of data set properties. The entries are separated by colons.

The empty lines in the file and the leading and trailing blanks are irrelevant. The end of the line is indicated by Carriage Return and Line Feed.

The following graphic illustrates this format:

Configuring a DataPlugin

  1. Select Settings»Extensions»DataPlugins in DIAdem NAVIGATOR.

  2. Click Create DataPlugin to configure a new DataPlugin.

  3. A dialog box opens where you can define the parameters for the new DataPlugin.

    Enter the Name of the DataPlugin, for example, DataPluginExample1.

    Under filename extensions, enter a list of file types that the DataPlugin can access, for example, *.ex1.

    Enter the Filename, including the path and the filename extension, to specify the script that DIAdem uses to connect the DataPlugin, for example, DataPluginExample1.vbs. Click ... to specify the script in a file selection dialog box. If you enter the name of a script that does not exist, DIAdem generates the script.


    Use Icon to specify the name, including the path and the filename extension, of the symbol file to which DIAdem links the DataPlugin, for example, DataPluginExample1.ico. Click ... to specify the symbol file in a file selection dialog box.

  4. Click OK.

  5. The new DataPlugin is included in the list of DataPlugins. Close the dialog box.

Note  You also can select Settings»Extensions»DataPlugins in DIAdem NAVIGATOR or in DIAdem SCRIPT to import, to export, to modify, or to delete an existing DataPlugin.

You can now start programming the DataPlugin.

Creating the DataPlugin

  1. Open the DataPluginExample1.vbs script in the script editor.
    The script contains an example. USI uses the prepared procedure ReadStore to read the contents of the specified file File. The File parameter contains the opened file, which you selected in the DataFinder.

  2. Delete the contents of the ReadStore procedure until only the following lines remain:

Option Explicit
Sub ReadStore(File)
End Sub

Providing Information about the Text File

  1. Use the File object to specify the general file format. Use the VBS constant vbNewLine as the linefeed character. Ignore the empty lines and the blanks outside the text. Specify a semicolon as the delimiter between single values and a point as the delimiter for thousands.

File.Formatter.LineFeeds        = vbNewLine
File.Formatter.IgnoreEmptyLines = true
File.Formatter.TrimCharacters   = " " 
File.Formatter.Delimiters       = ";"
File.Formatter.ThousandSeparator= "."

Reading Single Texts

  1. Use GetNextStringValue to read from the file the text that contains the name of the measurement. Because the statement does not extend past the end of the line, you must then position the file pointer in the next line.

Dim TitleValue : TitleValue = File.GetNextStringValue(eString)
File.SkipLine()
  1. The next line contains the description of the implicit channel. Use GetNextStringValue to read the name, the start value, the step width, and the number of values.

Dim ChannelName: ChannelName = File.GetNextStringValue(eString)
Dim StartValue : StartValue  = File.GetNextStringValue(eI32)
Dim Increment  : Increment   = File.GetNextStringValue(eI32)
Dim ChannelSize: ChannelSize = File.GetNextStringValue(eI32)
  1. Change the separator for reading out the data set properties:

File.Formatter.Delimiters = ":"
  1. Now read in the data set properties, each of which consists of a name and a value. The data set properties are in lines and go to the end of the file.

Dim PropertyName, PropertyValue
While (File.Position <> File.Size)
  File.SkipLine()
  PropertyName = File.GetNextStringValue(eString)
  PropertyValue= File.GetNextStringValue(eString)
Wend

Creating and Setting Properties

  1. You have read all the information from the file. You now must transfer this information to the Root object of the data set.

    The data set and the associated channel groups and channels have properties. The properties include base properties, for example, Title, as well as user-defined properties. Use Properties.Add to define a property. If the specified property exists, the statement overwrites the previous value of the property.

    Insert the following statement after the first GetNextStringValue statement, to specify the name of the measurement:

Call Root.Properties.Add("Title", TitleValue)
  1. After the name and the value of a property have been read, add this line inside the While loop:

Call Root.Properties.Add(PropertyName, PropertyValue)

Creating an Implicit Channel

  1. Create an implicit channel with the information that has been read in.
    Because a channel always belongs to a channel group, you create the group first and then use AddImplicitChannel to generate the implicit channel.

Dim ChannelGroup : Set ChannelGroup = Root.ChannelGroups.Add("MyChnGroup")
Call ChannelGroup.Channels.AddImplicitChannel(ChannelName, StartValue, Increment, ChannelSize, eI32)
  1. Save the DataPlugin.

Making Additions to the DataFinder

  1. Select Settings»DataFinders»Properties»DataPlugins in DIAdem NAVIGATOR and enable the DataPluginExample1 DataPlugin.

  2. Click OK to close the dialog boxes.

In the DataFinder you now can navigate in the DataPluginExample1.ex1 file and drag and drop the channels into the DIAdem Data Portal.
 

Overview of the Methods and Properties Used

File.Formatter

Formatter.LineFeeds

Formatter.IgnoreEmptyLines

Formatter.TrimCharacters

Formatter.Delimiters

Formatter.ThousandSeparator

File.GetNextStringValue

File.SkipLine

Root.Properties

Properties.Add

Property.Name

Property.Value

Root.Channelgroups

Channelgroups.Add

Channels.AddImplicitChannel

Log in to get a better experience