DIAdem Help

Example 2: ASCII File with Meta Information and Channel Data

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

Example 2: ASCII File with Meta Information and Channel Data

The following file shows you how to create a DataPlugin to read the ASCII file DataPluginExample2.ex2. This text file contains metadata and channel data. Refer to DataPluginExample2.vbs to open the DataPlugin script file.

 

Data Format Description

The file to be read contains a simple header and columns that contain channel values.

The header contains information about the measurement, followed by descriptions of the channels to be recorded. The columns with the channel values are separated by semicolons. A decimal point separates the integer and the decimal places.

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, DataPluginExample2.

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

    Enter the Filename, including the path and the filename extension, to specify the script that DIAdem uses to connect the DataPlugin, for example, DataPluginExample2.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, DataPluginExample2.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 DataPluginExample2.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. Outside the ReadStore procedure, define two text constants for the header identifier and the channel identifiers:

Const EndHeaderTag= "End Header"
Const ChannelTag  = "Channel"
  1. Inside the procedure, 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 colon as the separator between individual values and specify the time format. Skip the first line.

File.Formatter.LineFeeds        = vbNewLine
File.Formatter.IgnoreEmptyLines = true
File.Formatter.TrimCharacters   = " " 
File.Formatter.Delimiters       = ":"
File.Formatter.TimeFormat       = "DD.MM.YYYY hh:mm:ss"
File.SkipLine()

Reading Metadata

  1. When the File object is initialized, read in the general measurement information. Stop reading as soon as you reach a line with Channel or EndHeader, or at the end of the file.

    Transfer the read information to the data set properties.
    The data set and the associated channel groups and channels have properties. The properties include standard properties, for example, Name, and user-defined properties. Use the Properties.Add method to define a property. If the specified property exists, the method overwrites the previous value of the property.

    If you reach EndHeader or the end of the file before the Channel identifier occurs, the file does not contain any channel values. If this is the case, stop the ReadStore procedure.

Dim TagName, TagDescription
Do
  TagName       = File.GetNextStringValue(eString)
  TagDescription= File.GetNextStringValue(eString)
  File.SkipLine()
  If (TagName=ChannelTag) or (TagName=EndHeaderTag) or IsEmpty(TagName) Then Exit Do
  Call Root.Properties.Add(TagName, TagDescription)
Loop
If (TagName<>ChannelTag) Then Exit Sub

Reading the Channel Descriptions

  1. Outside the ReadStore procedure, define the following function, which converts the data type in the file to the data type of the properties:

Function TranslateType(TypeString)
  Select Case TypeString
    Case "I32"    TranslateType = eI32
    Case "R64"    TranslateType = eR64
    Case "Time"   TranslateType = eTime
    Case "String" TranslateType = eString
  End Select
End Function
  1. You now can read the channel descriptions from the file and generate channels. Because channels always belong to a channel group, create a new channel group first. Then transfer the remaining file contents to a StringBlock, to which you then assign the channels. Expand the ReadStore procedure as follows:

Dim ChannelGroup: Set ChannelGroup = Root.ChannelGroups.Add("Measurements")
Dim Block : Set Block = File.GetStringBlock()
  1. The file contains the channel descriptions. A channel description consists of the name and the data type of the channel.

    Use AddDirectAccessChannel to generate the channels according to the descriptions.

    Stop reading the properties as soon as you reach a line with EndHeader, or at the end of the file.

Dim TagType, Channel
Do
  File.SkipValue()
  TagDescription= File.GetNextStringValue(eString)
  File.SkipLine()
 
  File.SkipValue()
  TagType = TranslateType(File.GetNextStringValue(eString))
  File.SkipLine()
 
  Set Channel = Block.Channels.Add(TagDescription, TagType)
  ChannelGroup.Channels.AddDirectAccessChannel(Channel)
 
  TagName = File.GetNextStringValue(eString)
  File.SkipLine()
Loop Until (TagName=EndHeadertag) Or IsEmpty(TagName)

Displaying a Message when an Error Occurs

  1. If you reach the end of the file, the file does not contain channel values. Display an error message.

If IsEmpty(TagName) or (File.Position=File.Size) Then
  Call RaiseError("Reached the end-of-file, without finding the channel data.")
End If
  1. Change the delimiter to read out the channel data. Finally, specify the position in the StringBlock where the channel data reading starts.

    After the execution of GetStringBlock in step 7, the file pointer corresponds to the StringBlock of the current position of the file pointer. The StringBlock file pointer is positioned on the first channel description and must be positioned on the row with the channel data.

File.Formatter.Delimiters = ";"
Block.Position = File.Position
  1. Save the DataPlugin.

Making Additions to the DataFinder

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

  2. Click OK to close the dialog boxes.

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

Overview of the Methods and Properties Used

RaiseError

File.Formatter

Formatter.LineFeeds

Formatter.IgnoreEmptyLines

Formatter.TrimCharacters

Formatter.Delimiters

Formatter.TimeFormat

File.GetNextStringValue

File.SkipLine

File.SkipValue

File.GetStringBlock

StringBlock.Channels

DirectAccessChannels.Add

Root.Channelgroups

Root.Properties

Properties.Add

Channelgroups.Add

Channelgroup.Channels

Channels.AddDirectAccessChannel

Log in to get a better experience