DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Channel references in functions

Solved!
Go to solution

Hi,

 

In my quest to understand the benefits of object-orientated references I'd like to know if there's a better way of doing the following.

 

In using DIAdem functions I find that I need to reference channels by name and also their properties. For example, the Find function typically needs a channel name as part of a condition and may also need a value to use in that condition. That value might come from a channel property, so a typical Find function I would use, in old language, is something like:

 

L1 = Find("Ch(""Angle"") = ChnValMax(""Angle"")")

 

Following the various updates to the language, I am now using GetChannel to define a variable as a channel, and this results in the following equivalent line:

 

L1 = Find("Ch(""" & AngleChn.GetReference(eRefTypeIndexName) & """) = " & AngleChn.Maximum)

 

Further, when using functions like ChnStatisticsChannelCalc I now have to write AngleChn.GetReference(eRefTypeIndexName) in place of just the channel name.

A work around is to use GetChannel so that the channel properties can be accessed, such as Maximum, and also define a text variable that holds just the channel name for use in function strings. So, for example, I would end up with:

 

Dim AngleChn, AngleChnTxt
T1 = "[1]/Angle"
Set AngleChn = Data.GetChannel(T1)
AngleChnTxt = T1

L1 = Find("Ch(""" & AngleChnTxt & """) = " & AngleChn.Maximum)

 

This keeps the Find function short and readable, but is this good coding or am I missing something?

 

Regards, Simon.

0 Kudos
Message 1 of 2
(2,417 Views)
Solution
Accepted by topic author Simon_Aldworth

Hi Simon,

 

I recommend you switch from the old Find() function to the new ChnFind() function, which has additional parameters to enable you to pass in formula variable symbols of your choosing and clean channel or value referencing that attaches to those variables, straight from the channel object variable you've already got.

 

Dim AngleChn, VarSymbols, VarValues
T1 = "[1]/Angle"
Set AngleChn = Data.GetChannel(T1)
VarSymbols = Array("Angle", "MaxVal")
VarValues = Array(AngleChn, AngleChn.Maximum)
L1 = ChnFind("Angle >= MaxVal", 1, VarSymbols, VarValues)

 

Brad Turpin

Senior Technical Support Engineer

National Instruments

Message 2 of 2
(2,380 Views)