Open nick990 opened 2 years ago
Personally, if you are connecting every 5 seconds, I would leave the connection open.
Personally, if you are connecting every 5 seconds, I would leave the connection open.
I can't leave the connection open because EEIP is not able to reconnect in case of loss of connection.
After some tests, it seems that the device doesn't become unreachable if I put a sleep over seconds between the the UnregisterSession and RegisterSession calls. So the workaround I found is to leave the connection open and recreate the session in case of any error.
EEIPClient client ;
bool sessionRegistered = false;
void RegisterSession(){
client = new EEIPClient();
client.RegisterSession(IP_ ADDRESS, PORT);
sessionRegistered = true;
}
void DestroySession(){
client.UnRegisteredSession();
sessionRegistered = false;
}
while(true){
try{
if(!sessionRegistered){
RegisterSession();
}
client.GetAttributeSingle(CLASS_ID, INSTANCE_ID, ATTRIBUTE_ID);
Sleep(5000);
}catch(Exception ex){
DestroySession();
Sleep(10000);
}
}
I think the sleep of 10 seconds solves the problem because the client doesn't wait for unregistration. Is there a better way to check connection status?
I'm trying to to read data periodically using explicit messaging. Currently I do the following:
The idea is to register/unregister the session each loop cycle in order to prevent a disconnection from the device. In case of connection lost (e.g. network issue, PLC reboot, etc.) I was expecting the library would be able to register a new session. What happens is that after a few iterations, the device become unreachable. I can't even ping it, I have to reboot it.
I would to know if my approach is correct or there is a better way to obtain the desired behavior. If the approach is right, what could be the cause of this problem? Thanks