7 Replies Latest reply on Apr 30, 2016 7:07 AM by anupam

    How to get 15 minute average value of a tag in vb.net code

    anupam

      I am accessing my PI Server to get the snapshot value of my PI tag. But my requirement is to show 15 minutes average value of that tag. I have declared a tag ptavg of type PISDK.PIValue and used the code listed below to fetch the 15 minute average values:

       

      ptavg =  pt.Data.Summary('*-1d','*',ArchiveSummariesTypeConstants.asAverage,CalculationBasisConstants.cbTimeWeighted,'15m')

       

      Kindly help.

       

       

       

        • Re: How to get 15 minute average value of a tag in vb.net code
          bpayne

          Hello Anupam,

          Please be aware that the PISDK is soon to be deprecated. If this is a new application, I suggest you research migrating to PI AF SDK. With that said, You can find documentation on "Using the PI-SDK with Microsoft Dot Net" here.

           

          Butch

          • Re: How to get 15 minute average value of a tag in vb.net code
            gregor

            Hello Anupam,

             

            Since we strongly recommend using AF SDK for recent development, please see below AF SDK based example.

             

            using OSIsoft.AF;
            using OSIsoft.AF.PI;
            using OSIsoft.AF.Asset;
            using OSIsoft.AF.Time;
            using OSIsoft.AF.Data;
            namespace qAvg
            {
                class Program
                {
                    static void Main(string[] args)
                    {
                        PIServer srv = new PIServers()["PIserver"];
                        PIPoint pt = PIPoint.FindPIPoint(srv, "SINUSOID");
                        AFTime eTime = AFTime.NowInWholeSeconds;
                        AFTime sTime = eTime.LocalTime.AddMinutes(-15);
                        AFTimeRange tr = new AFTimeRange(sTime, eTime);
                        IDictionary<AFSummaryTypes, AFValue> sumS = pt.Summary(tr, OSIsoft.AF.Data.AFSummaryTypes.Average, OSIsoft.AF.Data.AFCalculationBasis.TimeWeighted, AFTimestampCalculation.EarliestTime);
                        AFValue sumAvg = sumS[AFSummaryTypes.Average];
                        Console.WriteLine("{0} at {1}", sumAvg.Value, sumAvg.Timestamp);
                        Console.ReadKey();
                    }
                }
            }
            

             

            The PI SDK call you've posted is almost right. In order to provide you with a complete answer, please find below a correction:

            PIValue ptavg = pt.Data.Summary("*-15m", "*", ArchiveSummaryTypeConstants.astAverage, CalculationBasisConstants.cbTimeWeighted, null);
            
              • Re: How to get 15 minute average value of a tag in vb.net code
                pthivierge

                Code provided by Gregor in VB.Net would give this:

                    Public Sub GetAverage()
                        
                        Dim srv as PIServer=PIServer.FindPIServer("PIServerName")
                        Dim pt As PI.PIPoint = PI.PIPoint.FindPIPoint(srv, "SINUSOID")
                        Dim eTime As AFTime = AFTime.NowInWholeSeconds
                        Dim sTime As AFTime = eTime.LocalTime.AddMinutes(-15)
                        Dim tr As New AFTimeRange(sTime, eTime)
                        Dim sumS As IDictionary(Of AFSummaryTypes, AFValue) = pt.Summary(tr, OSIsoft.AF.Data.AFSummaryTypes.Average, OSIsoft.AF.Data.AFCalculationBasis.TimeWeighted, AFTimestampCalculation.EarliestTime)
                        Dim sumAvg As AFValue = sumS(AFSummaryTypes.Average)
                        Console.WriteLine("{0} at {1}", sumAvg.Value, sumAvg.Timestamp)
                        Console.ReadKey()
                
                
                    End sub
                
              • Re: How to get 15 minute average value of a tag in vb.net code
                tmcmanus

                Here's an example that might help. If not, could you specifically state what problem you're encountering trying to implement this code? Is it just syntax you're looking for?

                 

                Time Weighted average

                average = pt.Data.Summary("*-15m", "*", PISDK.ArchiveSummaryTypeConstants.astAverage, PISDK.CalculationBasisConstants.cbTimeWeighted, Nothing).Value

                Event Weighted average (Mean)

                mean = pt.Data.Summary("*-15m", "*", PISDK.ArchiveSummaryTypeConstants.astMean, PISDK.CalculationBasisConstants.cbEventWeighted, Nothing).Value

                1 of 1 people found this helpful