5 Replies Latest reply on May 9, 2011 5:44 PM by charlie@osisoft.com

    How to preview values for a given tag




      For a given tag, if I wanted just to see the last 20 values (e.g., preview),


      What is the best way to do this.




      In OleDB, we can specify

      select top 20….

      But it is not obvious how this could be done through the PISDK.


      It seems we have to specify an arbitrary end date, and hope there is at least 20 values.




      Or specify a specific end date and keep executing (looping) with earlier dates until we have enough values.




      Is there something like, get last 20 values for a given tag.




      If I pick an arbitary far end date, will this have a significant performance impact?


      In orther words, does the RecordedValues api return all the values or is the implementation optimizaed so the PIValues collection only contains a key to the PIValue. And the PIValues are loaded as the collection is iterated.







        • Re: How to preview values for a given tag

          PIData.RecordedValuesByCount should work for you.

            • Re: How to preview values for a given tag

              What value would be specified in the first time parameter.


              I noticed that if I specify and empty string, I have to use PISDK.DirectionConstants.dReverse,


              but the first value is duplicated.


              Is there a list of all the possible timestamp formats and their meaning?


              "T", "-t" "-1h" etc.


              Maybe I have not looked far enough in the sdk.



                • Re: How to preview values for a given tag

                  Hi David,


                  The first time parameter should be a time reference where you want to get values for the tag. For example in your case where you want the latest 20 values of a tag, your time reference should be the current time. The PI time notation for current time is '*'. If you pass in an empty string, I believe the function will automatically uses the current system time, so this should work as well. 


                  As for the direction parameter, you should be using PISDK.DirectionConstants.dReverse (backwards in time) because the values that you want should be older than the current time. The other direction PISDK.DirectionConstants.dForward, looks for newer values relative to the time reference. This would be useful in other situations like finding the 1st 10 values recorded for today.


                  I think the reason for the duplicate value is because of the Boundary type that is specified in the call. The default type is PISDK.BoundaryTypeConstants.btAuto. Which means it will find an interpolated value at the boundary, which is the passed time. Since you are passing the current time to the call, and if there is no newer values, it is assumed the trend is a straight line and interpolation gives you the same value as the latest value. Hence the duplicate value. If you output the timestamp of the value, you should find a difference in the timestamp.


                  If you specify another boundary type PISDK.BoundaryTypeConstants.btInside, it should go away.


                  I am simplifying the explanation slightly, if you want more details about the different parameters. You can refer to the PI SDK Programming Reference for PIData object's RecordedValuesByCount method. You can download the PI SDK Programming Reference from the Library section.