5 Replies Latest reply on Jun 15, 2016 9:09 PM by John Messinger

    Create a function in Wrapper

    claudio

      We create a function that returns the path element as follows:

      [ComVisible(true)]

              public string GetPathByName(string fullElementName)

              {

                  PISystem myPISystem = new PISystems().DefaultPISystem;

                  NetworkCredential credential = new NetworkCredential("user", "password");

                  myPISystem.Connect(credential);

                  AFDatabase myDB = myPISystem.Databases.DefaultDatabase;

                  var myElements = AFElement.FindElements(

                  myDB, null, fullElementName, AFSearchField.Name,

                  true, AFSortField.Name, AFSortOrder.Ascending, 1);

                  myPISystem.Disconnect();

                  if (myElements != null && myElements.Count > 0)

                  {

                      return myElements[0].GetPath();

                  }

                  else

                  {

                      return null;

                  }

              }

       

      How do I get an associated tag name, passing the path of the element obtained in the previous function?

       

      Thanks for listening !

        • Re: Create a function in Wrapper
          John Messinger

          From here you will need an AFAttribute that you wish to get the tag name from. You can read the AFAttribute.PIPoint property directly to get this information.

          However, I could also read your question assuming that by tag name you are in fact referring to an Attribute name. If this is the case, you can use the AFAttribute.FindAttributesByPath method to obtain a list of element Attributes using the path you obtained from your previous function.

            • Re: Create a function in Wrapper
              claudio

              Dear John, thanks for the reply. I am a beginner in C # language.

              Unfortunately I am not able to use the AFAttribute.PIPoint property. Maybe you are missing some prerequisite. Please show me how to write this function in C # and it is necessary to include the version of .NET 4. Greetings

                • Re: Create a function in Wrapper
                  gregor

                  Hello Claudio,

                   

                  The majority of content including sample code is available for users that registered an SSO account with OSIsoft. There's however some content that is only available to users owning a paid membership to PI Developers Club. Building a Wrapper that makes AF SDK functionality available for MS Excel or PI ProcessBook VBA is an advanced topic and I assume because of that the AF Wrapper was decided to be restricted content.

                   

                  It's tradition at OSIsoft to leave nobody behind. I like to follow the tradition and build you a bridge by suggesting that you try your code first e.g. in a .NET Console Application. This is a) fully supported and b) allows you to test what you build before facing the complexity that comes with a Wrapper.

                   

                  You need to instantiate an AFAttribute first before being able to read its PIPoint property. Please also be aware that in case the AFAttribute does not use a PI Point Data Reference the PIPoint property will be null.

                  Can you please see if the example on this other thread helps you?

                  1 of 1 people found this helpful
                    • Re: Create a function in Wrapper
                      claudio

                      Hello Gregor,

                       

                      Thank you for the informations ! I need to get the reference: attribute.PIPoint.GetAttribute (PICommonPointAttributes.Tag). However, only got success when installed .Net 4.6 with Sharp Developer Tool version 5. The problem is that I am using Visual Studio 2008 and how it is not compatible with .Net 4, I will have to migrate to version 2012. It has a better idea?

                        • Re: Create a function in Wrapper
                          John Messinger

                          In order to access the newer functionality in AFSDK (Rich Data Access, classes in namespaces such as OSIsoft.AF.PI, etc), you will need .NET Framework 4.0 or higher. Given that Microsoft has announced it is ending support for .NET Framework versions 4, 4.5 and 4.5.1, I would recommend migrating to at least Visual Studio 2013 (and install the Microsoft .NET Framework 4.5.2 Developer Pack), or better yet go to Visual Studio 2015 and target the newer framework versions. I don't know much about the SharpDevelop IDE, but I would assume the current version can target .NET Framework 4.5.2 and higher. If not, then the Community Edition of Visual Studio may suit your needs (check the licensing terms first!) if you don't have a MSDN subscription.

                          2 of 2 people found this helpful