DIAdem Help

Additional Example 5: Using Processed Channels

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

Additional Example 5: Using Processed Channels

The following example shows a DataPlugin for reading in the text file DataPlugin_AdditionalEx5.aex5. The DataPlugin script file is located at DataPlugin_AdditionalEx5.vbs 

Data Format Description

This text file contains metadata and channel data. The metadata has three lines. The first line contains an identifier, the second line contains the channel names, and the third line contains the associated channel units.

Then the channel data follows: a date/time channel and a number of numeric channels. The settings in the text file are separated by a tabulator. The specified numbers use a point as the decimal symbol. The end of the line is indicated by Carriage Return and Line Feed. Any empty rows are irrelevant.

Special Features of the DataPlugin

  • Line feed: CrLf

  • Ignoring spaces

  • Separators: <Tab>

  • Checking file contents for a specific keyword

  • Reading in channel data. The date and time information is stored together in one channel.

  • Using a Processed Channel


Option Explicit 
Sub ReadStore(oFile)
  oFile.Formatter.LineFeeds        = vbCrLf
  oFile.Formatter.IgnoreEmptyLines = True  
  oFile.Formatter.Delimiters       = vbTab
  oFile.Formatter.DecimalPoint     = "."
  oFile.Formatter.TimeFormat       = "DD/MM/YYYY hh:mm:ss"

  ' Check whether selected file is known
  Dim sCurrLine : sCurrLine = uCase(oFile.GetNextLine)
  If not (InStr(sCurrLine, "XYZ") > 0) Then Call RaiseError("Not a known file.")

  Dim oChnGroup : Set oChnGroup = Root.ChannelGroups.Add(oFile.Info.FileName)
  Call oChnGroup.Properties.Add("description", Replace(sCurrLine, vbTab, ""))

  ' Read all channel names
  Dim saChnName : saChnName = Split(oFile.GetNextLine, vbTab)

  ' Read all channel units
  Dim saChnUnit : saChnUnit = Split(oFile.GetNextLine, vbTab)

  ' Create a file accessor
   Dim oBlock: Set oBlock = oFile.GetStringBlock()

  ' Create dummy channels because of data time
  Dim oChnD : Set oChnD = oBlock.Channels.Add("Date", eTime)
  Dim oChnT : Set oChnT = oBlock.Channels.Add("Time", eTime)
  Dim oPChn : Set oPChn = oChnGroup.Channels.AddProcessedChannel("DataTime", eTime, eAddProcessor)
  Call oPChn.Channels.Add(oChnD)
  Call oPChn.Channels.Add(oChnT)

  Dim iLoop, oChn
  For iLoop = 2 to UBound(saChnName)
    Set oChn = oBlock.Channels.Add(saChnName(iLoop), eR64)
    If saChnUnit(iLoop) <> "?" Then
      oChn.Properties.Item("unit_string").Value = saChnUnit(iLoop)
    End If
    'Provide the data to USI
    Call oChnGroup.Channels.AddDirectAccessChannel(oChn)
  Next
End Sub

DataPlugin Description

The DataPlugin first specifies the general format of the file through the File object. The DataPlugin uses the VBS constant vbCrLf as the word-wrap and ignores spaces which are not within the text. The VBS constant vbTab separates single values. A point is the decimal symbol.

The DataPlugin uses the GetNextLine function to read in the first line of the text file and checks whether the line contains the keyword XYZ. If this is not the case, the DataPlugin cancels the loading process with an error message. Then the DataPlugin generates a new channel group whose name corresponds to the name of the file to be read in. The DataPlugin saves the contents of the first read in line as a short description in the channel group.

The second line contains the name for every channel and the third line contains the channel unit. The DataPlugin reads in this data, uses the Split function to check the data for the separator vbTab, and stores the substrings in a one-dimensional, zero-based array. The number of arrays specifies the number of channels that the file contains.

The DataPlugin transfers the remaining file contents into a StringBlock. A Processed channel, which combines the values of the date channel and the values of the time channel in one channel, imports the date and time data.

If DirectAccess channels are associated with a StringBlock, the order of the values in a row determine which value belongs to which channel. The first value of the row belongs to the first channel, the second value of the row belongs to the second channel and so on. The value limits are specified by the Delimiter property, which in this case is vbTab. As the date and time data is already read in, the DataPlugin only creates new DirectAccess channels for the remaining channels and assigns these channels to the new channel group.

Log in to get a better experience