ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Object-oriented channel referencing

Solved!
Go to solution

Hi,

 

I'm just getting used to object-oriented referencing and I'm finding it difficult to learn any shortcuts, not assisted by the highly confusing object model help pages (the page Internal Data > Objects seems exceptionally unhelpful). This is resulting in long-winded code, far longer than when using the previous variable set (ChD, CL, etc).

 

I understand that if there are channels present in the data file for significant time then it's wise to use a variable set to reference that channel using GetChannel. However, I have channels that existing for a fleeting moment so it's a waste of time to set variables to reference them just to extract a simple piece of information.

 

So, my question is, if MyChannel is unique and I know it's group name or index, then how do I reduce the following line of code: 

 

 

Data.Root.ChannelGroups(1).Channels(MyChannel).Size

 

 

 ...to something shorter and simpler, such as:

 

 

Channels(MyChannel).Size

 

 

I don't understand the need to have to use Data.Root.ChannelGroups(1) everytime I want to reference a temporary channel.

 

Edit: things are more complicated than I thought as my first line of code above doesn't actually work. I am now unable to find in the help pages a way of referencing a specific channel. What do I put after ChannelGroups(1) to reference a unique channel by it's name? Once the long version is established, is there a shorter version that can be used for temporary channel referencing?

 

Second Edit: I now find that using the following doesn't work:

Data.Root.ChannelGroups(1).Channels(2).Size

And nor does the following when MyChannel is a text variable with the value [1]/HW Chn:

Data.Root.ChannelGroups(1).Channels(MyChannel).Size

I'm totally baffled as to how to reference a specific and unique channel by name. All help gratefully received.

 

Thanks, Simon.

 

0 Kudos
Message 1 of 4
(2,999 Views)

Hi Simon,

I think what you are looking for is the method GetChannel. Please have a look on the help: http://zone.ni.com/reference/en-XX/help/370858P-01/inavidata/methods/diacmpnt_method_getchannel_inav...

Hope this helps.

Winfried

0 Kudos
Message 2 of 4
(2,976 Views)

Hi Winfried,

 

I'm afraid that's not what I'm after. In the early part of my post I said that I am familiar with GetChannel and understand it's benefits for long term channels. However, it's longwinded for momentary channels. So, I'm asking for the quickest/shortest reference to a channel that avoids setting a variable or using Data.Root.ChannelGroups.etc.etc.

 

Thanks.

0 Kudos
Message 3 of 4
(2,973 Views)
Solution
Accepted by topic author Simon_Aldworth

Hi Simon,

 

First of all, for fleeting channels where you know their name and which group they're in, there's no problem with continuing to use the older "GroupRef/ChanRef" string approach.  Also, ChnLength() still works, even with the object variable as the argument.  I find that there are corner case situations where ChnLength(Channel) is more accurate than Channel.Size, so I still use it.  Also, you can use ChnLength(Channel) to set the channel length, whereas Channel.Size is read-only.

 

That said, you absolutely CAN reference a particular Channel by passing its name in a string variable or string constant or its index as an integer, and I do strongly endorse using Channel objects over the older "GroupRef/ChanRef" paradigm in DIAdem VBScripts that manipulate data channels.  I also recommend creating a Group object variable so you (and the script engine) don't have to keep repeating the Data.Root.ChannelGroups(Ref) part of the code over and over again.  Here are 3 examples:

 

Dim Group, AngleChnName, AngleChn
AngleChnName = "Angle"
Set Group = Data.Root.ChannelGroups(1)
Set AngleChn = Group.Channels(AngleChnName)
Set AngleChn = Group.Channels("Angle")
Set AngleChn = Group.Channels(2)
MsgBox AngleChn.Name & " channel size = " & AngleChn.Size

 

Brad Turpin

Senior Technical Support Engineer

National Instruments

0 Kudos
Message 4 of 4
(2,918 Views)