5 Replies Latest reply on May 24, 2011 1:17 AM by hanyong

    AFAttribute.GetValue on PIDataReference point on previous time

    wxz44428

      I am working with AFSDK 2.1.1.3624. I am calling from c#. I ran into an issue today, here is the situation:

       

      I have an AFAttribute, that is of PI Point Data Reference. Suppose at March 1st, I configured it to point to PI point Tag1. Later, say today, 5/20,  I chanaged it to point to PI point Tag2. And, now I am asking its value, like, (psedo code);

       

                          AFTime tmpTime = new AFTime("5/20/2011");

       

                          tmpValue = tmpAttribute.GetValue(tmpTime);

       

      It gives the today's value of PI Tag2. However, if I call the same code, but with a different date, say, March 2nd,

       

                          AFTime tmpTime = new AFTime("3/2/2011");

       

                          tmpValue = tmpAttribute.GetValue(tmpTime);

       

      The value I got was PI Tag1's value on 3/2/2011, instead of Tag2's value on that date. I need to get the attribute's value (on any given time) based on current PI data reference configuration, which is Tag2. How to realize this ?

       

      Thanks !

       

       

       

       

       

       

       

       

        • Re: AFAttribute.GetValue on PIDataReference point on previous time
          wxz44428

          I just realized that for that attribute, I had two versions defined for it and stored in the AF instance. One with Tag1, one with Tag2. I guess this must be the reason for the behaviour I am seeing ? If that's the case, how to override this versioning thing when asking for value through tmpAttribute.GetValue(AFTime), so that it always returns the value of the specified time, for the Current configured PI Data Reference, namely, Tag2 ?

            • Re: AFAttribute.GetValue on PIDataReference point on previous time
              hanyong

              Hi Joe,

               

              Yes, the versions of the AF element would explain why you are observing this.

               

              I'm not sure if there is anyway to override this behaviour. A workaround is to get the PIPoint object of tag2 from the attribute using RawPIPoint property, and read the value of the tag using PI SDK.

              AFElement _element;
              AFTime time;

              // get your element and time instance

              AFAttribute _attr = _element.Attributes["<your AF Attribute name>"];
              PIPoint tag2 = (PIPoint)_attr.RawPIPoint;
              PIValue _value = tag2.Data.ArcValue(time.PITime, RetrievalTypeConstants.rtAuto);

              In this code snippet, I'm assuming tag2's value retrieval method by time configuration is set to automatic.