1 Reply Latest reply on May 2, 2012 9:17 PM by mhamel

    Create EventPipeEvents to add handler

    yyao

      Here is my code snippet in c#:

       
      PISDK.Server _server = _pisdk.Servers["myserver"];
       
      // PI Server -> PI Point
      PISDK.PIPoint _point = _server.PIPoints["cdt158"];
      
      EventPipeEvents eventPipeEvents = _point.Data.EventPipe.Events;
      
      PISDK._DEventPipeEvents_OnNewValueEventHandler newValueHandler = new PISDK._DEventPipeEvents_OnNewValueEventHandler(EventPipeEvents_OnNewData);
      
      eventPipeEvents.OnNewValue += newValueHandler;
      

       

       

       

       

      When I debug the code, I am getting "Unable to cast COM object of type 'System.__ComObject' to interface type 'PISDK._EventPipeEvents'" on line "EventPipeEvents           eventPipeEvents = _point.Data.EventPipe.Events;"

       

       

       

      Please help.

       

       

       

      Thanks!

       

       

       

      -Yifei

        • Re: Create EventPipeEvents to add handler
          mhamel

          @Yifei: AFAIK, I think this is because you are not indicating how to cast your _NewValueHandler object. Can you try to cast as proposed below?

           
          //...
          
          //Create the event handler for InterfaceName_EventNameEventHandler.
          _NewValueHandler = new PISDK._DEventPipeEvents_OnNewValueEventHandler(EventPipeEvents_OnNewData);
          eventPipeEvents.OnNewValue += (PISDK._DEventPipeEvents_OnNewValueEventHandler) _NewValueHandler;
          

          Let me know if that worked.