3 Replies Latest reply on Aug 2, 2018 5:13 AM by Eugene Lee

    Creating an AFEnumerationSet type PI Point data reference issue

    jmoretti

      I am trying to create a PI Point data reference attribute that is a value type Enumeration Set using AFSDK 2017R2.  I set the AFAttribute.Type to typeof(AFEnumerationSet) and I see it working correctly while debugging and examining the attribute using intellisense.  However, when I check the attribute in PSE, it is configured as an Integer type.  In my code below, I have an Enumeration Set configured named "State" with 4 values.  I'm creating the attribute as a child of the rootAttribute.   The first line in cmdCreate_Click produces the erroneous PI Point attribute with an Integer value type.  The odd thing is thing is that the second line creates the Formula data reference with the appropriate Enumeration Set type correctly.  Even if I follow up the first line with explicitly setting the Status attribute's Type and TypeQualifier to what the CreateAttribute method would, intellisense shows it correctly but when i see it in PSE it's an Integer.  Am I doing something wrong?

       

      private void cmdCreate_Click(object sender, EventArgs e)
      {
      ...
           CreateAttribute(rootAttribute, "Status", "The tank state output", typeof(OSIsoft.AF.Asset.AFEnumerationValue), "State", "PI Point", "\\\\%Server%\\%@|TagName%.%..|Attribute%.%Attribute%;ReadOnly=False;pointtype=Int32;compressing=0;excdev=0;excdevpercent=0;pointsource=L;step=1");
           CreateAttribute(rootAttribute, "Tank State", "The tank state input", typeof(OSIsoft.AF.Asset.AFEnumerationValue), "State", "Formula", "A=[0];stepped=True");
      ...
      }
      
      private AFAttribute CreateAttribute(AFAttribute parentAttribute, string name, string description, Type type, string enumerationSet = null, string dataReferenceName = null, string configString = null, string uom = null)
              {
                  AFAttribute newAttribute = parentAttribute.Attributes.Add(name);
                  newAttribute.Description = description;
                  if (dataReferenceName != null && configString != null)
                  {
                      newAttribute.DataReferencePlugIn = parentAttribute.PISystem.DataReferencePlugIns[dataReferenceName];
                      newAttribute.ConfigString = configString;
                  }
                  newAttribute.Type = type;
                  if (enumerationSet != null)
                  {
                      newAttribute.TypeQualifier = parentAttribute.Database.EnumerationSets[enumerationSet];
                  }
                  else
                  {
                      if (type != typeof(String) && uom != null && parentAttribute.PISystem.UOMDatabase.UOMs.Contains(uom))
                      {
                          newAttribute.DefaultUOM = parentAttribute.PISystem.UOMDatabase.UOMs[uom];
                      }
                  }
                  newAttribute.IsConfigurationItem = true;
                  return newAttribute;  //if i use intellisense to examine newAttribute.Type here, it shows AFEnumerationValue correctly
              }
      
        • Re: Creating an AFEnumerationSet type PI Point data reference issue
          Eugene Lee

          Hi Jonathan,

           

          I tried running your code with the same AF SDK version that you are using as well as AF Server 2017 R2. I was able to create two child attributes with the type as the enumerationset.

           

           

          I created the Enumeration set named "State"

           

          I only modified the call to your CreateAttribute method slightly.

           

          CreateAttribute(rootAttribute, "Status", "The tank state output", typeof(OSIsoft.AF.Asset.AFEnumerationValue), "State", "PI Point", "\\\\%Server%\\%@|TagName%.%..|Attribute%.%Attribute%;ReadOnly=False;");
          CreateAttribute(rootAttribute, "Tank State", "The tank state input", typeof(OSIsoft.AF.Asset.AFEnumerationValue), "State", "Formula", "A=Status;[A];stepped=True");
          

           

          Make sure you already have a PI Point created in your default PI Data Archive. In my case, I created "hello.Attribute1.Status" manually with PI SMT. Also make sure that the PI Point has values that can map to the range of enumeration values that you have in your enumeration set. Otherwise, you will see

           

          2 of 2 people found this helpful
            • Re: Creating an AFEnumerationSet type PI Point data reference issue
              jmoretti

              Hi Eugene,

               

              Thanks for looking at this.  With the information you provided, I found a repeatable issue.

               

              1. If I create the attribute as shown in the code when the PI Point already exists, the attribute value type is set incorrectly to Int32.

              2. If I create the attribute as shown in the code when the PI Point doesn't already exist, the attribute value type is set to the correct Enumeration Set.

              3. If I create the attribute as shown in the code when the PI Point doesn't already exist, and then use the CreateConfig method on the PI Point data reference (Through code I did not post since I didn't think it was relevant to the original problem), the attribute value type is set incorrectly to Int32.

              4. If I create the attribute as shown in the code when the PI Point doesn't already exist, and then use PI System Explorer to create the PI Point via the Create or Update PI Point command, I can see the value type change from the correct Enumeration Set to the incorrect Int32.

               

              The purpose of this code is to automatically create the attributes and corresponding PI Points for the person building this AF data structure, so I don't want to have to create the point manually in SMT first.  Is this a bug in the PI Point data reference?  Why is it setting the value type to Int32 when I explicitly set it to a valid Enumeration Set?

                • Re: Creating an AFEnumerationSet type PI Point data reference issue
                  Eugene Lee

                  Without ever opening SMT, here are the results I get.

                   

                  1. If I create the attribute when the PI Point doesn't already exist, and then use the CreateConfig method on the PI Point data reference, the attribute value type is set correctly.

                   

                  var attr = CreateAttribute(rootAttribute, "Status", "The tank state output", typeof(OSIsoft.AF.Asset.AFEnumerationValue), "State", "PI Point", "\\\\%Server%\\%@|TagName%.%..|Attribute%.%Attribute%;ReadOnly=False;pointtype=Int32;compressing=0;excdev=0;excdevpercent=0;pointsource=L;step=1");
                  CreateAttribute(rootAttribute, "Tank State", "The tank state input", typeof(OSIsoft.AF.Asset.AFEnumerationValue), "State", "Formula", "A=Status;[A];stepped=True");
                  attr.DataReference.CreateConfig();
                  

                   

                  2. If I create the attribute when the PI Point doesn't already exist, and then use PI System Explorer to create the PI Point via the Create or Update PI Point command, the attribute value type is also set correctly.

                   

                   

                  This is my version information.

                   

                  It seems that your experience differs from mine. I would recommend you contact techsupport for a remote session to have a further look.