8 Replies Latest reply on Feb 19, 2019 8:24 AM by TDurand

    Custom PI Interface in C




      We are about to develop our own PI Interface, to feed data from our custom system to a Pi Data Archive.

      After searching in the documentation, I expected to use the PI API, because the C language is much easier to interface with.

      I struggle to find a complete code example for a custom interface. Is there any available?


      While searching, I found out that this PI API is actually deprecated.  Is there some tools to easily create my custom interface with the newer API, from C or similar languages?


      Thank you for your time and your help.



        • Re: Custom PI Interface in C
          Rhys Kirk

          You can use the AF SDK Overview with C#.

          That is how we tend to build new data flows into the PI System where an OSIsoft built interface doesn't exist.

          5 of 5 people found this helpful
            • Re: Custom PI Interface in C

              Thank you for your reply! I understand that the C# solution is advised today. However our application is not in C# so we would have to develop a bridge in between. For example I would need to encapsulate the C# methods in a library, to call them from the C. Maybe this is already done? Otherwise it looks more efficient for the development to go with the C PI API.

                • Re: Custom PI Interface in C
                  Rick Davin

                  Hello Thiery,


                  I would not say we are advising to use C#.  Rather we would advise using the correct PI Developer Technology.  AF SDK is for Windows only, and PI Web API would be for cross platform or mobile.  Those really are the only 2 technologies I would recommend for interfaces.  And that would be only after you heed Gregor Beck 's advice to verify there is not an existing interface or connector.  We have had other customers successfully use AF SDK with C.

                  3 of 3 people found this helpful
              • Re: Custom PI Interface in C

                Hello Thierry,


                Before you go build something custom, I suggest to verify if there is a PI Interface or PI Connector which would potentially work. Can you indicate what communication standards your custom system supports?

                2 of 2 people found this helpful
                  • Re: Custom PI Interface in C

                    Thank you for your help. Our communication is using our own tools, especially for security requirements.

                    I worry that adding an additional communication layer may add more burden on configuration, speed and security.

                    However, I will take a look at the list and check if something can fit.

                  • Re: Custom PI Interface in C

                    Let me summarize your developer technology options you have and try to provide you direction with using C/Ada languages. As pointed out by Gregor and reiterated by Rick, you should first check to see if PI Interfaces (over 450+ are available) fit the bill.

                    PI API (deprecated)

                    • Implements ANSI C functions so that code written with the PI API is portable across multiple  environments.
                    • Data access methods strictly restricted to PI Server (Point Database, the Archive, and PI Tables)
                    • PI API 2016+ implements Windows Integrated Security which provides enhanced security for communication
                    • Resources: PI-API Programmer's Help (contains only few code samples), sample code in ...\PIPC\examples install directory

                    PI AF SDK

                    • Microsoft .NET based programmatic library designed for easy access from languages like Visual Basic .NET (VB.NET), C#, and Managed C++
                    • Data access includes Assets(AF), Time series and event frames
                    • Resources: Developing Applications with PI AF SDK

                    PI Web API

                    • RESTful interface to the PI system
                    • Gives client applications read and write access to their AF and PI data over HTTPS
                    • Language and platform agnostic
                    • Resources: Programming in PI Web API


                    PI Web API seems to fit your mold and this is also something I recommend to partners/customers who are looking at re-writing their custom PI API interfaces.

                    Possible implementations

                    • C language: libcurl is a free client-side URL transfer library which provides a C API to make HTTP calls. You can choose other similar libraries which provide a wrapper for making and receiving requests over HTTP.
                    • Ada: PI Web API includes OpenAPI 2.0 specification (also known as a Swagger specification) that describes the RESTful API. The document can be used to generate client libraries including Ada using code generators. Also refer: The Best APIs are Built with Swagger Tools | Swagger

                    Word of caution, both C and Ada are challenging languages for "modern" application development. You may want to ease your development effort by making use of existing libraries as much as possible.

                    4 of 4 people found this helpful