|
|
Rank: Member Groups: Member
Joined: 8/26/2009 Posts: 10 Location: Canada
|
I am trying to subscribe to the OnDisconnect event of the Server object but I am getting an invalid cast exception.
Here is what I am doing.
Can you tell me what is going wrong? Any help would be most appreciated!
Regards, Joel.
PISDK.PISDK _piSDK = new PISDK.PISDK();
Server _piSDKServer = _piSDK.Servers["server_name"];
IServerDisconnect _srvdis = (IServerDisconnect) _piSDKServer; //The error occurs here. Invalid cast error on DisconnecEvents.
ServerDisconnectEvents srvdisevt = _srvdis.DisconnectEvents;
srvdisevt.OnDisconnect += srvdisevt_OnDisconnect;
void srvdisevt_OnDisconnect(Server pServer) { ... }
|
|
|
|
|
|
|
|
Rank: Administration
 Groups: Administration
Joined: 6/20/2008 Posts: 409 Location: Cheshire, United Kingdom.
|
Hi Joel, Set IServerDisconnect to Servers collection rather than an individual server. So Code: ServerDisconnect _srvdis = (IServerDisconnect) _piSDK.Servers;
Rhys. OSIsoft PI System SpecialistsPI consultancy on PI Systems, PISDK, AFSDK, OLEDB etc and PI custom developments. Well pretty much anything to do with PI!
|
|
|
Rank: Member Groups: Member
Joined: 8/26/2009 Posts: 10 Location: Canada
|
Hi,
Thanks for the reply.
I tried as you suggested but I am receiving the same error as when I used the individual Server.
Your sample shows that _srvdis is of type ServerDisconnect. Is this a typo? I do not see an object of type ServerDisconnect...only IServerDisconnect.
Regards, Joel.
|
|
|
Rank: Member Groups: Member
Joined: 8/26/2009 Posts: 10 Location: Canada
|
I've changed the code thusly:
_DServerDisconnectEvents_Event srvdisevt = (_DServerDisconnectEvents_Event) _piSDKServer;
srvdisevt.OnDisconnect += srvdisevt_OnDisconnect;
Rather than declare them as IServerDisconnect and ServerDisconnectEvents, I am using _DServerDisconnectEvents_Event.
I am not sure what the _D classes are but they seem to work...same goes for EventPipes.
This code executes without exception. Now I just need to test if the server actually raises the event like it is supposed to.
I will let you know.
Regards, Joel.
|
|
|
Rank: Member Groups: Member
Joined: 8/26/2009 Posts: 10 Location: Canada
|
The last code I posted allows me to receive the disconnect event.
Regards, Joel.
|
|
|
Rank: Administration
 Groups: Administration
Joined: 6/20/2008 Posts: 409 Location: Cheshire, United Kingdom.
|
Hi Joel, OK cool, glad you got it to work. Strangely I ran some VBA code and the IServerDisconnect interface works a treat so must be something lost in transalation with COM. I will follow up with OSI for completeness as to why the difference... Cheers, Rhys. OSIsoft PI System SpecialistsPI consultancy on PI Systems, PISDK, AFSDK, OLEDB etc and PI custom developments. Well pretty much anything to do with PI!
|
|
|
|
Guest
|