14 Replies Latest reply on Apr 21, 2016 4:35 PM by Dan Fishman

    How to get data from AF aliases

    Glise

      Hello,

       

      I would like to retrieve data from an alias stored in AF in C#.

      Does anyone knows how to do it please ?

       

      Regards,

       

      Marion

        • Re: How to get data from AF aliases
          Dan Fishman

          I don't know if you mean retrieve data from an alias stored in an AF Attribute. 

          To get the most current value you can use:

              AFValue myVal = myDB.Elements["element1"].Attributes["attribute2"].GetValue();

           

          The above code uses the element named "element1" under the root in an AF Database and grabs an attribute  named "attribute2". 

           

          I would recommend checking out the GetValues method as well here: AFAttribute Methods .

            • Re: How to get data from AF aliases
              Glise

              Thanks for your answer.

               

              Yes, the alias is stored in an AF attribute. Is it possible to filter using an expression ?

                • Re: How to get data from AF aliases
                  gregor

                  Hello Marion,

                   

                  Marion Glise wrote:

                   

                  Yes, the alias is stored in an AF attribute.

                  Is the alias stored in the attributes value or its description or where?

                  Is the alias stored inside a string that as well contains other information?

                  What's the pattern to recognize the alias?

                    • Re: How to get data from AF aliases
                      Glise

                      Hello Gregor,

                       

                      The tag alias are stored in the attributes of an element. In the attribute's name I have a string which define the tag alias and in the attribute's value I have a link to a pi point.

                      I can't give you a screenshot as I am working with confidential data, even if it would be easier to explain to you.

                       

                      My apologies if I'm not really clear, I am a beginner in programming with PI.

                        • Re: How to get data from AF aliases
                          gregor

                          Hello Marion,

                           

                          I understand that you like to programmatically read the value of an AF Attribute. PI Asset Framework (AF) Developer’s Kit 2015 R2 Install Kit installs Intellisense for Visual Studio and some help files that together build the AF SDK Programming reference. The files (AFSDK.chm, AFUIRef.chm ..) become installed to %PIHOME%\help\

                          The following link points to the current release of the online version of AF SDK Reference manual -> Examples -> Connecting to AF Server: Connecting to a PI AF Server

                          I believe the example under Multi-User Connection could get you started.

                            • Re: How to get data from AF aliases
                              Glise

                              I'm already using this kit. I just didn't find the way to do this. It's not easy to find an information in the help file.

                                • Re: How to get data from AF aliases
                                  gregor

                                  Hello Marion,

                                   

                                  Please accept our apologies but I assume that this is a starting barrier. The more you become used to the help file and the AF SDK object model, the easier it becomes. Please don't hesitate asking if you cannot find the answer to your question within the documentation.

                                    • Re: How to get data from AF aliases
                                      Glise

                                      I have only found the method getValues(). But what I want to do is to filter the result. I don't need all the data that getValues() returns. So I would like to use an expression or something similar to filter my request.

                                        • Re: How to get data from AF aliases
                                          gregor

                                          Hello Marion,

                                           

                                          The example I was referring to uses GetValue() instead of GetValues(). Can you please see if GetValue() delivers what you need?

                                          If not can you please describe what kind of filter you like to apply?

                                            • Re: How to get data from AF aliases
                                              Glise

                                              getvalue() doesn't give me what I need.

                                              What I need is to get datas in a period, as getvalues() does, but this method returns every values in the period and I need to filter with this kind of expression : 'tag'>350

                                              1 of 1 people found this helpful
                                                • Re: How to get data from AF aliases
                                                  Dan Fishman

                                                  Thanks for providing an example of what you would like to do.  You can call myAttribute.Data.RecrdoedValues().  Check out the OSIsoft.AF.Data namespace and you can access the data access methods from your AFAttribute via the Data property.  You will see quite a few AFData methods and you probalby want to use RecordedValues and provide a filter similar to what you have in the above post.

                                                    • Re: How to get data from AF aliases
                                                      Glise

                                                      Thanks for your help.

                                                      I have used this code :

                                                      afRootElement.Elepents[path].Attributes[alias].Data.RecordedValues(new AFTimeRange(start, end),AFBoundaruType.Inside, null, filter, false, 0);

                                                      with filter : '[{AlarmPriority}]="1"

                                                      and alias : AlarmMsg

                                                       

                                                      AlarmPriority is another tag alias.

                                                       

                                                      If I use either the tag alias or the tag, they are not recognised by the system. But if I use the PIPoint.RecordedValues the tag is recognised.

                                                       

                                                      So my question is what is the difference between Data and PIPoint ?

                                                        • Re: How to get data from AF aliases
                                                          Dan Fishman

                                                          You are welcome.  Thnaks for sharing more on your code.  I did a test here and was surprised that AFAttribute.Data.RecordedValues with a filter shows that the filter is not supported.  If AlarmPriority is the name of an AFAttribute you should be able to pass in an expression such as "'AlarmPriority' = 1" and recordedValues will resolve this to the correct PI Point.  You are correct, tag names are not reconized when using the AFData with filter (it only knows AFAttributes), and they are reconized from the PI.Data namespace.  Pretty confusing and I appreciate you providing this example.

                                                           

                                                          In general, AF Data is designed to work with all AFAttributes and PIPoint works only with the PI Server.

                                  • Re: How to get data from AF aliases
                                    gregor

                                    Hello Marion,

                                     

                                    What you would like to accomplish very likely is possible using AF SDK but I am uncertain what you are after. We use the term Alias with PI Module Database. Are you possibly trying to read time series data from an AF Attribute that refers a PI Point? If not, please describe a bit more detailed what you like to do and feel free including a screenshot from PI System Explorer for illustration.

                                     

                                    When developing against AF SDK, we suggest having the latest PI AF Client and the PI AF Developer's Kit installed. At current time, the following 2 download links are valid.

                                    PI Asset Framework (AF) Client 2015 R2 Install Kit

                                    PI Asset Framework (AF) Developer’s Kit 2015 R2 Install Kit