5 Replies Latest reply on Feb 16, 2016 3:46 PM by Marcos Vainer Loeff

    Reference an attribute of type text in an equation

    MassimoSporchia

      Hello,

      I'm currently using PI System Explorer 2014 R2 SP1 and I'm trying to reference an attribute value of type String in an equation attribute.

       

      I've a situation like this:

       

      A1: TextValue

      A2: True/False

      A3: AnotherTextValue

      A4: if A2 then A1 else A3

       

      The same template works fine if A1 and A3 aren't of type String and I coulnd't find a concrete answer on why this isn't possible.

      The error returned on A4 is "Data was not available for attribute 'A1': TextValue

       

      I hope this community I'm posting in is the right one, if not, I'm sorry and please feel free to move it to its specific spot.

       

      Thanks in advance.

        • Re: Reference an attribute of type text in an equation
          skwan

          Hi Massimo:

           

          It seems to work for me.  Attribute1, Attribute2 and Attribute3 are all String value type.

           

          a1.jpg

           

          I then created an analysis with If-Then-Else.

           

          a2.jpg

           

          It evaluates properly.

           

          Can you share your configuration?

          --

          Steve Kwan

            • Re: Reference an attribute of type text in an equation
              MassimoSporchia

              Hi Stephen,

               

              Thanks for the tip, I've tried but the result is this:

              afImage.png

               

              I'm attaching the code: http://pastebin.com/C8vbS4bt

              • Re: Reference an attribute of type text in an equation
                MassimoSporchia

                Hi,

                Thanks everyone, it "works" but not as I intended and maybe this isn't the right way to do it.
                I'd like this analysis to run whenever the three attributes I reference changes but it seems the attributes I reference aren't made for triggering this type of analysis.

                 

                I guess I could trigger it manually everytime I need the updated Value when I access it from AF SDK but I'm wondering if it's the right way to do it, is there any better solution? (Or am I trying to kill an ant with a bazooka? meaning I shouldn't bother trying to optimize these things).

                 

                Thanks in advance, again.

                 

                p.s.This is the code I'm using to run the analysis, I've noticed that the code that should trace the error isn't logging anything to AFTrace, this occurred if CurrentCase was null.

                analysis.AnalysisRule.CurrentCase = new AFCase(analysis);
                OSIsoft.AF.Analysis.AFAnalysisRuleState rs = new OSIsoft.AF.Analysis.AFAnalysisRuleState(analysis.AnalysisRule.GetConfiguration());
                rs.SetExecutionTimeAndPopulateInputs(new AFTime(DateTime.Now));
                analysis.AnalysisRule.CurrentCase.Run();
                var publishResult = analysis.AnalysisRule.Publish();
                return attribute.GetValue().ToString();
                
                  • Re: Reference an attribute of type text in an equation
                    Marcos Vainer Loeff

                    Hi Massimo,

                     

                    Have you configured the Scheduling for Event-Triggered for “Any Input”? According to my tests, this option works as long as the input is using the PI Point Data Reference. If no data reference is defined, then the trigger won't work. This is the result I have obtained on my environment.

                     

                    Therefore, there are 3 things for you to try:

                     

                    - Keep using your code to trigger the calculation which isn’t a great solution.

                    - Use Periodic Scheduling with a small time period if possible.

                    -Create string PI Points on the PI Data Archive and map the attributes you already have to those PI Points by setting up the PI Point data reference for each attribute.

                     

                    Hope it helps!

                    1 of 1 people found this helpful