voo33

Reset attribute to template and create the PI point

Discussion created by voo33 on Apr 25, 2014
Latest reply on Apr 28, 2014 by Marcos Vainer Loeff

Hi,

 

I've been pulling my hair off for the last 2 days because of the error I'm having with AFSDK. Basically I'm trying to reset an attribute to template and then create the PI point. The code below throws an exception when PI point doesn't exist but the config string is 'locked in' and pointing to another existing tag.  The error I get is:

 

 Exception:Caught: "The object 'Adm_Meter_6377_Distributor' was not found, or it could not be created." (OSIsoft.AF.PI.PIException)
A OSIsoft.AF.PI.PIException was caught: "The object 'Adm_Meter_6377_Distributor' was not found, or it could not be created."

 

Code:  

 
foreach (AFAttribute attr in elem.Attributes)
{
    if (attr.DataReferencePlugIn != null && attr.DataReferencePlugIn.Name.Equals("PI Point"))
    {
        if (attr.Name.Contains("Tag"))
        {
              attr.ResetToTemplate();
              try
              {
                  attr.DataReference.CreateConfig();
              }
              catch (Exception e)
              {
                  throw e;
              }
          }
     }
}

One thing I noticed when I'm debugging is: the config string doesn't reset to template in System Explorer after attr.ResetToTemplate() is done and returns 'true'. My understand is the config string should be reset to whatever is in the template. It works when I manually click on the 'Reset to Template' button in AF System Explorer.

 

Does anyone have any suggestion?

 

Thanks in advance!

 

Shanshan

 

 

Outcomes