7 Replies Latest reply on Oct 20, 2009 7:11 PM by RJKSolutions

    OnDisconnect event in .Net

      Was asked a question to which I could not find a comprehensive answer.
      I am hoping vCampus can provide that answer


      For the OnDisconnect event, PISDK details the interface IServerDisconnect is to be used to get access to the event.


      Here is the code for VB6/VBA from the manual:


      Option Explicit
      Dim WithEvents srvdisc As ServerDisconnectEvents
      Dim srv As Server

      Private Sub Command1_Click()   
      Set srv = Servers.DefaultServer   
      Dim isrvdis As IServerDisconnect   
      Set isrvdis = Servers   
      Set srvdisc = isrvdis.DisconnectEvents
      End Sub

      Private Sub Command2_Click()      
      srv.Open      srv.Close
      End Sub

      Private Sub srvdisc_OnDisconnect(ByVal pServer As PISDK.Server)      
      MsgBox "disconnected from " + pServer.Name
      End Sub

      The above works great.

      Now try the equivalent code in .Net using the interops and it fails saying "No Such Interface" for IServerDisconnect!?


      After some headsratching we found that using the following does work but wonder why the interface IServerDisconnect does not work using the interop?

      _DServerDisconnectEvents_Event srvdisevt = (_DServerDisconnectEvents_Event) _piSDKServer; // Using IServerDisconnect here fails.

      srvdisevt.OnDisconnect += srvdisevt_OnDisconnect;


        • Re: OnDisconnect event in .Net

          Hi Rhys,


          I had to find out that this seems to be a documentation issue .


          So here we are in VB.NET:

          PublicClass Form1

              DimWithEvents _SrvDiscEv As PISDK._DServerDisconnectEvents_Event
              Dim _PISrv As PISDK.Server
              Dim _PISDK As PISDK.PISDK


              PrivateSub _SrvDisk_OnDisconnect(ByVal PIServer As PISDK.Server) _


              Handles _SrvDiscEv.OnDisconnect
                  MsgBox("disconnected from " + PIServer.Name)
              PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _


              Handles Button1.Click
                  _PISrv = _PISDK.Servers.DefaultServer
                  _SrvDiscEv = _PISDK.Servers
              PrivateSub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _


              Handles Button2.Click
              PrivateSub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _


                  _PISDK = New PISDK.PISDK()

          hope this helps,



            • Re: OnDisconnect event in .Net

              Thanks Andreas.


              Any reason why the IServerDisconnect interface is not supported in the interop?

                • Re: OnDisconnect event in .Net



                  Seems that the .NET event handlers are different. This question started an internal discussion in the PI SDK team. If there is something interesting/usefull, I'll post it here.



                    • Re: OnDisconnect event in .Net

                      When I asked about the differing code "exposure" from COM to the Interops at a recent vCampus webinar I think the answer I got back was that the code is present in the interops, it is just the intellisense that isn't working correctly (or something along those lines), which doesn't seem true.


                      Don't suppose I could get a written explanation from OSI on this one so I understand it better..?
                      Another example would be the "AddTags" method of the IPIPoints2 interface.

                        • Re: OnDisconnect event in .Net

                          I'll check with Charlie - However, if I recall it right he mentioned that he had a look at the intreop with ILDASM - and if you do that with the OSIsoft.PISDK.dll you see that the IServerDisconnect does not expose an event while the _DServerDisconnectEvents_Event does.



                          Another example would be the "AddTags" method of the IPIPoints2 interface


                          This time the code example in PISDK works exactly as in .NET  - what further explanation are you looking for?



                            • Re: OnDisconnect event in .Net

                              I would like to reiterate Andreas' question about the IPIPoints2.AddTags method: can you give more information about the circumstances in which you cannot it?  VS.NET version, language, OS, etc.?  Are you able to reproduce reliably on other machines?  It seems to be that may be a different issue that the former (secondary interface events required a different idl definition, I believe – the fact that "AddTags" does not show up for you may be IDE or project settings or cached information by your version of VS.NET – or you may be using VS.NET 2003 or some such).  Did you check your references?  Version of .NET Framework: 1.1 or 2.0/3.x?

                                • Re: OnDisconnect event in .Net

                                  Ooops, sorry didn't follow this one up.


                                  I am trying to remember what setup I had when I only saw an "Add" method and no "AddTags" for the interface IPIPoints2.  I was using virtual machines so just discarded the VM once I butchered it - from memory it was Vista, .Net 2.0, PI-SDK 1.3.4 (I think!), C#.  I notice now that on 2 or 3 other VM's that the AddTags method is present so maybe I was just having one of those days