How to detect failure or disconnection of ethernet cable with Modbus_TCP / IP communication

I am using the Modbus_TCP_10 library to use an AXC F 2152 as a server and communicate eith a slave I’m having trouble detecting when the ethernet cable is disconnected, because when I reconnect it, the PLC server detects that the slave is still connected (xConnected==True). How can I detect this disconnection? Wait response, thanks.

Hello Hpous, the server only recognises a timeout if the connection breaks during a write access. „tTimeout Time Timeout monitoring when there is a write access. After a write function was executed, a write telegram must be received again within the time specified here. A timeout error is reported if this is not the case. Specify the timeout value T#0s to disable this function.“ If you just remove the cable , the TCP protokoll dictates that a session will be kept alive for some time. → The same session etc. can be reused as soon as the cable is reattached. The Server in Modbus does not know If a client should still be polling data. All it recognises is that the Socket is still open. So even a „broken“ connection is not reconised instantly as the OS itself does not register it as broken instantly. You could check the link state of the PLCs ETH port to reset your Server FB. (but that would only work if the connection between PLC and Modbus Client is direct, No Switches inbetween etc. so not a very flexible solution) Or you can read the udtDiag structure for the udtDiag.*_RECIEVE.xNDR to monitor if you are continuously recieving data. In case of connected client and no more incoming data you can then handle your application according to that. e.g. Restart the server or set an alarm that incoming data stopped… It is however not part of the Modbus standard as far as I know. So its not a part of the FB. kind regards, Oliver

Thank you very much for your help Oliver, I have read the udtDiag structure for the udtDiag. * _ RECIEVE.xNDR and now I can restart the connection.