From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I use block functions with a file that has channel names in the rows

Solved!
Go to solution

Hello,

 

I hope the title isn't too confusing, but I have data in the format shown below:

Chn_1    1      2      3      4      5

Chn_2    a      b      c      d      e

Chn_3    1.1   2.1   3.1   4.1   5.1

Chn_4    1      2      3      4      5

 

I want to be able to use the GetCellBlockor or GetStringBlock with this data, but it seems to require that the channel names are going across the columns instead of down the rows. 

Does anyone have a clean way grab these channel and add them with the correct data type to the data portal?

0 Kudos
Message 1 of 3
(2,284 Views)

Hello Kevin_McG, 

 

Would you mind posting how you are attempting to use these calls? I want to see if I can recreate something over here and mess around with the calls. 

 

Best, 

Danielle

0 Kudos
Message 2 of 3
(2,255 Views)
Solution
Accepted by Kevin_McG

There is no way to use the stringblock directly but you plugin code could look like this just using the build in parser to help.

Data

Chn_1    1      2      3      4      5
Chn_2    a      b      c      d      e
Chn_3    1.1   2.1   3.1   4.1   5.1
Chn_4    1      2      3      4      5

Plugin Code

Option Explicit

Sub ReadStore(File)
  File.Formatter.Delimiters = " "
  File.Formatter.LineFeeds = vbNewLine
  file.Formatter.TrimCharacters = " " ' trim the spaces
  File.Formatter.DecimalPoint = "."

  Dim ChannelGroup : Set ChannelGroup = Root.ChannelGroups.Add(File.Info.FileName)
  do
    dim channelName : channelName = File.GetNextStringValue(eString)
    if isEmpty(channelName) then
      RaiseError ' This file has a different format
    end if

    ' use the first value to determine the datatype of the channel
    dim channelValue : channelValue = File.GetNextStringValue(eString)
    dim channelDataType : channelDataType = eR64
    if(0 = file.Formatter.ParseString(channelValue,channelDataType) AND "" <> file.Formatter.ParseString(channelValue, eString)) then
      channelDataType = eString ' value is not numeric so we load it as string
    end if
    dim chO : set chO = ChannelGroup.Channels.Add(channelName,channelDataType)
    dim i : i = 1
    cho.Values(i) = file.Formatter.ParseString(channelValue,channelDataType)
'    ' add the remaining values by looping till the line is eaten
    channelValue = File.GetNextStringValue(channelDataType)
    do while NOT VBEMPTY = VarType(channelValue)
      i = i + 1
      cho.Values(i) = channelValue
      channelValue = File.GetNextStringValue(channelDataType)
    Loop
  Loop until NOT File.SkipLine
End Sub

 

0 Kudos
Message 3 of 3
(2,248 Views)