2 Replies Latest reply on May 7, 2014 12:36 PM by GALLON

    AFSDK how to check if the PIPoint as AFAttribute is already created or not

    GALLON

       Hi,

       

      I'm creating AFElements and their related PIPoints by using the CreateConfig function (see the code below).

       

      I do not find a nice way to check if the PIPoint as AFAttribute is already created or not... Every method I try, I receive an Exception. I would like to avoid try catching for that 

       

      Any idea?

       
                 foreach (AFAttribute curAttribute in myElement.Attributes)
                  {
                      string an = curAttribute.Name;
                      if (curAttribute.DataReference != null && curAttribute.DataReferencePlugIn == curAttribute.PISystem.DataReferencePlugIns["PI Point"])
                      {
                          string type = curAttribute.Type.Name;
                          AFElementContainer ac = AFElementContainer.findIndexByAttributeName(curAttribute.Name, attributeConfigNames);
                          
                          curAttribute.DataReferencePlugIn = AFDataReference.GetPIPointDataReference(myPISystem);
                          curAttribute.ConfigString = String.Format(@"\\%Server%\{0}_{1};ptclassname=classic;pointtype=""{2}"";descriptor=""{3}"";shutdown=0;datasecurity=etc.....", curAttribute, afelementSuffixName, type, curAttribute.Description);
                          curAttribute.DataReference.CreateConfig();
                      }
      ...
      

       

       

      Thanks,

       

      Mahyar SEPEHR

        • Re: AFSDK how to check if the PIPoint as AFAttribute is already created or not
          xwang

          Hi Guillaume,

           

          I have ever made a project to use PI AF SDK to establish the PI AF tree and PI points automatically.  Some of the attributes of the elements in the AF tree has the PIPoint data reference, and I made a if... else... loop to confirm if the PI point for each attribute are created.  If so, I will not create that PI point via CreateConfig() function.

           

          My attributes are create by PI AF template, and use ElementName.Attribute.Name as the PI point name.  Therefore, I use the following code snippet to decide if PI point needs to create.  If it has existed, do not create it.

           
           foreach (AFAttribute attribute in check_list)
                      {   
                          PIPoint point = null;
                          string point_name = attribute.Element.Name.ToString() + "." + attribute.Name.ToString();  //got the PI point name as the string type
                          Boolean exist = PIPoint.TryFindPIPoint(pi_server,point_name, out point);       // TryFindPIPoint() is the key function to look for PI Point, and will return true or false            
                          if (exist == true)
                          {
                          }
                          else
                          {
                              attribute.DataReference.CreateConfig();
                          }
          

           Hope this could help you.

           

          Xi Wang

           

          vCampus team

          1 of 1 people found this helpful