7 Replies Latest reply on Jun 8, 2010 8:49 AM by Asle Frantzen

    Different results for PrevVal in debug and runmode

    dorj

      I am writing data to PI with 'out of order' timestamps (as this is laboratory data). I need to calculate the difference between the current input and the previous input. In debug mode everything works ok. In runtime mode however I don't calculate on the new value but on the previous value and the value before that, so the calculation is one step behind.

       

      The code looks like:

       

      PreValue = InputTag.PrevVal()

       

      PreTimeStamp = Inputtag.PrevEvent()

       

      PrePreValue = InputTag.PrevVal(PreTimeStamp.UTCSeconds-1)

       

      Outputtag.Value(PreTimeStamp) = PreValue - PrePreValue

       

      I need the outputtag to have the same timestamp as the inputpoint. If I use Value instead of PrevVal() I don't get the same timestamp as the inputtag,

        • Re: Different results for PrevVal in debug and runmode
          Asle Frantzen

          Hi

           

          In runtime, are you scheduling the calculation to run at a certain time - or are you using 'natural' (trigger tag)?

            • Re: Different results for PrevVal in debug and runmode
              Asle Frantzen

              Hallo Dorte

               

              To specify a bit more:

               

              If you use natural scheduling - and set up the calculation to be triggered whenever InputTag gets a new value - your output tag is automatically getting the same timestamp as your InputTag. If you use multiple input tags, you can check the PIACEPoint's .IsTrigger to see which input tag actually trigged the calculation.

               

              So both '*' and the variable ExeTime reflect the time of the execution, and the time of the triggering tag's event.

               

              You can then cut your code down to the following one-liner:

              Outputtag.Value() = Inputtag.Value()-Inputtag.PrevVal('*-1s')

               

               

              Regarding testing and comparing the timestamps you get debugging in the Visual Studio environment, I don't think you can trust those 100%. If you run the 'Test' option from the ACE Wizard context menu, I believe you have better chances of succeeding than if you select only 'Debug'.

                • Re: Different results for PrevVal in debug and runmode
                  dorj

                  Hi Asle,

                   

                  I have tested your solution. The problem is that the outputtag gets the timestamp at the time the trigger occurs and not the timestamp of the archived inputtag. The inputtag is timestamped in the past and not at the time it is written to PI. It is a laboratorie-measurement that needs to be timestamped at the time the sample was taken and the outputtag has to have the same timestamp.

                   

                   

                   

                   

              • Re: Different results for PrevVal in debug and runmode
                hanyong

                Perhaps something like this would work?

                PreValue = InputTag.Value()
                PreTimeStamp = InputTag.PrevEvent(System.DateTime.Now)
                PrePreValue = InputTag.PrevVal(PreTimeStamp.UTCSeconds - 1)
                OutputTag.Value(PreTimeStamp) = PreValue - PrePreValue

                  • Re: Different results for PrevVal in debug and runmode
                    Asle Frantzen

                    I don't think that'll work. One of the most important no-no's in ACE is to use System.DateTime.Now - as this is always slightly different from the execution time. And how about recalculating - then it would definitely not work!

                     

                    We've have a good discussion about this subject in this thread: http://vcampus.osisoft.com/forums/p/1031/5012.aspx

                     

                     

                     

                    But I still think my solution should work. As I said, both '*' and the variable ExeTime reflect the time of the execution, which again reflect the time of the triggering tag's event. So even if Dorte at the time 11 AM is inputting a value with timestamp 10 AM, the InputTag triggers the ACE calculation with its recently added value/event time (10 AM that is).

                     

                     

                     

                    Dorte, you should do a couple of tests. Try manually adding values for a tag, lets say like this:

                    TimeValue
                    12 AM 0
                    1 AM 1
                    2 AM 2
                    3 AM 3
                    4 AM 4
                    5 AM 5
                    6 AM 6
                    7 AM 7
                    8 AM 8
                    9 AM 9
                    10 AM 10
                    11 AM 11

                    After that, it'd be much easier to test your code and check for the different timestamps you get while using the PrevVal and PrevEvent. Add some logging to your code (I use the windows event log), start your ACE calculation, and try adding new values to that inputtag - and keep all your timestamps at "half past", i.e. 9:30 AM, 10:30 AM, etc.

                     

                    If you add the value 9.5 at the timestamp 9:30 AM, you'll know what to expect when calling PrevVal and PrevEvent. (Correct answer would be '9' and '9 AM')