5 Replies Latest reply on Aug 14, 2012 9:25 PM by spilon

    Determining when an AF Attribute value was last updated

    wilsona

      I am looking for a way of determining when an AF Attribute value last changed.

       

      Ideally I would be able to use PI OleDbEnt to formulate and ask the question but I would also be happy to use the SDK. Is this possible?

       

      Cheers,

       

      Arthur

        • Re: Determining when an AF Attribute value was last updated
          mhamel

          @Arthur: The GetValue method 1 (with no arguments) of an AFAttribute object will return you the snapshot value or the last value if it refers to a PI Point. An exception will apply if the PI Point makes no use of compression or a very long period of time has elapsed without any change. You could monitor absolute change to a PI Point by creating a Performance Equation (PE) that will write a value only when your source value has changed. A possible PE equation would be:

           
          IF PrevEvent('Tag1') <> TagVal('Tag1') THEN 1 ELSE NOOUTPUT()
          

           

           

          As an example, I have Attribute1 configured on the PI Point named Tag1 and Attribute2 configured on PI Point named MonitorChangeTag1 using the proposed Performance Equation. You could use the query below to obtain time of the last change for Attribute1.

           
          SELECT s.Time
          FROM
               [AFDB].[Asset].[ElementHierarchy] eh
               INNER JOIN
               [AFDB].[Asset].[ElementAttribute] ea
                    ON ea.ElementID = eh.ElementID
               
               INNER JOIN
               [AFDB].[Data].[Snapshot] s
                    ON s.ElementAttributeID = ea.ID
          WHERE     
               ea.Name = N'Attribute2'               -- Read Attribute2
               AND eh.Path = N'\'                     -- root elements
               AND eh.Name = N'MyElement'          -- This attribute belongs to MyElement element.
          OPTION (FORCE ORDER, EMBED ERRORS)
          

           

           

          With AF SDK, you would call the GetValue method (with no arguments) on Attribute2 (AFAttribute) object and use the TimeStamp.LocalDate property to "know" what is the last value.

           

          For other AF Data References, it depends how the GetValue method has been defined.

           

          Let me know if that helped.

            • Re: Determining when an AF Attribute value was last updated
              wilsona

              Thanks Mathieu for your reply. What if the attributes I am interested in are not PI Data References?

               

              Unless an attribute is a PI Data Reference it does not appear that Time field in either the Snapshot or Archive are updated. They always read '1970-01-01 12:00:00.000'. The Value field is updated but the corresponding Time field is not, which means I cannot get the time that a value was updated.

               

              Is there another way?

                • Re: Determining when an AF Attribute value was last updated
                  mhamel

                  @Arthur: This information is stored in the AF SQL database, but it is not available from either the AF SDK or PI OLEDB Enterprise.  Its purpose in Microsoft SQL Server is for auditing, and a public programmatic exposure of that information is not yet available.

                    • Re: Determining when an AF Attribute value was last updated

                      @Arthur: an AF Attribute that is not tied to a Data Reference (e.g. PI Point) are generally constants or attributes whose value changes very seldomly (e.g. once a year). In other words, not the kind of attributes you are interested in their timestamp. The reason behind the 01-Jan-1970 is that it makes that value valid at any point in time.

                       

                      The part of the PI System that is really good at tracking changes over time is the PI Data Archive - and that is done by means of PI Points. I'm not sure what your use cases are, but your best bet is probably to create a PI Point to store the data you're interested in, and then expose that PI Point via an AF Attribute. That gives you access to additional analytical, etc. capabilities provided throughout the PI System, than by using a raw, DR-less AF Attribute.