5 Replies Latest reply on Mar 13, 2018 6:46 PM by ErnyC

    AF Custom Data Reference to return multiple values


      Hi All

      I'm studying Custom Data Reference in AF.
      I've successfully developed my first CDR using GetValue. It works as expected, and I'm able to use it in analysis.

      What I'm trying to do with next step I to try to return multiple values from Custom Data Reference, and write results to different PI Points.

      Please see attached... Is it possible to use GetValues to accomplish this task? Is there any other solution?







        • Re: AF Custom Data Reference to return multiple values
          Rick Davin

          Hi Ernesto,


          You should not be using a custom data reference (CDR) to achieve this.  Understand that a CDR is intended to provide a value at a timestamp for a given attribute, or perhaps provide a range of values over a time range for that same attribute.  And it does so dynamically on demand.  What you are proposing is against the philosophy of a CDR in that you want it to also simultaneously consume the values it provides.  Besides being a serious violation of the principle of Separation of Concerns, it also produces the ill side effect of your CDR writing back to the PI Data Archive on each dynamic request.  What if you access the same time range back to back?  Do you really want to write back to the PI Data Archive repeatedly to the exact same PI Points with the exact same values?


          Perhaps you should just write a console application to do what you desire, and run it as a scheduled task.

          5 of 5 people found this helpful
            • Re: AF Custom Data Reference to return multiple values

              Thanks for your answer Rick

              and sorry for misunderstanding the use of custom Data Reference.

              Let me explain with a real life example:

              suppose you need to calculate gas flow rate. It requires an iterative calculation, so it's not possible to use standard analysis.

              The result of this calculation needs to be stored (in a PI Point?) to have history, and calculate hourly totalizer, daily totalizer, an so on...

              Can you suggest the right way to accomplish this task?



                • Re: AF Custom Data Reference to return multiple values
                  Rick Davin

                  Hello again Ernesto,


                  Here are a few options for you to consider:


                  Custom App - you could write a custom console app or Windows Service.  A console app would need to be scheduled periodically with a Task Scheduler.  The problem here is there is a very high burden placed on you to create how it gets scheduled or how frequently a Windows Service polls itself.


                  ACE - okay this pains me to admit but any complex calculations require looping constructs cannot be done in Analytics so ACE still has a very limited but special place.  But at least ACE has a scheduler built-in.  Note that in PI AF 2018 (AF SDK 2.10 ), there will be some support for arrays.  We will touch upon the array features on March 21 webinar: Asset Analytics native integration with MATLAB.


                  To me the easiest way to do this is have as simple an ACE calculation as possible to calculate the Gas Flow Rate for a given instant in time, and of course, have ACE save that calculated result back to a PIPoint.  Then you would have Analytics to generate the averages (see below).



                  If your Gas Flow Rate calculation relies upon PI points, then you would have one analysis just to calculate the instantaneous Gas Flow Rate, and also write that back to PI.  Then you would have other analyses that would trigger off the new GasFlowRate tag in PI.  Those other analyses would perform the averages.  In other words, break it down into discrete analyses and let one analysis propagate to another.


                  Formula and Analytics

                  If your Gas Flow Rate calculation relies upon PI points, then the Formula DR will have an AFEventSource to publish data to an AFDataPipe.  What that means to you is that Analytics can get event-triggered updates from your formula.  Your formula must be streamlined and focused to only calculate a given Gas Flow Rate for a given instant in time (no averaging just yet).  However, since the Formula DR has the AFEventSource (backed by input PI points), Analytics can be event-triggered or also periodically-triggered.  You would then have an analytic to create the various averages and persist the calculated averages back to a PIPoint(s).


                  Another option along with this is to have an analytic read your Gas Flow Rate from the formula, and persist the instantaneous Gas Flow Rate back to a PIPoint.  Note this is a two-stage process because of the previously discussed nature of data references: they only should produce a value.  They do not write back to PI.  So let the Formula produce the value in the first stage, and then for the second stage let an analysis write the value back to PI.


                  Hybrid Solution using a CDR with an AFEventSource and Analytics

                  Similar to Formula solution above but with a custom data reference.  You will need to implement the AFEventSource yourself.  I have a code sample to do that if you choose this route.

                  1 of 1 people found this helpful