6 Replies Latest reply on Jan 29, 2018 1:01 PM by Marcos Vainer Loeff

    How to create Event Frame using PI Web API Wrapper for VBA

    dljzc

      Hi

      Anyone who know how to use PI Web API Wrapper for VBA to create event frame?

       

      I read user guide which has the function called "CreateEventFrame"

      But when I try to define a new event Frame, look like all properties of the new PIEventFrame are Readonly.

       

      who can tell me how to define a new event frame?

       

      Thanks

       

       

      Jin

        • Re: How to create Event Frame using PI Web API Wrapper for VBA
          rschmitz

          Hi ZongCheng,

           

          I took a look into this and you should be able to set the properties on the AFEventFrame Object before sending them through the client, those properties aren't read-only. What errors (if any) are you receiving if you step through the debug code when trying to set those properties?

           

          I wrote up a quick example chunk of code for reference if you need:

           

          Sub CreateEventFrame()
              Dim client As New PIWebApiClient
              Dim connectedToPIWebAPI As Boolean
              connectedToPIWebAPI = client.Connect("https://<PI WEB API BASE URL>/piwebapi", True)
          
          
              Set afServer = client.AssetServer.GetByName("<AF Server>")
              Set afDatabase = client.AssetData.GetByPath("<AF Server>\NuGreen")
             
              Dim response As ApiResponseObject
              Dim newEF As New PIEventFrame
              newEF.Name = "TestEventFrame"
              newEF.StartTime = "01-04-2018 12:00:00"
              newEF.EndTime = "01-05-2018 12:00:00"
              newEF.TemplateName = ""
             
              Set response = client.AssetData.CreateEventFrameWithHttpInfo(afDatabase.webId, newEF)
          End Sub
          
          
          
          
          
          
          
          
          
          

           

           

          Cheers,

          Rob

          • Re: How to create Event Frame using PI Web API Wrapper for VBA
            dljzc

            Hi Rob

             

            do you have time, can we set up a webex?

             

            Thanks

             

            Jin

              • Re: How to create Event Frame using PI Web API Wrapper for VBA
                kduffy

                Hi Zongcheng,

                 

                I'm not sure if you're still working on this since it's been a few weeks, but the first thing I would check is if your PI Web API instance is set to DisableWrites. Open PSE and connect to the AF server hosting the configuration for this PI Web API instance, then connect to the Configuration database, then to OSIsoft > PI Web API > [Name of PI Web API server] > System Configuration. Check the attributes tab and see if DisableWrites is set to True.

                 

                As for the WebEx, since this isn't technically a released product, but is sample code provided by Marcos as is. Therefore we can't guarantee support for it, however if you were to call in to techsupport we could look at the general health of your PI Web API and ProcessBook VBA installations. On a more granular level than that, though, maybe Marcos could assist.

                 

                Kelsey

                  • Re: How to create Event Frame using PI Web API Wrapper for VBA
                    Marcos Vainer Loeff

                    Hi Zongcheng,

                     

                    I've copied and modified the code below and it worked successfully:

                     

                    Public Sub ButtunPressed()
                        Dim client As New PIWebApiClient
                        Dim connectedToPIWebAPI As Boolean
                        connectedToPIWebAPI = client.Connect("https://marc-web-sql.marc.net/piwebapi", True)
                        Dim afdb As PIAssetDatabase
                        Dim af As PIAssetServer
                        Set afdb = client.AssetDatabase.GetByPath("\\MARC-PI2016\AFSDKTest")
                        Dim nEF As New PIEventFrame
                        nEF.Name = "Test EF"
                        nEF.StartTime = "04/01/2018 12:00:00"
                        nEF.EndTime = "05/01/2018 12:00:00"
                        nEF.TemplateName = ""
                        Dim res2 As ApiResponseObject
                        Set res2 = client.AssetDatabase.CreateEventFrameWithHttpInfo(afdb.WebId, nEF)
                        MsgBox (res2.StatusCode)
                        
                    End Sub
                    

                     

                    What I think it is not working is how VBA handles the error. In my case, if the WebId input from the CreateEventFrameWithHttpInfo is wrong, I do receive the 80131500 code but with an error message which helps me troubleshoot as shown below:

                     

                     

                    You need to find out the content of this error message. Here are some suggestions:

                     

                    1)Use POSTMAN to make a similar POST request in order to create an event frame. Review the response.

                    2)Install Wireshark and try to review the network packages

                    3)Create a Console Application using .NET Framework and add a reference to the library (PIWebApiWrapper.dll). Write a similar code in C# or VB.NET.

                     

                    Hopefully VS will let you know the error message and then it will be easy to troubleshoot with the help of OSIsoft TechSupport.

                     

                    Finally, the new version of this library compatible with PI Web API 2017 R2 is available on GitHub. PIAssetData was renamed to PIAssetDatabase.

                     

                    Let me know if this helps you!