12 Replies Latest reply on Jun 20, 2017 6:23 AM by Arpit

    PI Server time

    Arpit

      Hello

       

      I have a custom application which collects(reads) data from PI server.

       

      The server on which that application is running is set up to use BST time, however the PI server which i am using to collect data is not set up to observe day light saving time, so currently it is running in GMT/UTC.

       

      Now i see a mismatch of 1 hour in the time/data between the interface server (BST) and PI server (GMT/UTC)

       

      What are the best ways to make the data in sync between 2 servers ? If i need to make a change in the application is there any way i can use PI server time?

       

      Thank you!

        • Re: PI Server time
          Rick Davin

          Hello Arpit,

           

          Which developer technology are you using for this application: PI AF SDK or PI SDK?  Please note that for new applications we strongly discourage PI SDK as its been targeted for deprecation.

           

          What version of the respective SDK are you using?  What language are you developing in?

            • Re: PI Server time
              Arpit

              Hello Rick

               

              Thank you for your reply!

               

              Application uses PI SDK with C# and the method used for reading the data is RecordedValues.

               

              Application is already developed and is Live, my concern here is that the interface time is in BST and PI Server time is in GMT, that is where i see mismatch in time

                • Re: PI Server time
                  Rick Davin

                  PI SDK with C# uses Microsoft's Interop services.  The big thing at play here is not so much the PISDK Interop but the PITimeServer Interop.  Here's where it gets confusing: though the interop exposes the times as .NET DateTime objects, the actual PITimeServer code is written in C++ and has no idea about the existence of a DateTime object.  In C++ the dates were stored as Double and references local time with absolutely zero knowledge of time zones, UTC, or DST.

                   

                  Using the .NET Interops, if you tinkered around with PITime.LocalDate you will discover that is Kind is not Local as you would expect but rather is Unspecified, which itself is unaware of DST.  Hence the 1 hour offset.  The key would be to convert the PITime.LocalDate so that its Kind is Local, and then .NET should be able to handle DST correctly.

                   

                  // assuming that pt is a PITime object
                  var localTime = DateTime.SpecifyKind(pt.LocalDate, DateTimeKind.Local);
                  // now use localTime instead of pt.LocalDate.
                  
                  1 of 1 people found this helpful
                  • Re: PI Server time
                    Rick Davin

                    Hi Arpit,

                     

                    Did my suggestion yesterday work for you?  Or is it still off by 1 hour?  If that small bit of code did not work, you may try adding a new class to your app:

                     

                    using System;
                    using PITimeServer;
                    
                    public static class PITimeExtensions
                    {
                        private static readonly DateTime beginningOfUtcTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
                        public static DateTime ConvertToLocalTime(this PITime inputTime)
                        {
                            var utcTicks = Convert.ToInt64(inputTime.UTCSeconds * TimeSpan.TicksPerSecond);
                            var utcTime = beginningOfUtcTime.AddTicks(utcTicks);
                            return utcTime.ToLocalTime();
                        }
                    }
                    

                     

                    Please follow up with your thread to let us know if your problem is solved or if you need more help.

                    • Re: PI Server time
                      gregor

                      Hello Arpit,

                       

                      Please allow me to refer you to Deprecating the PI SDK

                      Even I am pretty certain that the options suggested by Rick Davin are sufficient we recommend using AF SDK upon PI SDK with recent development projects.