8 Replies Latest reply on May 5, 2016 4:19 AM by Argel

    PI Tag Values and Attributes




      I'm creating a winform application which fetches PI Values. Currently, I can get the current values only.


      I'm planning to get the Min Value, Max Value, and Average Value as well as the PI Point attributes such as UOM, etc.


      During my research I came across this PIPoint.Summary() but I'm not quite sure how to use this.


      Can someone please give me an example of codes which I can use? I am using C# and not VB.



        • Re: PI Tag Values and Attributes

          Hi Argel,



          I have not used C#. but see if following portion helps:



          Dim myServer As PISDK.Server    'PI server

                  Dim PT1 As PISDK.PIPoint    'PI Point

                  Dim myPoints As PISDK.PIPoints  'PI Points

                  Dim PiVal As PISDK.PIValue  'PI Value

          Dim Data_Count As Long  'Archive value count



          'Set PI server

                  myServer = g_SDK.Servers.Item(ServPickList1.SelectedServer.Name)

                  myPoints = myServer.PIPoints

                  'Set PI Point

                  PT1 = myPoints.Item("<<TagName>>")

                  'Read PI Point Attributes

                  ptatr = PT1.PointAttributes.Item("Descriptor")

                  descriptor = ptatr.Value

                  ptatr = PT1.PointAttributes.Item("EngUnits")

                  engunits = ptatr.Value







          'Calculated Data Code

                  Dim pdata As PISDK.PIData

                  Dim ipid2 As PISDK.IPIData2, ipiCalc As PISDK.IPICalculation

                  Dim nv As PISDKCommon.NamedValues

                  Dim nv_pi_val As PIValues

                  Dim Calc_Type As String



              ipiCalc = myServer

                      pdata = PT1.Data

                      ipid2 = pdata



                      Data_Count = ipid2.Summaries2(Start_Date, End_Date, <<Interval>>, <<Int value for Summary type>>, <<Time weighted or Evet Weighted>>).Item(1).Value.count

                      Calc_Type = ipid2.Summaries2(Start_Date, End_Date, <<Interval>>, <<Int value for Summary type>>, <<Time weighted or Evet Weighted>>).Item(1).Name




                      Dim Comp_Data_Array(Data_Count - 1, 2) As String  'No redim required like vba

                      nv = ipid2.Summaries2(Start_Date, End_Date, <<Interval>>, <<Int value for Summary type>>, <<Time weighted or Evet Weighted>>)

                      nv_pi_val = nv(Calc_Type).Value



          For i = 0 To Data_Count - 1

                          Timestamp(i) = nv_pi_val.Item(i + 1).TimeStamp.LocalDate.ToString

                          Val1(i) = nv_pi_val.Item(i + 1).Value


                      Next i

          • Re: PI Tag Values and Attributes
            Eugene Lee

            Hi Argel,


            We would recommend AF SDK and not PI SDK. Please see below sample code.


            var summarizedvals =myPoint1.Summary(new AFTimeRange("8:00", "9:00"), AFSummaryTypes.Maximum | AFSummaryTypes.Minimum | AFSummaryTypes.Average, AFCalculationBasis.EventWeighted, AFTimestampCalculation.Auto);
            Console.WriteLine("Average: "+summarizedvals[AFSummaryTypes.Average].Value);
            Console.WriteLine("Max: "+summarizedvals[AFSummaryTypes.Maximum].Value);
            Console.WriteLine("Min: "+summarizedvals[AFSummaryTypes.Minimum].Value);


            myPoint1 is your PIPoint object. This code gets the summary for 8am to 9am today.