12 Replies Latest reply on Jun 22, 2015 9:39 AM by VCampus-METCO

    PI-SDK iPIData2.Summaries2 - start/end time interpretation

    VCampus-METCO

      Hello,

       

      I just noticed some strange behaviour with the way in which the start and end times are interpreted with the IPIData2.Summaries2 call to get the average value for a tag.

      My client is configured with English UK regional settings with short form date dd/mm/yyyy.

       

      Using the tag CDT158, and strings to pass in the start/end time "16/06/2015" and "16/06/2015 23:59:59" the call fails with the error  "[-11059] No Good Data For Calculation"?

      Using the tag CDT158, and strings to pass in the start/end time "16-Jun-15" and "16-Jun-15 23:59:59" the call is successful.

      Using the tag CDT158, and strings to pass in the start/end time "06/16/2015" and "06/16/2015 23:59:59" the call is successful.

       

      So it looks like the SDK call if passed a string will always assume the string is in English USA format and not the regional setting of the client PC.

      Is this a "Feature" or a bug with PI-SDK. The documentation does not mention any restrictions over the date format used with strings.

       

      I am using PI-SDK 2012 so maybe this behaviour has been fixed.

       

      Simon

        • Re: PI-SDK iPIData2.Summaries2 - start/end time interpretation
          dng

          Hi Simon,

           

          I was not able to reproduce your results using with same version of PI SDK. In my test, PI SDK was able to successfully interpret the time string. Can you check the following?

          • If you open up the Windows regional setting for the OS, do you see the correct date format?

              2015-06-17 10_23_50-DNG-CODE - Remote Desktop Connection Manager v2.2.png

          • If you open up About-PISDK > Tools > Set Language, what do you see for user UI, system, and regional setting?

              2015-06-17 10_49_05-DNG-CODE - Remote Desktop Connection Manager v2.2.png

          • Does it happen only for IPIData2.Summaries2 call? Or other calls as well? For example, can you try doing a RecordedValues call? While doing this test, display the PIValue.TimeStamp.LocalDate to see if it is of the correct format. E.g.

           

                      PISDK.PISDK sdk = new PISDK.PISDK();
                      Server myPI = sdk.Servers["DNG-PI2012"];
                      PIPoint pt = myPI.PIPoints["cdt158"];
                      String startTime = "17/6/2015 00:00:00"; // if this fails, change to mm/dd/yyyy format and repeat test
                      String endTime = "17/6/2015 01:00:00";   // if this fails, change to mm/dd/yyyy format and repeat test
                      PIValues vals = pt.Data.RecordedValues(startTime, endTime);
                      foreach (PIValue val in vals)
                      {
                          Console.WriteLine("{0} {1}", val.TimeStamp.LocalDate, val.Value);
                      }
          

           

               This should give you the results with the correct data format:

               2015-06-17 10_53_27-DNG-CODE - Remote Desktop Connection Manager v2.2.png

               Can you verify if this is true?

            • Re: PI-SDK iPIData2.Summaries2 - start/end time interpretation
              VCampus-METCO

              Daphne,

               

              My regional settings are English UK.

              My SDK language is

               

              So this looks like my UI language is set to 1033 (en-us), but my machine is set to 2057 (en-gb)

               

              With these settings using dd/mm/yyyy hh:mm:ss as start/end time I get "No Good Data" Error

              Settings time to US format  dd/mm/yyyy hh:mm:ss, I get a correct value back.

              As I also do if I use PI Time format.

              I changed SDK language to regional settings.and also custom (2057) re-ran the test.

               

              It does not seem to affect how the dates are interpreted, I stopped and restarted by application. Do I also have to stop all other applications on my machine that are using SDK that might be holding the old (en-us) language?

               

              I have never needed to play with the language before so this is the first time I have used this feature of SDK.

                • Re: PI-SDK iPIData2.Summaries2 - start/end time interpretation
                  dng

                  Hi Simon,

                   

                  Yea.. PI SDK should be able to pick up the regional settings once it's changed. Can you give me the following information (requested above)?

                   

                  - Can you try doing a RecordedValues call? Also try different date/time format for the call.

                   

                              PISDK.PISDK sdk = new PISDK.PISDK(); 
                              Server myPI = sdk.Servers["DNG-PI2012"]; 
                              PIPoint pt = myPI.PIPoints["cdt158"]; 
                              String startTime = "17/6/2015 00:00:00"; // if this fails, change to mm/dd/yyyy format and repeat test 
                              String endTime = "17/6/2015 01:00:00";  // if this fails, change to mm/dd/yyyy format and repeat test 
                              PIValues vals = pt.Data.RecordedValues(startTime, endTime); 
                              foreach (PIValue val in vals) 
                              { 
                                  Console.WriteLine("{0} {1}", val.TimeStamp.LocalDate, val.Value); 
                              } 
                  

                   

                  - While doing this test, display the PIValue.TimeStamp.LocalDate to see if it is of the correct format. Can you paste the screenshot of the Console output?

                    • Re: PI-SDK iPIData2.Summaries2 - start/end time interpretation
                      VCampus-METCO

                      With SDK language set to User UI with LCID 1033 (en-us) and times set to US m/d/yyyy format

                      Daphne,

                       

                      With SDK language set to User UI with LCID 1033 (en-us) and times set to US m/d/yyyy format

                       

                       

                           string startTime = "06/17/2015 00:00:00";

                           String endTime = "06/17/2015 23:59:59";

                       

                      Values are returned

                      With time set to UK format

                           string startTime = "17/06/2015 00:00:00";

                           String endTime = "17/06/2015 23:59:59";

                       

                      Error as you might expect

                       

                      With SDK language set to Regional Setting with LCID 2057 (en-gb) and times set to UK dd/mm/yyyy format

                      Error! Which is not what I would have expected.

                       

                      With time set to US format values are returned.

                       

                      So my earlier observation that the SDK language does not affect the interpretation of string times seems to still hold true, i.e. it always expects times to be in US format.

                       

                        • Re: PI-SDK iPIData2.Summaries2 - start/end time interpretation
                          Eugene Lee

                          Hi Simon,

                           

                          Similar to Daphne, I couldn't reproduce your issue.

                           

                           

                          Interpretation of string times doesn't always have to be in US format. I am suspecting this could be due to your version of PI SDK. I am using PI SDK 2014

                           

                          Changing my language to USA format, I can get the datetime in USA format.

                           

                           

                            • Re: PI-SDK iPIData2.Summaries2 - start/end time interpretation
                              VCampus-METCO

                              Eugene,

                               

                              I will try upgrading SDK to 2014 and see if I get the same behaviour.

                              But with the version I have I definitely don’t get the correct behaviour. And the same issue is happening on a customer site. On one machine things work perfectly. On another it does not.

                               

                              regards

                               

                              Simon Dyson | +44 1642 773049

                                • Re: PI-SDK iPIData2.Summaries2 - start/end time interpretation
                                  dng

                                  Hi Simon,

                                   

                                  As I mentioned before, I could not reproduce your issue with PI SDK 2012. With that said, there is no harm upgrading to PI SDK 2014. In fact, you will be able to take advantage of the many bug fixes and enhancement requests. Please let us know if the issue persists after the upgrade.

                                   

                                  Do you have multiple accounts on these computers? Do all these accounts have the same time format settings? What account is the application running as (a user account? a system account?) If the application is not running as your account, can you check the time zone settings for that account? (You can also see all these settings in the registry.) I wonder if the problem is because that the account that the application is running as has a different time format setting.

                                    • Re: PI-SDK iPIData2.Summaries2 - start/end time interpretation
                                      VCampus-METCO

                                      Daphne,

                                       

                                      I upgraded to SDK 2014 and re-ran the program with language set to regional (en-gb) and put in an en-gb date format string.

                                      The dates failed still. It only works with en-us date strings.

                                       

                                      I will just have to work with native DATE types or PI time formats because of this bug.

                                       

                                      I am not using local accounts on my machine, but my normal domain account which is a local admin. My regional settings are English UK from control panel. I don't know where in the registry this info is stored.

                                       

                                      Simon

                                        • Re: PI-SDK iPIData2.Summaries2 - start/end time interpretation
                                          dng

                                          Hi Simon,

                                           

                                          In the registry, the information for the current user is stored at HKEY_CURRENT_USER > Control Panel > International. The information for other users are stored in HKEY_USERS > (user's SID) > Control Panel > International. Are you running the PI-SDK application under your domain account?

                                           

                                          From the information provided so far, it looks like the issue might be caused by some settings on the specific machines. Since you have one machine that is working and one that is not, we can compare the settings on the two machines. If you'd like, we can open up a Technical Support Case for you and do a remote session. Would you like to pursue this path?

                                            • Re: PI-SDK iPIData2.Summaries2 - start/end time interpretation
                                              VCampus-METCO

                                              Daphne,

                                               

                                              Yes I am running from a normal domain account.

                                               

                                              The same problem happens on a number of customer machines. String dates ignore whatever the SDK language setting is set to when they are evaluated. We have changed the settings on a machine that does not work to be exactly the same as a machine that does and it still fails to translate the dates correctly.

                                              .

                                              So it looks like this functionality just does not work properly.

                                               

                                              The workaround is to just stick with PI time format times if using strings. They work on all machines.

                                               

                                              Simon

                            • Re: PI-SDK iPIData2.Summaries2 - start/end time interpretation
                              pthivierge

                              Hello Simon,

                               

                              I think you could quickly workaround this if don't rely on PI SDK to perform the string to date conversion.

                              Instead of passing a string, you can either pass a Date/DateTime object or a PITime object ( you need to reference to OSIsoft.PITimeServer)

                               

                              PITime - From Documentation

                              Dim pt1 As New PITime
                              pt1.LocalDate = Text1.Text
                              

                               

                              Date

                              Depending of the programming language you are using, VBA/VB.Net/C#, you can quickly create a date:

                              string date = "2015-06-18";
                              DateTime dt = Convert.ToDateTime(date);
                              

                               

                              This way you will have the power to troubleshoot and adapt code better to fit your needs to manipulate the dates.

                               

                              Regards,

                                • Re: PI-SDK iPIData2.Summaries2 - start/end time interpretation
                                  VCampus-METCO

                                  Patrice,

                                   

                                  Thanks for this.

                                  The application was actually developed by a customer and if I were to do the same thing I would also use native datetime data types to get around this.

                                  I have seen similar issues when working on systems with mixed user regional settings, i.e. English and German/Norwegian, where we were given numbers and dates in different formats.

                                  .

                                  For those we used a simple wrapper routine that would do a simple check to see whether we were in German

                                   

                                   

                                              If CDbl("1.1") > 2 Then

                                                 'German

                                            Else

                                                 'English