8 Replies Latest reply on Mar 26, 2018 6:08 PM by dmoler

    AF Data Pipe Update on Attribute Changes

    neilg

      Hi World,

       

      We have an AFDataPipe which is monitoring weather station data in attributes linked to the weather station PI Points.


      The attributes are:
      Measured Wind Speed points to 'M.WS1.MWINDSPEED'

      Measured Ambient Temperature points to 'M.WS1.OBS_MTEMP'

      where 'WS1' = Weather Station 1

      and Closest Weather Station|ID = WS1

      The PI Tag names for the telemetered attributes are built from an ID attribute (M.%@Closest Weather Station|ID%_OBS_MTEMP).

       

      We have an AF Analyses (runs periodically) which switches the current weather station to another one if the current weather station data goes stale. It does this by changing the Closest Weather Station|ID attribute which all the telemetered tags derive their tag names from.

       

      This means that if WS1 goes stale the Analyses will switch the attributes as below:

      Measured Wind Speed points to 'M.WS2.MWINDSPEED'

      Measured Ambient Temperature points to 'M.WS2.OBS_MTEMP'

      and Closest Weather Station|ID = WS2

      When the switch happens the AFDataPipe still keeps receiving data from WS1 and does not get data from WS2.

       

      I have done research on it and came across this post https://pisquare.osisoft.com/message/74306-re-how-does-af-attributes-subscription-work and implemented the suggested approach but it does not work when AF Analyses changes the ID attribute.


      I basically get all changes from the AFDatabase and apply it to the AFDataPipe (AFDataChangeMonitor object in the below code) before attempting to retrieve events from the AFDataPipe. Also of note is that the AFDBCookie is retrieved once on startup and the same object is retained on subsequent calls.

       

       

      I also tried removing and re-adding the changed attributes but an error comes up when trying to remove the changed attribute:

       

      {[Measured Wind Speed, System.InvalidOperationException: stream not found in Upstream Pipe

         at OSIsoft.AF.PI.PIPipeToAFPipeTransformer.QueueRemovePIPointSignup(PIPoint inputStream, AFAttribute stream)

         at OSIsoft.AF.PI.PIPipeToAFPipeTransformer.OSIsoft.AF.Data.IAFEventSource<OSIsoft.AF.Asset.AFAttribute>.QueueRemoveSignup(AFAttribute stream, Object routingToken)

         at OSIsoft.AF.Data.AFDataPipeAggregator`2.OSIsoft.AF.Data.IAFEventSource<TStream>.QueueRemoveSignup(TStream stream, Object routingToken)

         at OSIsoft.AF.Data.AFDataPipeSplitter.QueueRemoveSignup(Int32 streamIndex, AFAttribute stream, Object routingToken)

         at OSIsoft.AF.Data.AFDataPipeSplitter.SplitStream.OSIsoft.AF.Data.IAFEventSource<OSIsoft.AF.Asset.AFAttribute>.QueueRemoveSignup(AFAttribute stream, Object routingToken)

         at OSIsoft.AF.Data.AFDataPipeCalculator.QueueRemoveSignup(AFAttribute stream, Object routingToken)

         at OSIsoft.AF.Data.AFDataPipe.RemoveSignups(IList`1 attributes)]}

       

      Are there any other things I can try? Or am I doing something incorrectly with the code above?

        • Re: AF Data Pipe Update on Attribute Changes
          tramachandran

          I would have to test this behavior when the attribute configuration is updated.

          Could you provide the version of the AF SDK and PI AF Server?

          You could also generate the AF SDK trace logs for your application using AFgettrace utility (use switches /s /pid:<pid from taskmgr>  /log:<file path>) to investigate the issue further.

          • Re: AF Data Pipe Update on Attribute Changes
            dmoler

            Hi Neil,

             

            Attribute substitutions for tag names are only evaluated on initialization. We have resolved the issue that cause the exception you saw in the latest release, but that won't satisfy your use case. The data pipe requires that all potential input be available for monitoring - it can't dynamically change signups based on changes to data. So you'll need to monitor both of your weather stations as inputs to a calculation (e.g. Formula or Analysis) and decide based on the data which one to output as the current value. Since you already have an Analysis determining which input is the current one, you could use that to output the value of that current attribute as an output mapped to a PIPoint or Analysis data reference.

            3 of 3 people found this helpful
              • Re: AF Data Pipe Update on Attribute Changes
                neilg

                Hi David, I get what you are saying about the data pipe not being able to update in case of data changes.


                I have an engine which should be able to remove and re-add the attribute from the Data pipe. The engine does more complex things when the closest weather station "data" changes and hence we cannot rely on Analyses itself to give us an output to use. I had thought of removing the attribute from the Pipe but it gave the error. Based on your comment, I upgraded AFSDK to the latest version (2.9.5.8352) to see if I could remove the attribute which has been added to the pipe and I get the same error. Do you know which version this error has been fixed in?

                 

                {[Measured Wind Speed, System.InvalidOperationException: stream not found in Upstream Pipe

                   at OSIsoft.AF.PI.PIPipeToAFPipeTransformer.QueueRemovePIPointSignup(PIPoint inputStream, AFAttribute stream)

                   at OSIsoft.AF.PI.PIPipeToAFPipeTransformer.OSIsoft.AF.Data.IAFEventSource<OSIsoft.AF.Asset.AFAttribute>.QueueRemoveSignup(AFAttribute stream, Object routingToken)

                   at OSIsoft.AF.Data.AFDataPipeAggregator`2.OSIsoft.AF.Data.IAFEventSource<TStream>.QueueRemoveSignup(TStream stream, Object routingToken)

                   at OSIsoft.AF.Data.AFDataPipeSplitter.QueueRemoveSignup(Int32 streamIndex, AFAttribute stream, Object routingToken)

                   at OSIsoft.AF.Data.AFDataPipeSplitter.SplitStream.OSIsoft.AF.Data.IAFEventSource<OSIsoft.AF.Asset.AFAttribute>.QueueRemoveSignup(AFAttribute stream, Object routingToken)

                   at OSIsoft.AF.Data.AFDataPipeCalculator.QueueRemoveSignup(AFAttribute stream, Object routingToken)

                   at OSIsoft.AF.Data.AFDataPipe.RemoveSignups(IList`1 attributes)]}

                  • Re: AF Data Pipe Update on Attribute Changes
                    dmoler

                    Hi Neil,

                     

                    The issue I was thinking of was resolved in 2.9 (AF 2017) - the cause there was that if a referenced attribute was configured on the PIPoint Data Reference and that attribute being pointed to was edited, then a similar issue would occur. On closer inspection, this is not what you are seeing. It seems as if your PIPoint Data Reference attribute is changing which PIPoint it points to without a configuration change which is not expected. The data pipe no longer knows which PIPoint it is supposed to unsubscribe from which you do the remove which is the source of the exception you are getting.

                     

                    I'll do some investigation and see if I can reproduce your issue. To be sure that I'm clear, you have:

                    Element1:

                      -Temperature attribute: ConfigString=M.%@Closest Weather Station|ID%_OBS_MTEMP

                      -Closest Weather Station|ID: Attribute with no data reference updated by Asset Analytics (do I have this right?)

                     

                     

                    You are doing find changes and observer-refresh-process as recommended and not making any other changes in the process with the data pipe, but are still getting into a state where remove signup is giving you an error. Do I have that correct?

                     

                    David

                      • Re: AF Data Pipe Update on Attribute Changes
                        neilg

                        Yep you are correct on your questions and we are not making any further changes apart from what is done by the analyses.

                         

                        What we are trying to do is use the "closest good weather station" for an asset for further calculations.

                         

                         

                        The AF Analyses is simple and all it does is if one weather station goes stale then it flips the "Closest Weather Station|BOM ID" to reflect the next good weather station to use. The "BOM ID" or ID as I had said initially to keep things simple is then used by the "Measured Ambient Temperature", "Measured Wind Bearing" and "Measured Wind Speed" attributes to reflect the next closest weather station to use. Config for these attributes are as "M.%@Closest Weather Station|BOM ID%_OBS_MTEMP".


                        AF Analyses:

                        If(TimeStamp(PrevVal('Weather Station 1|Last Weather Update','*')) > '*-3m') Then 'Weather Station 1|BOM ID'

                        Else If(TimeStamp(PrevVal('Weather Station 2|Last Weather Update','*')) > '*-3m') Then 'Weather Station 2|BOM ID'

                        Else If(TimeStamp(PrevVal('Weather Station 3|Last Weather Update','*')) > '*-3m') Then 'Weather Station 3|BOM ID' Else "Unknown"

                         

                        I guess a way around this is if we put attributes under the "Weather Station #" nodes and monitored them directly and then on change to BOM ID we would be removing an actual good attribute from the pipe and re-adding the attributes for the new weather station to use.

                         

                         

                        Let me know how you go on this.

                        • Re: AF Data Pipe Update on Attribute Changes
                          neilg

                          Hi David, Did you get a chance to investigate this further?

                            • Re: AF Data Pipe Update on Attribute Changes
                              dmoler

                              Hi Neil,

                               

                              I think I can explain what is happening:

                              • The change Analytics is generating is a value update since it is writing to a non-configuration item - these are not considered metadata changes and the data pipe will not remove/resubscribe in this case.
                              • Once the data pipe is subscribed, it does not change the point is signed up for unless it is removed and readded.
                              • The PIPoint data reference reports its PIPoint using the updated substitution parameter.
                              • So once the data changes, the attribute starts responding that it is using a different PIPoint. When you attempt to unsubscribe the attribute, it tries to remove this updated point which is not signed up.

                               

                              I've created a new WI 200243 to resolve the issue of not being able to unsubscribe. With this resolved you would be able to remove/readd without issue, but the pipe will still not dynamically switch which PIPoint is monitored. For your use case I recommend either:

                              • Creating a new PIPoint for "Measured Ambient Temperature" and use the analysis that computes the closest station to also write the data from that station to this point. This will be the highest-performance solution.
                              • Use a formula data reference with conditional statements to return the value from the closest weather station's data.