Modbus TCP client reconnection problem

fmon
2025-03-17
2025-03-18
  • fmon - 2025-03-17

    Hello,

    I am using codesys Modbus TCP client (4.4.0.0) to communicate with a python modbus server (package pyModbusTCP).

    I first start my python server on the distant machine.
    After a fresh codesys compilation, a plc connection/transfer and a PLC run, the modbus connection is OK. Every time in this context the connection is created correctly.

    When I shut down the server, the modbus connection falls, that is normal.
    When I restart the python server, impossible to recreate the modbus connexion. With the client autoreconnection, I see on my server that the client tries to connect but unsuccesfully. I have the following message :

    DEBUG:pyModbusTCP.server:accept new connection from ClientInfo(address='192.168.1.20', port=33476)
    DEBUG:pyModbusTCP.server:Exception during request handling: NetworkError('recv return null')

    I tried to stop the codesys client and to restart it with these commands :

    Modbus_TCP_Client.xStop := True;  // Or False
    Modbus_TCP_Client.Enable := True;  // Or False
    Modbus_TCP_Server.Enable := True;  // Or False
    

    I tried to confirm the error manually to force reconnection with:

    Modbus_TCP_Server_Motors.xConfirmError := TRUE;
    

    I tried also this command to STOP/RESET/START client and server (codesys side) but nothing happens :

    status_client := Modbus_TCP_Client.SetCommunicationState(eRequestedState := DED.DEVICE_TRANSITION_STATE.STOP);  // .RESET & .START
    

    The answer of this function when executed is "status_client = NOT_SUPPORTED". Is it normal ?

    It seems that is a socket problem, but I do not understand if it is on the client or server side.
    I tried a modbus simulator called "ananas.exe" and the result is the same. Impossible to get a modbus client reconnection.

    What is different at the first client connection and at a reconnection attempt ?

    Thanks for your help

     
  • fmon - 2025-03-18

    Problem solved

    The client modbus cycle time was linked to a task at 500ms. Whereas the channel modbus was at 200ms. Certainly problem of packages synchronisation.

    I let the client modbus cycle time to be handled by itself (See attachement) --> "Use the bus cyle time parameters" (traduce from french)
    See attachement

     

Log in to post a comment.