AnsweredAssumed Answered

Get Formula Values from AFAttributes

Question asked by Optrix on Jan 8, 2019
Latest reply on Jan 8, 2019 by Optrix

I've written a driver that extracts values from AF attributes linked to PI data points, and it works very well - performance is excellent.


It builds a list of AFAttribute objects (each created with the PI AF path of the attribute I want to query) that it stores in an AFAttributeList.


I then use AFAttributeList.GetValue() to read all of the values.


This works perfectly for points connected to PI data points, but doesn't appear to work for formulas, complaining that The referenced Attribute '[path]' for attribute '[path]' is not configured as a PI Point DataReference.


This would indicate that I can't use an AFAttribute to query these sorts of points. Interestingly, the AFAttribute tells me that the attribute supports most of the read functions (GetValue etc.), but none of them work. Note that the AFAttribute is created with simply new AFAttribute(DB, Pathname) - since this appears to get a UniqueID for the attribute, I'm assuming that it's loaded information from the server. Interestingly, the DataReference for the AFAttribute shows it as a PI Point, although it's clearly a formula in the configuration.


At the end of the day, I'd probably suggest to my users that they create performance equations rather than AF formulas, since it will be significantly faster to use when dealing with historical queries, but the questions remain...


1) How do I read the value of a static value or formula using the AF SDK, if given only an AF Path?

2) Is there a way using AFAttribute to determine if the attribute is linked to a formula, rather than an AF data point?


Thanks for anyone who can help.


               string FullPath = "";
                 //"Addresses" is a dictionary containing the PI AF paths to the attributes I want to query. "Leader" contains the server name, database name and any parent elements (ie "\\\\MYSERVER\\MyDatabase\\ParentElement")
                //Get AFAttributes and place them in the PollingSet list...
                  AFAttributeList PollingSet = new AFAttributeList();
                 string FullPath = "";
                 foreach (KeyValuePair<string, list<pointinfo="">> KV in Addresses)
                     FullPath = Leader + KV.Key.Replace('/', '\\');
                     //Log(0, "Finding " + FullPath);
                         AFAttribute Attr = new AFAttribute(DB, FullPath);
                         //At this point, the AFAttribute LOOKS like it's linked to a PI point.
                         Log(1, "Unable to located PI AF address '" + FullPath + "'");
                   //Poll the values....
                  AFValues valueset = PollingSet.GetValue();
                  string val = "";
                 foreach (AFValue V in valueset)
                                             if (!V.IsGood)
                         //This is where I'm getting the exceptions about the attribute not being a PI point.
                                                     val = "^";
                         //Do standard processing