9 Replies Latest reply on Jul 19, 2010 2:24 PM by bpolaski

    PI Archive Start Time

    bpolaski

      How do I determine the start time of the primary archive through the PI-SDK?

       

       

        • Re: PI Archive Start Time

          You cannot.

           

          Although the PI SDK offers some "system management" functionality, its main focus tends to be on "data access". And as far as data access, one should never have to care about which archive you are getting data from (or writing data to), nor the dates/details about specific archive files. This is true for any data access product, not only PI SDK...

           

          There are other tools to deal with archive management (e.g. piartool, pidiag), so I would recommend you touch base with our regular Technical Support team about this kind of system administration tasks...

            • Re: PI Archive Start Time
              bpolaski

              How does the stand-alone PI-SMT determine the start/end of archives?

                • Re: PI Archive Start Time
                  MichaelvdV@Atos

                  For one of our applications, where we needed this kind of specific information, we used piconfig from our .NET application, redirect the stdin and stdout, and get the information that way. It worked great, but it isn't a very nice solution.

                    • Re: PI Archive Start Time

                      @Brian: your best option is to make use of one of these command-line utilities I mentioned in my reply (but wrapped in .NET calls). That's also what Michael did, according to his reply. The easiest is "piartool -al", which lists all archives on the PI Server. You can also use "piartool -al 1" to get just the Primary Archive.

                       

                      The rest is standard .NET stuff (i.e. not related to PI at all)... reading from and writing to files, launching processes, etc.

                       

                      Below is an example of how you could write the appropriate command to run into a .bat file, execute that .bat file and send the results to another text file, and then parse that text file. This is provided as an example only - make sure you edit it to correspond to your environment and add the appropriate checks and error handling...

                      System.IO.StreamWriter sw = null;
                      System.IO.StreamReader sr = null;

                      // Write a new .bat file with the appropriate command in
                      string strCommandFile = Environment.CurrentDirectory.ToString() + \\al.bat;
                      string strOutFile = Environment.CurrentDirectory.ToString() + \\al.out;
                      sw = new System.IO.StreamWriter(strCommandFile, false);
                      sw.Write("C:\\PI\\adm\\piartool.exe -al > \"" + strOutFile + "\"");
                      sw.Close();
                      sw = null;

                      // Make a new Process with stdout redirected to me
                      // UseShellExecute = true is required for piartool to run
                      // You cannot programmatically redirect output to a variable, so output must be redirected to a file
                      System.Diagnostics.Process proc = new System.Diagnostics.Process();
                      proc.EnableRaisingEvents = false;
                      proc.StartInfo.UseShellExecute = true;
                      proc.StartInfo.CreateNoWindow = true;
                      proc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                      proc.StartInfo.RedirectStandardOutput = false;
                      proc.StartInfo.FileName = strCommandFile;

                      if (proc.Start())
                      {
                          proc.WaitForExit();
                      }

                      //Parse the al.out file
                      if (System.IO.File.Exists(strOutFile))
                      {
                          //Read it in.
                         
                      sr = new System.IO.StreamReader(strOutFile);

                          listBox1.Items.Clear();

                          while (sr.Peek() > -1)
                          {
                              // Read in a line
                              System.String strLine = sr.ReadLine();

                              // Do what you need to do with this line...

                          }
                      }

                      // Close and delete files
                      sr.Close();
                      sr = null;
                      System.IO.File.Delete(strOutFile);
                      System.IO.File.Delete(strCommandFile);

                    • Re: PI Archive Start Time
                      cescamilla

                      Brian Polaski

                      How does the stand-alone PI-SMT determine the start/end of archives?

                       

                       

                      It uses a specific and really hidden feature we don't know about, and the ones who knew about it has been silenced.

                       

                       

                       

                      I would follow Michael's suggestion or Steve's comment, the only feasible way for an external application to do so is running at the PI Server and gathering that info by running te appropiate commands.

                    • Re: PI Archive Start Time
                      Martin.Thivierge

                      Steve Pilon

                      ... one should never have to care about which archive you are getting data from (or writing data to), nor the dates/details about specific archive files. This is true for any data access product, not only PI SDK...

                       

                      I'd like to agree with that one but I can't.  Unfortunately, some of my clients are using massive amount of tags ( 200k and more) and they quite often write back in the past to achieve forecating analysis.  Usually, they will delete all the data from a tag and will re-use this reprocessed tag (because you can wite data in them beyond the Primary Archive cutoff date) for something else or to perform a recalculation using ACE.  As such, they built a nice application that call the SDK subroutine PIPoint(myPointName).data.removeValues(myStartDate, "*", PISDK.DataRemovalConstants.drRemoveAll) which is fully documented and supported by the SDK.

                       

                      This lead to biggest problem with PI...if you delete data spanning over multiple archive, the chance is very high that you will end up with archive corruption and won't be able to collect anymore data until those archives are reprocessed (and primary archive shifted).

                       

                      This bug as been around for years now and the only way to mitigate it would be to have a way to let the application know that the user is about to delete data beyond the primary archive and to warn or stop the user from doing so.

                       

                      Two option here:

                       

                      - Correct that nasty bug once and for all.

                       

                      - Expose the start date of the primary archive via SDK for at least mitigating the problem caused by RemoveValues.

                       

                      If you guys know another way to delete data spanning over multiple archive, without the nasty corruption risk, I would be very grateful (and my clients too) to hear about it.

                       

                       

                       

                      Cheers,

                       

                      Martin

                        • Re: PI Archive Start Time

                          While I understand your different requirements, I think you are mixing a few different things here:

                          • From a 'Data Access' standpoint (reading, writing, editing, deleting values), you should definitely not have to care about which particular archive you are accessing.
                             
                          • From a 'System Management' standpoint, you indeed have to know some things and take some actions (e.g. reprocessing an archive) to allow the users and client applications to read/write data at will, without having to worry about which particular archive they are accessing.

                          If you have ideas around manageability of archives, reprocessing, etc., I would like to propose you contact our regular Technical Support, as they are the ones who deal with Enhancement Requests and Bug Fixes (we're just the architecture/development/integration guys ). That way you can get the Punchlist Item (PLI) created if it doesn't already exist, or have your call linked to it to give "more weight", if it does exist.

                           

                          As you will find in other discussion threads in these forums, some users already suggested ideas around this - which means PLIs already exist. Examples of that are this thread and this other thread.

                           

                          Also, regarding that long-standing corruption bug you referred to, do you have the PunchList Item (PLI) number? Can you find it listed under http://techsupport.osisoft.com > PI Server > Known Issues? Whether you find it there or not, I would say the same as above: contact our regular technical support team about this... they will treat it as need be and channel that through Product Management and Engineering.

                            • Re: PI Archive Start Time
                              bpolaski

                              Steve,

                               

                              In our particular scenario, knowing where the data will ultimately reside is important.  We will create tags automatically, and when this is done there is already data ready for the new tags (using UFL interface).  We then plan to programatically write a value in the past (at the start of the primary archive) and delete the initial "Pt Created" so that the data comes into PI in order.  However, we are drawing a line in the sand with the primary archive start time - any data prior to this will be ignored.  This is so we can avoid trying to dynamically reprocess prior archives (in order to get the new point header info into them for the past data).