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: 

DataPlugin: how to read one line of channel names or units?

Solved!
Go to solution

Most of the examples for DataPlugin programming use channel names in separate lines, like the following example:

Channel
Name: Time
Type: Time

Channel
Name: XShift
Type: R64

Channel
Name: YShift
Type: R64

 

Most of my data sets have channel names and / or units in one tab-separated line such as

 

"Dehnung" "Standardkraft" "Sensor" "Zyklusnummer" "PWM"

"mm" "N" "V" "" "%"

 

Is there a more efficient way of adding channels named and equipped with units as per these lines than cycling through some index variable? As my channel number, naming etc. vary frequently, I'd be looking for a more flexible solution, avoiding fixed array sizes or hard-coded names.

 

I suppose

 

aMyChannelNames = split(File.GetNextStringValue(eString), vbTab)

aMyChannelUnits = split(File.GetNextStringValue(eString), vbTab)

for i = 0 to UBound(aMyChannelNames)

    Set Channel = Block.Channels.Add(aMyChannelNames(i),eString)

    channel.porperties("Unit")=aMyChannelUnits(i)

next

 

might do the job - but is this the most efficient way?

Thank you for assisting.

Michael

 

0 Kudos
Message 1 of 3
(4,921 Views)
Solution
Accepted by topic author nimic

Hello Michael,

 

I don't see the real problem.

 

You read the header and split it into an array. This is the information how many channels you have. The array size ubound depends on the line you've red and isn't fix. Everything should be fine now.


You first read hte information and split it to arrays. Afterwards you use a loop to generate the channels and set the properties. I don't think there's a more efficient way to do this.

 

Kind Regards,

 

Philipp K.

AE | NI Germany

0 Kudos
Message 2 of 3
(4,904 Views)

Hi Michael,

 

I prefer to use Split() in exactly the way you mentioned.  You could also try File.GetNextStringValue() if you prefer, just don't forget to call File.SkipLine() or you won't ever move the file cursor to the next line, which File.GetNextLine() does automatically.

 

Brad Turpin

DIAdem Product Support Engineer

National Instruments

0 Kudos
Message 3 of 3
(4,887 Views)