DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Can't open a txt-file with the generated plugin

Hello,

 

I've got some data in an txt-file like this.

ID=210
Version=1.5
Pretrigger=0
Posttrigger=9
SampleRate=1e+04
...
DataType=Text
DataStart=68
+5,5934e-01    +3,7008e-01    +1,4520e-05    +5,8064e-06
+5,5935e-01    +3,7009e-01    +1,0854e-04    +5,1823e-05
+5,5937e-01    +3,7010e-01    +3,9940e-04    +2,2776e-04
+5,5939e-01    +3,7010e-01    +9,8879e-04    +6,5642e-04

Well, the 4 rows with the measurement-data starts in line 53. Theres no problem using the assistant to read in the 4 rows to channels. With the config-file I can save my setting. So I decided to create an plugin with the plugin-assistant, which appears before importing the data.

But it doesn't work. I can't open the same file with the generated plugin. I guess theres no comment in the vbs-script to begin at line 53. But when I skip the first lines by File.SkipLines(NumberToSkip) it doesn't help.

 

Can anyone help me: Heres the generated code from the plugin.

 

Thanks

Gabriel

 

 Option Explicit

Sub ReadStore(File)

   ' Set the file format
   File.Formatter.TrimCharacters = " "
   File.Formatter.Delimiters = vbTab
   File.Formatter.TimeFormat = "MM/DD/YYYY hh:mm:ss"
   File.Formatter.LineFeeds = vbNewLine
   File.Formatter.CommentSign = "#"
   File.Formatter.CharacterFormat = eANSI
   File.Formatter.IgnoreEmptyLines = TRUE
   File.Formatter.ExponentSeparator = "e"
   File.Formatter.DecimalPoint = ","
   
   File.SkipLines(1)

   Dim ChnNum : ChnNum = GuessChnCount(File)

   Dim ChnType : ChnType = GetChnType(ChnNum)
   If IsArray(ChnType) Then ReDim Preserve ChnType(ChnNum)

   ' Define the channel group
   Dim ChnGroup : Set ChnGroup = Root.ChannelGroups.Add(File.Info.FileName)

   ' Define the block
   Dim Blk : Set Blk = File.GetStringBlock()

   ' Here create the channels
   Dim Chn
   Dim Index
   For Index=0 To ChnNum-1
     If ChnType(Index) <> "Ignore" Then
       If ChnType(Index) = eNoType Then
         Set Chn = Blk.Channels.Add("Chn", eString)
       Else
         Set Chn = Blk.Channels.Add("Chn", ChnType(Index))
       End If

       Call ChnGroup.Channels.AddDirectAccessChannel(Chn)
     End If
   Next

End Sub

'---------------------------------------------------------------------
' Function to get a single line of attributes.
'---------------------------------------------------------------------

Function GetInfoFromFile(oFile, iSkips, eDataType, bGetWholeLine)
   Dim Value(), Temp
   Dim Index
   GetInfoFromFile = NULL
   Index = -1
   If ( bGetWholeline ) Then
     oFile.SkipLines(iSkips-1)
     GetInfoFromFile = oFile.GetNextLine
   Else
     oFile.SkipLines(iSkips-1)
     Do
       Temp = oFile.GetNextStringValue(eDataType)
       If ( IsEmpty(Temp) ) Then Exit Do
       If ( Temp <> "" ) Then
         Index = Index + 1
         ReDim Preserve    Value(Index+1)
         Value(Index) = Temp
       End If
     Loop
     GetInfoFromFile = Value
     oFile.SkipLine()
   End If
End Function

'---------------------------------------------------------------------
' Function to calculate the number of channel in the file. The current file
' pointer is positioned to point on the first line of the channel data.
'---------------------------------------------------------------------

Function GuessChnCount(File)
   Dim CurrPos, K, nColumns, Tokens
   GuessChnCount = 0

   CurrPos = File.Position

   ' count columns in the next few lines
   For K=1 To 10
     ' use ParseTokens to count columns
     Tokens = ParseTokens(File, eString)
     If ( IsArray(Tokens) ) Then
       nColumns = uBound(Tokens)
     Else
       nColumns = 0
     End If

     ' use maximum number of columns
     If ( GuessChnCount < nColumns ) Then GuessChnCount = nColumns
     If ( File.Position >= File.Size ) Then
        Exit For
     End If
   Next
   ' restore file pointer
   File.Position = CurrPos
End Function

'---------------------------------------------------------------------
' Function to parse a single line of attributes
'---------------------------------------------------------------------

Function ParseTokens(File, eDatatype)
   Dim Token(), nToks, CurrToken, Index
   ReDim Token(0)
   ParseTokens = NULL
   Index = -1
   Do
     CurrToken = File.GetNextStringvalue(eDatatype)
     If ( IsEmpty(CurrToken) ) Then Exit Do
     If ( CurrToken <> "" ) Then
       Index = Index + 1
       ReDim Preserve Token(Index+1)
       Token(Index) = CurrToken
     End If
   Loop
   File.SkipLine()
   ParseTokens = Token
End Function

'---------------------------------------------------------------------
' Function to get the channel type from STP file
'---------------------------------------------------------------------

Function GetChnType(ChnNum)
   Dim ChnType(), K
   ReDim ChnType(ChnNum)
   For K=0 To ChnNum-1
     ChnType(K) = eR64  ' initialize with default type
   Next
   ChnType(0) = eR64
   ChnType(1) = eR64
   ChnType(2) = eR64
   GetChnType = ChnType

End Function

 

0 Kudos
Message 1 of 6
(4,739 Views)

Hi Gabriel,

 

I think with enough patience one could get the ASCII DataPlugin Wizard to create a DataPlugin that would work for your file, but the resulting code generated by the wizard is not easily understandable, and it would not have correctly devined the sampling rate from your file format.  I've written a DataPlugin from scratch which correctly reads the data snippet you sent over.  I included an implicit time channel so that you could easily see the time values inferred from the "SampleRate" line.  The implicit time channel rerquires all the lines in the ASCII file to be parsed in order to figure out the correct channel length (line 58), so if you have large data files you should comment out the time channel lines (44, 45, 58) and use just the implict time information already encoded in the data channel waveform properties (for faster file indexing).  Unless your files are verry large, though, I think you'll like the DataPlugin as it is.

 

Brad Turpin
DIAdem Product Support Engineer
National Instruments

0 Kudos
Message 2 of 6
(4,714 Views)

Hi Again,

 

I posted an earlier version by mistake which did not create waveform channels.  Here's the latest version.

 

Brad Turpin
DIAdem Product Support

0 Kudos
Message 3 of 6
(4,712 Views)

Hi fischerg,

 

I want to help but let me understand your problem first. So, I tried to reproduce your case. I wrote a txt-file with same structure as yours, even took your values. Then I registered the dataplugin and wrote down your code in the vbs-file.

So, next time I wanted to load this txt-file the ascii-import-assistent appeared. I've just clicked on finish (not on next) and saw the channels in the data portal.

On which step do you become confused?

 

By the way, did you already checked the DataPlugins reference guide?

http://zone.ni.com/devzone/cda/epd/p/id/4822

 

Maybe there are some hints for you?

 

Waiting on your answer,

Sergei

0 Kudos
Message 4 of 6
(4,711 Views)

Hello Brad Turpin,

 

Thanks for your Plugin. Creating woveforms is exact what i wanted to do the next step. But unfortunaly it doesn't work exact. Your Plugin only creates one waveform channel.I attached a file with an measurement, maybe you have an idea why this happens.

 

Thanks

Gabriel

0 Kudos
Message 5 of 6
(4,614 Views)

Hi Gabriel,

 

The data file snippet you posted was space-delimited, whereas the file you attached was tab-delimited.  I'm going to assume that you only want a DataPlugin for tab-delimited files.  I also moved the channel-specific properties in the data file down to the channel level in the Data Portal (they were stuck on the Root/File and Group levels before).

 

Brad Turpin
DIAdem Product Support Engineer
National Instruments

0 Kudos
Message 6 of 6
(4,604 Views)