2 Replies Latest reply on Feb 22, 2012 12:46 AM by Mike Zboray

    AF SDK GetValue returns null value for only attributes declared as PI Points

    ejcrosalesg

      The development team has implemented within a .NET code a function that reads the AF with AF SDK commands.

       

      This function returns values for attributes declared as Table Lookup, Rollup, Formula.....but alwyas returns NULL values for those attributes declared as PI Points even though the tags have values. The followind code is the one being used by the development team:

       

      Te la envío así como lo tengo… la siguiente función obtiene valores de atributos, cuando el atributo hace referencia a un PIPoint, regresa null:

       

       

       
      private string GetAFAttributeValue(AFElement node, string attName, string sDate)
      { 
          string value = null; AFAttributeList listAtt = AFAttribute.FindElementAttributes(myDB, node, node.Name, null, null, AFElementType.Any, attName, null, TypeCode.Empty, false, AFSortField.Name, AFSortOrder.Ascending, 1);
      
          if (listAtt.Count > 0)
          { 
              DateTime dtDate = new DateTime(Convert.ToDateTime(sDate).Year, Convert.ToDateTime(sDate).Month, Convert.ToDateTime(sDate).Day, 0, 0, 0, 0);
      
              AFValue afValue = listAtt[0].GetValue(dtDate.ToUniversalTime());
      
              if (afValue.IsGood) value = afValue.Value.ToString().Trim();
          }
          return value;
      }
      

       

       

       

       

       

       

      Please let me know why is this problem being presented and possible solutions. Thanks.

        • Re: AF SDK GetValue returns null value for only attributes declared as PI Points
          MvanderVeeken

          First of all, welcome to OSIsoft vCampus!

           

          I have reformatted your post, because it was completely unreadable. Also, not all of our members (including me) speak Spanish, so please use English only here. 

           

          Google translate of the Spanish part:

           

          "I send you and I have it ... the following function obtains attribute values, if the attribute refers to a PIPoint, returns null:"

           

          Back to the issue at hand:

           

          What are you really trying to accomplish here? From what I can read, you want to return the value for  the attribute with name attName at sDate? It seems really wrong to use AFAttribute.FindElementAttributes for this. Also. please have a look at DateTime.Parse...

           

          Why not use node.Attributes[attName].GetValue(DateTime.Parse(sDate)?

           

           

            • Re: AF SDK GetValue returns null value for only attributes declared as PI Points
              Mike Zboray

              Hey,

               

              There are two possibilities here. One is that your call to FindElementAttributes is not returning any attributes. Your arguments seem correct, but accessing via the Attributes collection would be easier on the eyes. The other is that the AFValue returned by GetValue has IsGood == false.  Typically if an exception is thrown by GetValue, AF wraps the exception in an AFValue object with IsGood set to false and the Value property set to the exception object. You should design for this case and log and/or propagate the error. An exception could be thrown for any number of reasons including not having security rights to access via AF (not having ReadData permission) or not being able to communicate with the PI Server. Also tags in a System digital state (e.g. Pt Created) will return IsGood as false as well.

               

              Mike