Additional Example 7: Using Waveform Channels
- Updated2024-09-12
- 3 minute(s) read
DataPlugin > Examples > Additional Example 7: Using Waveform Channels
Additional Example 7: Using Waveform Channels
The following example shows a DataPlugin for reading in the text file DataPlugin_AdditionalEx7.aex7. The DataPlugin script file is located at DataPlugin_AdditionalEx7.vbs
Data Format Description
This text file contains metadata and channel data. The metadata corresponds with a number of channel properties or group properties. When this information is saved, a row contains the name of a property in quotation marks and, separated by a semicolon, the value of this property.
Then the channel data follows: a date/time channel and a numeric channel. All channel data in the text file is separated by a semicolon. The specified numbers use a comma as the decimal symbol and E as the exponential sign. 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
-
Separators: Semicolon
-
Decimal symbol: Comma
-
Exponential character: E
-
Ignoring quotation marks and spaces
-
Checking file contents for specific keywords
-
Reading in the channel data which is stored in combination with a waveform channel
-
Defining waveform channel properties
Option Explicit Sub ReadStore(oFile) ' Set string formatter oFile.Formatter.LineFeeds = vbCrLf oFile.Formatter.Delimiters = ";" oFile.Formatter.DecimalPoint = "," oFile.Formatter.ThousandSeparator = "" oFile.Formatter.ExponentSeparator = "E" oFile.Formatter.TrimCharacters = " """ ' Create channel group object and set property Dim oChannelGroup : Set oChannelGroup = Root.ChannelGroups.Add(oFile.Info.FileName) Dim PropName, PropValue, iProp, ChnName Dim saPropName(13), saPropValue(13) PropName = oFile.GetNextStringValue(eString) PropValue = oFile.GetNextStringValue(eString) Call oFile.SkipLine() iProp = 0 Do While PropName <> "" Select Case PropName Case "Title" ChnName = PropValue Case "Date", "Time" Call oChannelGroup.Properties.Add(PropName, PropValue) Case Else saPropName(iProp) = PropName saPropValue(iProp) = PropValue iProp = iProp + 1 End Select PropName = oFile.GetNextStringValue(eString) PropValue = oFile.GetNextStringValue(eString) Call oFile.SkipLine() Loop ' Get object for block stored data Dim oBlock : Set oBlock = oFile.GetStringBlock() ' Import first channels with fast access ' First read dummy then read Y channel as waveform Dim oChn Set oChn = oBlock.Channels.Add("Dummy", eR64) Set oChn = oBlock.Channels.Add(ChnName, eR64) ' Add properties Dim oFormatter : Set oFormatter = oFile.Formatter Dim iLoop For iLoop = 0 to iProp-1 Select Case saPropName(iLoop) Case "X scale" Call oChn.Properties.Add("wf_increment", oFormatter.ParseString(saPropValue(iLoop),eR64)) Case "X at 0%" Call oChn.Properties.Add("wf_start_offset", oFormatter.ParseString(saPropValue(iLoop),eR64)) Case "X samples" Call oChn.Properties.Add("wf_samples", oFormatter.ParseString(saPropValue(iLoop),eI32)) Case "X unit" Call oChn.Properties.Add("wf_xunit_string", saPropValue(iLoop)) Case "X label" Call oChn.Properties.Add("wf_xname", saPropValue(iLoop)) Case Else Call oChn.Properties.Add(saPropName(iLoop),saPropValue(iLoop)) End Select Next ' Create wave form channel Call oChn.Properties.Add("wf_time_pref", "relative") ' Add defined channel to DIAdem channel group Call oChannelGroup.Channels.AddDirectAccessChannel(oChn) 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 linefeed character. The semicolon separates single values, the comma is the decimal symbol, and E is the exponential character. The DataPlugin ignores quotation marks and leading and trailing blanks.
The DataPlugin generates a new channel group whose name corresponds to the name of the file to be read in. Then the DataPlugin reads in the metadata rowwise and checks the data for certain keywords. The DataPlugin saves the information in two arrays: one array with the names of the properties and one array with the associated values.
The DataPlugin transfers the remaining file contents into a StringBlock. 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 limits of the value are specified by the Delimiter property, which in this case is the semicolon. The DataPlugin ignores the data of the first channel and saves the data of the second channel in a waveform channel. In order to generate a waveform channel, the DataPlugin checks the array with the previously read properties for certain keywords and transfers the associated values to the required waveform properties. The DataPlugin specifies the other properties as custom properties of the waveform channel.