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: 

ChnStatisticsChannelCalc

Solved!
Go to solution

Hi,

 

I am new to DIAdem and it has been a while since I have used VB Script. I have some channels that I want to find the Arithmetic Mean of and am trying to use ChnStatisticsChannelCalc to get the mean of one channel (will be done for many data sets) and then place it into another channel. Currently I have not managed to get any data into the channel. Any ideas where I am going wrong.

Thanks Hannah 

 

Option Explicit 'Forces the explicit declaration of all the variables in a script.

Dim Stat_Result

Call Data.Root.ChannelGroups(1).Channels.Add("Stat_Results",DataTypeChnFloat64)

Set Stat_Result = ChnStatisticsChannelCalc("[1]/TempAmb_Val",32,0,0,0,1,0,"IndexName")

 

0 Kudos
Message 1 of 3
(2,980 Views)
Solution
Accepted by topic author Hannah19

Hi Hannah, 

 

The argument description and list of the ChnStatisticsChannelCalc command is here - http://zone.ni.com/reference/en-XX/help/370858N-01/comoff/chnstatisticschannelcalc/

 

The Stats Selection is StatsArithmeticMean which is what you are looking for. However, the start index and the end index are both zero. I think that would from row 0 to row 0 so that would not read all the data. 

 

Does changing this change the result? 

 

Many Thanks, 

 

Riley Ilieva

 

Applications Engineer

National Instruments

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

Thanks Riley,

 

Thats has helped, I used recording mode to find ChnStatisticsChannelCalc and it had all of the options set to zero so the help initially confused me.

 

I managed to achieve want I wanted through this code, as I had not realised that the output is the channel name and not the value.

 

Thanks Hannah

 

Option Explicit 'Forces the explicit declaration of all the variables in a script.

 

Dim Stat_Result

Dim Result

Dim ChLen

 

Call Data.Root.ChannelGroups(1).Channels.Add("Stat_Result",DataTypeChnFloat64)

Set Stat_Result = Data.Root.ChannelGroups(1).Channels("Stat_Result")

 

ChLen = Data.GetChannel("[1]/TempAmb_Val").size

 

Result = ChnStatisticsChannelCalc("[1]/TempAmb_Val",32,1,ChLen,0,1,0,"OnlyName")

 

Stat_Result(1) = Data.GetChannel("/ArithmeticMean").Maximum

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