5 Replies Latest reply on Jun 9, 2016 5:04 PM by dsouzarich

    'if ... then ... else' in a AF Formula


      I'm attempting to do what would appear very straightforward but (according my local expertise) may not be doable without recourse to using Af Analtytic or whatever.

      By way of exampe I have two attribute in an element. One, |INPUT is an input to an external program (that reads from AF using the AF SDK) the other |OUTPUT is an output from the same external program (that writes to AF usung the AF SDK). Under normal operation the value of |OUTPUT is copied to |INPUT (with a formula in |INPUT of the form A=|OUTPUT.


      This works fine.


      However I want to be able to 'break the link' for diagnostic purposes. Of course I could simply delete the formula, except that I have many input/outut relationships. Instead I created a |LOOPBACK attribute and an if ... then ... esle formula.


      First I tried

      if !LOOPBACK == 1 the !INPUT = !OUTPUT

      This wouldn't compile so then I tried

      if !LOOPBACK == 1 the !INPUT = !OUTPUT else !INPUT

      This compiled but on evaluation reported a circular reference for !INPUT. Perfectly reasonable!

      Anyway ids there a way to create a formula of the form

      if !LOOPBACK == 1 the !INPUT = !OUTPUT else do nothing


      I have a secondary question that I'll post in another existing 'reletibe paths' thread.

        • Re: 'if ... then ... else' in a AF Formula

          Hello Chris,


          PI Performance Equations offers NoOutput() for the use case you describe but I understand you are having custom code that reads AF Attributes (Input and Loopback) and in case Loopback = 1 is supposed to do some math and to write back to Output. If Loopback != 1, the calculation is supposed to not execute. So why don't you simply not execute / write back to Output in that case? Am I misunderstanding what you like to accomplish?

          1 of 1 people found this helpful
            • Re: 'if ... then ... else' in a AF Formula
              Roger Palmen

              Assuming the custom code only reads input and writes output, the custom code does not know the value of Loopback.


              Within a formula you could use DigState("No Data") and handle that Digital state in the custom code not to write an output value. It would still generate an event going into the datapipe though, so that would lead to processing where none is required.

              1 of 1 people found this helpful
                • Re: 'if ... then ... else' in a AF Formula

                  My code such as it is is simply a formula entered in the Settings area of an AF Attribute. Not using performance equations as none if the attributes reference PI.


                  I set Loopback to 0 or 1 manually.


                  Sent from my Windows Phone

                    • Re: 'if ... then ... else' in a AF Formula
                      Roger Palmen

                      Well, that explains why you get a circular reference. In your original text you stated an external program would read Input and write output. And that won't create a circular reference directly within AF. If you use formulas to copy from input to output and output to input, that won't work as you found out. Formulas are interpreted, so that will lead to a loop which will probably stop at some hardcoded nesting level (maximum recursion depth).

                    • Re: 'if ... then ... else' in a AF Formula

                      As Roger has suggested, DigState() can be used to pass back information that could be handled by some external code, as well as something to be utilised within AF. I have used DigState() to handle calc failed issues and pass back a string like "Input Issue" that can be displayed in some visualisation or in this case pass back some other information to some code.