DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

How to read out the channel length??

Greets,
 
I've just tried to fill one channel with predefined values.  I've used a FOR .. TO loop to do this.  Then I wanted to set the length of the loop to be as long as the length of the previous channel in the same group.  I've tried to read out the previous channel length with Root.ChannelGroups(1).Channels(CNo("/NewChannel")-1)).Properties.Length and it didn't work.  It showed me an error:  "Root variable not defined" ?!  What's wrong??  How to read out the channel length??
 
Thanks in advance, Hristo
 
0 Kudos
Message 1 of 4
(7,782 Views)

Hi Hristo,

I'd recommend you try the age-old function ChnLength(CNo("/NewChannel")), although you could add additional error checking that might have uncovered the source of the trouble in your original code:

ChNum = CNo("/NewChannel")
IF ChNum = 0 THEN Call AutoQuit("Could not find channel '/NewChannel'")
ChLen = ChnLength(ChNum)

Brad Turpin
DIAdem Product Support Engineer
National Instruments

0 Kudos
Message 2 of 4
(7,771 Views)
Hello Brad,  thanks for the answer, it works with ChnLength.  Funny, but if you're searching in Diadem Help for "channel length" or "length" only, it doesn't show you this function, even if it is ancient 🙂 !!  Anyway, I still cann't realize why the other method didn't work?!  How can I access the Root object tree?!  Cheers, Hristo
0 Kudos
Message 3 of 4
(7,747 Views)

Hi Hristo,

I think the error code you're getting is misleading.  What the error should say is something like "The channel index parameter is invalid".  The trouble arises because there is a difference between the global channel number that CNo() returns and the group-relative channel index that is pertinent in the Channels collection.  If you only have 1 group, and if the channels were created in order and never moved, then these two properties "Channel.Number" and "Channel.GroupIndex" are in fact the same for each channel.  As soon as you have a second group, though, its first channel has Channel.GroupIndex = 1, and this is not equal to its Channel.Number property, which is > 1.  I also missed the "-1" in your original code post-- you want to reference the channel BEFORE the "NewChannel".  So, you first need to get the group-relative channel index of the "NewChannel", then reference the channel immediately previous to that channel, like this:

ChIdx =

Data.Root.ChannelGroups(GroupDefaultGet).Channels("NewChannel").Properties("groupindex").Value
ChLen = Data.Root.ChannelGroups(GroupDefaultGet).Channels(ChIdx-1).Properties("length").Value

Ask if you have further questions,
Brad Turpin
DIAdem Product Support Engineer
National Instruments

0 Kudos
Message 4 of 4
(7,736 Views)