4 Replies Latest reply on Apr 1, 2013 2:12 PM by Rick Davin

    AF.PI LoadAttributes clears cache?

    Rick Davin

      I’ve been putting together a WinForms app that makes an AFOperations.FindPIPoints call to show the AF Tag Search dialog.  I load the returned List<PIPoint> into a data grid view that includes displaying the Descriptor and EngineeringUnits, which proves those PI point attributes are indeed in my local cache.  If I later click a certain command button, the app takes the List<PIPoint> and uses a little LINQ to filter on just those of PIPointType.Digital.  The filtered enumerated list is used to create a new PIPointList, which I then use to issue a PIPointList.LoadAttributes(PICommonPointAttributes.DigitalSetName) to load the DigitalSetName attribute into my cache so that I can later issue a PIPoint.GetAttribute(PICommonPointAttributes.DigitalSetName). 

       

      All of that is working fine and dandy.  That after I load the DigitalSetName attribute into cache that the other attributes previously in cache (Descriptor and EngineeringUnits) are unloaded from cache for the subset of digital tags.  I was hoping that subsequent calls to LoadAttributes would have added to rather than completely replaced that point’s cache.

       

       

       
      PIPointList SearchForTags(string piserverName, string tagFilter)
      {
          IWin32Window window = this;
          bool bMultiSelect = true;
          bool bReturnEntireQuery = false;
          bool bOkayWithoutSelection = true;
          PIPointCriteria criteria = new PIPointCriteria();
          criteria.NameFilter = tagFilter;
          // The UI Dialog will be called and user may change filter.
          return new PIPointList(AFOperations.FindPIPoints(window, piserverName, bMultiSelect, 
                                 bReturnEntireQuery, bOkayWithoutSelection, criteria));
      }
      
      void Example1()
      {
          object piproperty = null;
          PIPointList points = SearchForTags("RicksServer", "3DTCW*");
          var digiFilter = from point in points where (point.PointType == PIPointType.Digital) select point;
          PIPointList digitals = new PIPointList(digiFilter);
          // This works so Descriptor must be cached.
          piproperty = digitals[0].GetAttribute(PICommonPointAttributes.Descriptor);
          // Load DigitalSetName
          digitals.LoadAttributes(PICommonPointAttributes.DigitalSetName);
          // This works
          piproperty = digitals[0].GetAttribute(PICommonPointAttributes.DigitalSetName);
          // But now this does not.  Descriptor is no longer in the cache.
          piproperty = digitals[0].GetAttribute(PICommonPointAttributes.Descriptor);
      }
      

       

       

       While I’m at it, my overall app requires me to load a few extra attributes.  I naturally want Descriptor, EngineeringUnits, and PointType which are included in the FindPIPoints call.  I also want DigitalSetName, DataSecurity, and PointSecurity to name a few others.  It would be nice if I could have those attributes loaded by FindPIPoints.  I tried using this code, but it did not work.  An exception is thrown the instant I try to access GetAttribute(PICommonPointAttributes.DigitalSetName).  The exception tells me I haven’t loaded the DigitalSetName into cache, so that tells me the next bit of code doesn’t work as intended.

       

       

       
      PIPointList SearchForTags2(string piserverName, string tagFilter)
      {
          IWin32Window window = this;
          bool bMultiSelect = true;
          bool bReturnEntireQuery = false;
          bool bOkayWithoutSelection = true;
          PIPointCriteria criteria = new PIPointCriteria();
          criteria.NameFilter = tagFilter;
          // This doesn’t load the last 3.
          var propertyNames = new List(); 
          propertyNames.Add(PICommonPointAttributes.PointID);  
          propertyNames.Add(PICommonPointAttributes.PointType);  
          propertyNames.Add(PICommonPointAttributes.Descriptor);  
          propertyNames.Add(PICommonPointAttributes.EngineeringUnits);  
          propertyNames.Add(PICommonPointAttributes.DigitalSetName);  
          propertyNames.Add(PICommonPointAttributes.DataSecurity);  
          propertyNames.Add(PICommonPointAttributes.PointSecurity);  
          criteria.PIPointAttributes = propertyNames; 
          // The UI Dialog will be called and user may change filter.
         return new PIPointList(AFOperations.FindPIPoints(window, piserverName, bMultiSelect, bReturnEntireQuery, bOkayWithoutSelection, criteria));
      } 
      

       

       

       

       

       I guess the questions I have for this thread are:

       

      1)      Do others see the same behavior of the cache being cleared out on subsequent LoadAttributes calls?

       

      2)      Is clearing the cache the intended behavior or might it be a bug?

       

      3)      Am I not allowed to add PIPointAttributes for the PIPointCriteria for that overload?

       

      Thanks. 

       

       

        • Re: AF.PI LoadAttributes clears cache?

          Hey Rick,  It seems reasonable to me that when you are explicitly saying LoadAttributes you literally only want those attributes loaded whether the PIPoint is cached or not.  I think in AF SDK there are next to no attributes loaded by default to limit the size of calls to load PIPoints; seem to remember just the tag name, point id and point type come back for each PIPoint.  The AF SDK UI must have a wrapper around FindPIPoints to include the descriptor.  When you create the new PIPointList with the PIPoint objects returned from the UI the descriptor is included so just gets added to the list.  When the LoadAttributes method is called it locates the PIPoint from the collection and sets the new set of attributes requested rather than append them - I guess in case the attributes already loaded go out of date? (or a bug as you say )

           

          Can you still access the pointtype after loading the digital set attribute?