7 Replies Latest reply on Mar 19, 2015 12:12 AM by rk2479

    Oldest tag value available on PI server

    rk2479

      I want to find out what is the oldest tag value available for the tag on my PI server. I have tried using the SQL commander but it is somehow not working and sometimes giving me a timeout error.Will check why the error is.

       

      But thought of checking if there is any other simple method to find the oldest tag value and timestamp...

        • Re: Oldest tag value available on PI server
          zge

          Try this PE:

          FindEQ('cdt158', '1-Jan-2000','*', 0)

           

          Put any time that is before the server installation as start time, and any value that this tag's value is certainly not going to be equal to as the value parameter. And this function will return the timestamp of the first event of the tag. You can use some other parameters to filter out or include system digital states such as "Pt Created".

          • Re: Oldest tag value available on PI server
            xwang

            Hi,

             

            If SQL commander not work, please see the following code as the reference, which created by one of our Techsupport engineers.

             

            var piSystems = new PISystems();            
            var database = piSystems["olekspc"].Databases["NuGreen"];
             
                        var attr = AFAttribute.FindAttribute(
                            @"\\OLEKSPC\NuGreen\NuGreen\Little Rock\Distilling Process\Equipment\B-125|Process Feedrate",database);
             
                        //
             Cannot use AFTime.MinValue directly as it will result in exception 
            returned from the PI Server - "[-11049] Invalid Times For Archive Call"
                        // shift it 1 millisecond to avoid exception to be thrown
                        var startTime = AFTime.MinValue.UtcTime.AddMilliseconds(1);
                        var value =
                            attr.Data.RecordedValuesByCount(startTime, 1 /*count*/, true /*forward*/, OSIsoft.AF.Data.AFBoundaryType.Inside, null, null, false).Single();
             
                        Console.WriteLine("Attribute {0}: {1} {2}", attr.Name, value.Timestamp, value.Value);
                        Console.ReadKey();
            

             

             

            In this example, it used an AF Attribute to get the value out.  If you do not wish to use AF Attribute, it is easier to get out the value from PI Server directly.  The following code could be as the reference:

            PIServers. servers = new PIServers();
            PIServer server = servers["your server name"];
            PIPoint point = PIPoint.FindPIPoint(server,"your tag name");
            var startTime = AFTime.MinValue.UtcTime.AddMilliseconds(1);
            var value = point.Data.RecordedValuesByCount(startTime, 1 /*count*/, true /*forward*/, OSIsoft.AF.Data.AFBoundaryType.Inside, null, null, false).Single();
            

             

            Hope this helpful.

             

            Xi Wang

            PI Developer Club

            • Re: Oldest tag value available on PI server
              dng

              Just throwing another alternative out there, you can use PI DataLink > archive value and use the retrieval mode of "next only" to get the first timestamp and tag value for a list of tag (if you set your timestamp early enough). Note that you are likely to get PtCreated as the first archived value. Depending on your need, you can then query the next timestamp and value.

              2015-03-10 14_50_34-Book1 - Excel.png

              • Re: Oldest tag value available on PI server
                Steve Boyko

                Try the performance equations NextEvent('tag','1-jan-1970') and NextVal('SINUSOID','1-jan-1970') - the first gives the timestamp and the second gives the value.

                 

                PI will not accept a date prior to January 1 1970 so you are guaranteed to get the first value. Relying on your PI server installation date is not reliable as you can backfill data prior to that time.

                • Re: Oldest tag value available on PI server
                  rk2479

                  Thanks you everyone.. I have tried the Datalink option and worked fine. Will try on the other options as well.

                   

                  Appreciate the response.