4
« on: January 24, 2024, 08:44:21 AM »
I'm using the ClxDriver and I create a new connection like this:
_CLXDriver = new ClxDriver.EthernetIPforCLX
{
CIPConnectionSize = 508,
DisableMultiServiceRequest = false,
DisableSubscriptions = false,
IPAddress = ClientIP,
PollRateOverride = 500,
Port = 44818,
ProcessorSlot = 0,
RoutePath = null,
Timeout = 4000,
UseOmronRead = false
};
I wan't to make a class that automatically connects to the PLC when it is available, keeps retrying to connect when the PLC is not available and publishes an event when the connection changes. I subscribe to the following events:
_CLXDriver.ConnectionEstablished += OnConnectionEstablished;
_CLXDriver.ComError += OnConnectionLost;
_CLXDriver.ConnectionClosed += OnConnectionClosed;
The problem is that "ConnectionEstablished" does not fire if there is no Read called. So just creating the "ClxDriver.EthernetIPforCLX" object and waiting for "ConnectionEstablished" to fire whenever the PLC is booted up doesn't work since it never fires. If I do a read when the PLC is booted up it does fire, but if I do a read when the PLC is not booted up, an unhandled "System.Net.Sockets.SocketException" is thrown that I cannot catch since it is thrown on a different thread. So how can I know when the PLC is connected and how can I wait indefinately for a PLC to connect to?
Thnx!