2 Replies Latest reply on Jun 7, 2010 11:48 AM by deonpienaar

    Recommended error trapping/handling when using Event Pipes (IEventPipe2)

    deonpienaar

      Good day,

       

      We're building a few proof-of-concepts involving periodic or on-event data retrievals from PI.  Immediately working with using event pipes, I see a possible problem regarding error handling and recovery (such as internal SDK errors, disconnected from server, error with polling etc).

       

      To be clear: signing up for updates will only happen during initialization, so we don't have to worry about adding/removing more points for signup.  _pipe.RemoveSignUp() is called upon termination (if _pipe!=null). 
      What are the recommended errors to trap for during initilization, the OnNewValue event and generally checking when the event pipe has failed? Can the event pipe be reinitialized or should all objects be made NULL and re-created.

       

      Also, during the OnNewValue event, would it be beneficial to attempt the 'Using' block to assit with memory manayement?  (For example, the code below uses the System.Array object.  I could inherit it and attempt to implement the iDisposable interface and dispose the related objects)

      Thanks in advance, below is a summary of the code in use:

      Property Declarations


      //SDK connection
      PISDK.PISDK _sdk = new PISDK.PISDK();
      PISDK.Server _server;
      PointList ptlist = new PointList();

      //EventPipes
      PISDK._DEventPipeEvents_Event _ptEvent;
      IEventPipe2 _pipe;

       

      Initialization


      //add points to pointlist
      _pipe = (IEventPipe2)ptlist.Data.EventPipe;
      _ptEvent = (_DEventPipeEvents_Event)_pipe;
      _ptEvent.OnNewValue += new _DEventPipeEvents_OnNewValueEventHandler(_ptEvent_OnNewValue);
       

       

      On new value Event handling


      private void _ptEvent_OnNewValue()
      {
       Array tmpArray = _pipe.TakeAll();
       foreach (Object obj in tmpArray)
       {
        //handle values
       }
      }

        • Re: Recommended error trapping/handling when using Event Pipes (IEventPipe2)
          dcoda

          Hello Deon,

           

          With respect to error handling and event pipes - all of the SDK calls should throw proper COM exceptions which can be caught using the standard try-catch functionality of the ,NET languages.  All of the exceptions from the SDK should be COM, so the COMexception object in .NET should be appropriate for accessing and interpreting them.  Often we recommend a try-catch for specifically COM exceptions and then a second one for general system exceptions.

           

          With respect to specific trappable errors - I would refer to the online help file (pisdk.chm) - the programmers guide lists the common trappable errors with each object's entry for a given method (and the standard errors are listed in a separate page called (appropriately) "Standard Errors").  The PI-SDK error codes (those that are defined in the PI SDK have an enumeration that is delineated by the "pse" prefix (for example, pseEVPIPENOTFOUND) for common access and defintion for PI SDK based applications.

           

          Also note, an example of defining and using event pipes in VB.NET and C# (though they are event pipes for module DB events) are available through the techsupport website for download.  This shows a basic error handler and all of the proper definition syntax for event pipe usage in .NET.

           

          With respect to your question about reconnection, the event pipe will attempt reconnect under the hood - and with newer versions of the PI server, that connection should persist through disconnections minimizing missed events.  You should not need to explicitly reconnect under normal circumstances.  There could be some extreme errors where the event pipe was not created, created correctly, or been destroyed somehow, that might require clean up  - but for the more common disconnection (and those happen with more frequency in real life than anyone cares to admit), the event pipe should recover its connection with out additional action by the application.

           

          Hope this helps.

           

          - Dave Oda, Software Developer, OSIsoft