5 Replies Latest reply on Dec 1, 2015 10:10 AM by pthivierge

    PI SDK method for PI API Time functions


      How I can replace the following PI API function using PI SDK?






      I don't want to reference PI API in my project so I have to get rid of all the PI API calls. So please let me know how I can replace the above calls using PI SDK.

      Plz don't recommend me a solution using AF SDK as I have to use only PI SDK here.

        • Re: PI SDK method for PI API Time functions
          Asle Frantzen



          I haven't used the PI API so I can't tell you exactly which methods to replace them with, but I'd recommend you start by looking at the PITimeServer assembly/dll



          • Re: PI SDK method for PI API Time functions

            Hello Mohammed,


            What is the programming language that you are using?

            Also, if you elaborate on what your code is doing we may be able to provide you a sample to do the same thing with PI SDK.




            I have searched our website to first find what these function do and here are my remarks for usage with the PI SDK:


            This functions splits a timestamps into month, day, year, etc...


            With PISDK, you receive PITime Objects, and PITime objects have a .LocalDate attribute.  This would return a DateTime object in .NET that you can manipulate easily to get the date parts.

            I'll need more information to better guide you.




            I am not sure about this one, it seems to be related with open-vms... can you elaborate why it is needed in your code?




            PITime internally stores the time in UTC,


            using piTimeObject.UTCSeconds could be an option.

            if you need sub-seconds precision then usin UTCFileTime may be better.





            Please consider this as a raw answer, getting more information will greatly help to provide more accurate information.

              • Re: PI SDK method for PI API Time functions

                I am using C++ as programming language in my application. So example with C++ will really help.


                I use pitm_secint to extract the date fields. for example, If the PI Point Type is of type pttypTimestamp, then I will get the value as double. so I have to extract the value as Year, Day, Month & so on. Let me know how can i do this using SDK interfaces.


                I use pitm_setpitime to fill PITIMESTAMP from a double time value (epoch time), then I use pitm_getutctime to get the UTC time by providing PITIMESTAMP value. Basically, I will get the time as long value and I have to get its relevant UTC time as long. So wit PI API pitm_setpitime & pitm_getutctime  are used to do so. Now I need to do the same using SDK.


                Hope I made clear on what I am trying to do. You guidance here would be really appreciated.

                  • Re: PI SDK method for PI API Time functions

                    Hi Mohammed,


                    Below is sample code where you can get the Year, Month, Day etc., and get the utctime. I hope this is helpful.


                       // Get PI-SDK COM object
                              IPISDKPtr pPISDK(__uuidof(PISDK));
                           // Get and set server pointer
                       ServersPtr pServers = pPISDK->Servers;
                       ServerPtr  pServer  = pServers->GetDefaultServer();  
                              _PointListPtr pPointLst = pServer->GetPoints("tag='CDT158'", 0);
                       long x = 1;
                       _variant_t vVar(x);
                       PIPointPtr ptPtr = pPointLst->GetItem(&vVar); 
                       ptPtr = pPointLst->Item[&vVar];
                       _PIValuePtr pvPtr(ptPtr->Data->Snapshot);
                       _PITimeFormatPtr pTime;
                       cout << pTime->OutputString << endl;
                       DATE date = pTime->GetLocalDate();
                       cout << date << endl;
                       CY cyDate = pTime->GetUTCFileTime();
                       cout << cyDate.int64 << endl;  //Can be used for FileTimeToSystemTime() Year, Month, Day...
                       double utcSeconds = pTime->GetUTCSeconds();
                       cout << utcSeconds << endl;
                          catch( ... ) 
                      cout <<  "exception" << endl; 
                    2 of 2 people found this helpful