In runtime, are you scheduling the calculation to run at a certain time - or are you using 'natural' (trigger tag)?
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'.
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.
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
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:
Time Value 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')
Thanks for your input!
Your solution Asle works fine. (I had made a 'small' mistake in the first test run - but now it works). The suggestion of using windows eventlog for debugging was also very helpful.
Sure, no problem!
Glad to hear it works fine now!