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: 

Determine if a channel is monotonic (increasing specifically)

Solved!
Go to solution

I'm sure I'm doing this horribly wrong, but I don't know really anything about the available functionality, so I'll ask here.

I'd like to know if a given Channel is monotonic.

DIAdem already displays this information in the "Other" information section, under "Monotony". I don't appear to be able to read that value as a property (it's greyed out - perhaps this has some special meaning).

A naive (working) implementation is as follows:

 

For Each gr In oAllGroups
  isMonotonic(index) = True
  Set oCh = gr.Channels("ChannelNameHere")
  Dim innerIdx, delta
  For innerIdx = 1 To oCh.Size-1
    delta = oCh.Values(innerIdx+1) - oCh.Values(innerIdx)
    If delta <= 0 Then
      isMonotonic(index) = False
    End If
  Next
  Call MsgBoxDisp(isMonotonic(index))
  index = index + 1
Next

but of course this is dreadfully slow (and only checks increasing monotonically - presumably the property also allows decreasing).

Probably use of a Break would speed this up (since I can stop checking once I find a step down).

 

Is there some built-in function that can accomplish this much more quickly?

The channel isn't evenly spaced, but it should be monotonic (so I expect in general the box to display TRUE, and the check when done in this manner to require ch.Size number of checks...)


GCentral
0 Kudos
Message 1 of 3
(2,590 Views)
Solution
Accepted by topic author cbutcher

If you see a property in DIAdem portal, you can drag and drop it into script to get a script line to read it.

Data.Root.ChannelGroups(1).Channels("Time").Properties("monotony").Value

The greyed out just means it is not writable.

dim chO : set chO = data.Root.ChannelGroups(1).Channels(1)
Call ChnCharacter(chO) ' calculate characteristics it
LogFileWrite chO.Properties("monotony").Value

ChnCharacter or ChnCharacterAll can be used to make sure that the characteristic values are calculated.

Message 2 of 3
(2,569 Views)

'Call LogFileWrite("bChnMonotonyIsIncreasing() = " & bChnMonotonyIsIncreasing(Data.Root.ChannelGroups(1).Channels(1)))

 

Dim oChn
For Each oChn In Data.Root.ChannelGroups(1).Channels
Call LogFileWrite("bChnMonotonyIsIncreasing(" & oChn.Name & ") = " & bChnMonotonyIsIncreasing(Data.Root.ChannelGroups(1).Channels(1)))
Next

 

Function bChnMonotonyIsIncreasing(ByVal oChn)
'Returns TRUE if the monotonony of oChn is increasing.
bChnMonotonyIsIncreasing = False
If Not IsObject(oChn) Then Call Err.Raise(65535,,"ERROR - object of type channel expected")
Call ChnCharacter(oChn)
If Not oChn.Properties.Exists("monotony") Then Exit Function
If StrComp(oChn.Properties("monotony").Value,"Increasing",vbTextCompare) = 0 Then bChnMonotonyIsIncreasing = True
End Function 'bChnMonotonyIsIncreasing()

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