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 ?
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.
// 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.
The behavior can be overridden.
If no Query Date is specified, which is the default mode of AF SDK, then the call to AFAttribute.GetValue(time) will move to the version of the attribute that was valid at the specified time. If you wish to override this behavior, then you must specify a query date for the element. If a Query Date is specified, then AF SDK will use that version no matter what time is passed in.
To set a query date, use something like:
AFDatabase databaseWithQueryDate = myDatabase.ApplyQueryDate("T");
All elements retrieved from "databaseWithQueryDate" will then also have the query date specified.
Likewise, you could do this on an individual element basis:
AFElement elementWithQueryDate = myElement.ApplyQueryDate("T");
Had the same issue. Fixed by doing a Refresh on the database before calling the getValue().
@Chris: Nice! I've totally missed this out, great to know how to do this.