5 Replies Latest reply on Sep 6, 2016 11:08 AM by ErikDeSmedt

    Retrieving basic summaries in PI AF SDK

    ErikDeSmedt

      Hi

       

      I am writing an application in PI AF SDDK which retrieves some basic summaries such as averages. Whenever I try to request an average a cryptic error message appears. However, if I perform another query before requesting the average everything works fine.

       

      I would like to understand why this is happening and learn how can I avoid performing this seemingly spurious call?

       

      //retrieve the required attribute
      
      ...
      
      // Uncomment the next line to fix the code
      
      // var test = attribute.Data.InterpolatedValue(new AFTime("*"), null);
      
      IDictionary<AFSummaryTypes, AFValue> result1 = attribute.Data.Summary(timeRange, 
      
          AFSummaryTypes.Average, 
      
          AFCalculationBasis.TimeWeighted, 
      
          AFTimestampCalculation.Auto);
      
      AFValue value = result1[AFSummaryTypes.Average];
      
      Assert.IsTrue(value.IsGood, value.Value.ToString());
      
      //When the line is uncommnented the test succeeds and the average is computed correctly
      
      //When the line is commented out the test fails. A bad value with the following error message appers.
      
      //Assert.IsTrue failed. System.Runtime.Serialization.SerializationException: Type 'OSIsoft.AF.Data.AFDataProvider+AFQueryDataProvider' in assembly 'OSIsoft.AFSDK, Version=4.0.0.0, Culture=neutral, PublicKeyToken=6238be57836698e6' is not marked as serializable. 
      

       

        • Re: Retrieving basic summaries in PI AF SDK
          pmartin

          Hi Erik,

           

          I was not able to reproduce this behavior.  Could you fill me in with a bit more information?

           

          What version of AF and AF SDK are you using?

          What types of values does this attribute have? Or does it happen with multiple attributes of different types?

          If you add a breakpoint, do the result1 and value variables look valid?  Can you read the average value?

            • Re: Retrieving basic summaries in PI AF SDK
              Rick Davin

              Adding to Paul's comments, can you perhaps add this little statements in to check your locals when debugging:

               

              Replace line 19 with these 3 lines:

               

              bool condition = value.IsGood;
              string message = value.Value.ToString();
              Assert.IsTrue(condition, message);
              
              • Re: Retrieving basic summaries in PI AF SDK
                ErikDeSmedt

                Hi Paul

                 

                Thanks for your reply.

                 

                The attribute I am requesting is a simple PI Point configured as in the screenshot below.

                I am using

                • AF SDK Version 2.8.1.7459. Assembly Version: 4.0.0.0. .Net: v4.0.30319
                • PI AF Server Version 2.6.1.6238

                 

                When I add a a breakpoint the value is not looking valid.

                 

                bool condition = value.IsGood; //returns false
                object Value = value.Value; // returns a System.Runtime.SerializationException
                string message = value.Value.ToString()
                /**
                System.Runtime.Serialization.SerializationException: Type 'OSIsoft.AF.Data.AFDataProvider+AFQueryDataProvider' in assembly 'OSIsoft.AFSDK, Version=4.0.0.0, Culture=neutral, PublicKeyToken=6238be57836698e6' is not marked as serializable.
                  at System.AppDomain.get_Evidence()
                  at System.AppDomain.get_EvidenceNoDemand()
                  at System.AppDomain.get_Evidence()
                  at System.Configuration.ClientConfigPaths.GetEvidenceInfo(AppDomain appDomain, String exePath, String& typeName)
                  at System.Configuration.ClientConfigPaths.GetTypeAndHashSuffix(AppDomain appDomain, String exePath)
                  at System.Configuration.ClientConfigPaths..ctor(String exePath, Boolean includeUserConfig)
                  at System.Configuration.ClientConfigPaths.GetPaths(String exePath, Boolean includeUserConfig)
                  at System.Configuration.Internal.ConfigurationManagerInternal.System.Configuration.Internal.IConfigurationManagerInternal.get_ExeProductName()
                  at System.Configuration.ApplicationSettingsBase.get_Initializer()
                  at System.Configuration.ApplicationSettingsBase.CreateSetting(PropertyInfo propInfo)
                  at System.Configuration.ApplicationSettingsBase.EnsureInitialized()
                  at System.Configuration.ApplicationSettingsBase.get_Properties()
                  at System.Configuration.SettingsBase.GetPropertyValueByName(String propertyName)
                  at System.Configuration.SettingsBase.get_Item(String propertyName)
                  at System.Configuration.ApplicationSettingsBase.GetPropertyValue(String propertyName)
                  at System.Configuration.ApplicationSettingsBase.get_Item(String propertyName)
                  at OSIsoft.PI.Net.Properties.Settings.get_ServiceOperationImplAssemblyName()
                  at OSIsoft.PI.Net.ServiceOperations.ServiceOperationFactory.GetServiceOperation()
                  at System.Lazy`1.CreateValue()
                  at System.Lazy`1.LazyInitValue()
                  at System.Lazy`1.get_Value()
                  at OSIsoft.PI.Net.ServiceOperations.ServiceOperationFactory.get_Operations()
                  at OSIsoft.PI.Net.StreamDirectory.<GetBlock>d__9.MoveNext()
                  at OSIsoft.PI.Net.StreamDirectory.<Marshal>d__5`1.MoveNext()
                  at OSIsoft.PI.Net.StreamDirectory.<FindStreams>d__6`1.MoveNext()
                  at OSIsoft.PI.Net.StreamDirectory.<FindStreams>d__32`1.MoveNext()
                  at OSIsoft.PI.Net.StreamDirectory.<FindStreams>d__28`1.MoveNext()
                  at OSIsoft.PI.Net.StreamList.<GetAttributes>d__62`1.MoveNext()
                  at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
                  at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
                  at OSIsoft.PI.Net.Stream.GetAttributes[T](IEnumerable`1 attributes, StreamAttributeFactory`1 factory)
                  at OSIsoft.PI.Net.Stream.Update(Func`2 createException)
                  at OSIsoft.PI.Net.Stream.get_Type()
                  at OSIsoft.AF.PI.PIPoint.get_PointType()
                  at OSIsoft.AF.Asset.DataReference.PIPointDR.CheckSummaryTypeAgainstPointType(AFSummaryTypes summaryType, PIPoint ptPI)
                  at OSIsoft.AF.Asset.DataReference.PIPointDR.Summary(AFTimeRange timeRange, AFSummaryTypes summaryType, AFCalculationBasis calcBasis, AFTimestampCalculation timeType)
                  at OSIsoft.AF.Data.AFData.SummaryQuery.QuerySourceDataReference(AFAttribute attribute, AFDataReference dataReference, AFDataProvider inputProvider, UOM desiredUOM)
                  at OSIsoft.AF.Data.AFDataCaller`1.SyncCaller.ExecuteQuery(IAFDataReferenceQuery`1 query, AFAttribute attribute, AFDataReference dataReference, AFDataProvider inputProvider, UOM desiredUOM) */