3 Replies Latest reply on Feb 23, 2017 10:44 AM by gregor

    Get the time when a tag change

    patrik0173

      Hello!

       

      Do anyone know how to get the time and the total time for a tag (string) when it changed?

       

      Value1: 2017-02-21 08:49 (the time when operator started the batch)

      Value2: Now() - Value1 (total time since start of batch)

       

      My plan is to show in processbook (realtime) the time and the time elapsed since the batch changed. :-)

       

      //Patrik

       

        • Re: Get the time when a tag change
          gregor

          Hello Patrik,

           

          There are a lot of ways to accomplish what you like to do. Let's look at the 2 approaches that appear to meet best. The first one is to create a PI Calculation DataSet in PI ProcessBook and the second one would be using Asset Analytics. What both have in common is the PI Expression Syntax. I am using the sample tag BA:ACTIVE.1 for this example and suggest using the PI Performance Equation Reference manual (%pihome%\help\pereference.chm). Alternatively you can use the PE Reference at Live Library.

          The calculation approach that I am using is to look backwards in time when the value has changed to the current value and to calculate the time elapsed since then. The first function that appears useful is FindNE

          Please check out the parameter description e.g. for the endtime parameter. If the endtime is before the starttime, the function will look backwards in time. Please make sure you chose a period which is not too small depending on how often you expect a change. I have chosen 60 minutes which is already too short considering BA:ACTIVE.1 is not changing very frequent.

          An additional input parameter is the current value which you can get by either using TagVal or by just referencing the PI Point 'BA:ACTIVE.1'. So, let's wrap up the FindGE approach:

           

          FindNE('BA:ACTIVE.1', '*', '*-60m',TagVal('BA:ACTIVE.1'))

           

           

          Now we want the difference (seconds) between now and the time returned by FindNE

           

          '*'-FindNE('BA:ACTIVE.1', '*', '*-60m',TagVal('BA:ACTIVE.1'))

           

           

          This equation should work as PI Calculation within ProcessBook or within Asset Analytics.

          2 of 2 people found this helpful
            • Re: Get the time when a tag change
              patrik0173

              Thank you Gregor :-)

              I put it in AF, then connect to that asset from processbook .... thank you again

                • Re: Get the time when a tag change
                  gregor

                  Hello Patrik,

                   

                  I am glad to read my suggestion was useful for you.

                   

                  If you agree with my understanding that my above reply is the [Correct Answer] please chose it as such. This will make it easier for other users to quicker find the answer when looking at your question which is extremely useful with questions that contain some back and forth because the reader doesn't have to read the complete thread to find the post which contains the correct information. For now, I will mark your question as assumed answered.