ModbusFB not reconnecting and gets hung up

matthew
2022-02-24
2022-03-06
  • matthew - 2022-02-24

    Hi,

    Is there a way to reset the ModbusFB functions? If I disconnect or loose power to a device and connect again the communication get's hung up most of the. Sometimes it will reconnect and not be an issue, but most of the time it just gets hung up. It's erroring with reply timeout and just cycles through the max number of retries ( 5 ) and does not reconnect.

    If I disconnect the SerialClient completely and reconnect the client it still does not work, I have tried restarting the communication sequence based on the error and still does not fix the issue.

    The only way to get it working again is to go online with a full download or restart the CodeSys runtime. Is there a way I can dynamically reset or restart the ModbusFB?

     
  • dFx

    dFx - 2022-02-25

    Assuming your code is the same you posted earlier,

    You should fix a bad call issue : You call the ClientSerial Instance twice, and on first call, no parameters were provided, so at first call you run on defauts.

    And a bad behavior about retries sequencing : when you cycle from retry steps to step 10, this is only one FB instance call with xConnect = FALSE. Keep in mind that some resources are async, especially doing communication. Meaning that it may take more than one cpu cycle for some tasks to be done correctly.
    I would try the following for the last point :
    1) xConnect = False
    2) Wait xConnected goes to FALSE
    3) Then xConnect = TRUE

     
    • matthew - 2022-03-02

      Hi dFx,

      I have corrected those errors and changed a few other things and I now have it mostly working. If I disconnect one device the other device still functions and if I reconnect the device it reconnects and works fine. The problem I now have is if both devices are disconnect and then connected again they still have an error and connect no longer works. I have to restart the CodeSys runtime and then they both work again.

      The ClientSerial does not error at all and reconnects fine. Just the slaves have the error of reply timeout and will not reconnect. I need this to be robust and for slaves to reconnect when available as some sensors will be off a batter supply and have sleep modes and I will also have a Wireless RS485 link to a weather station.

      I have attached the project as it will probably be easier to view then putting all the code here. Hopefully you can help and pick up where I have gone wrong.

      Edit: They both reconnect and work fine if requests are not made. As soon as a request is made while disconnected they will not reconnect again or anything. Seems odd and even disconnecting ClientSerial and reconnecting again will not bring the network back up or anything.

       

      Last edit: matthew 2022-03-02
      • dFx

        dFx - 2022-03-02

        I can't really tell without opening your archive, but I can't do it for now. Just have a look on a disconnected state without requests, and with, and play the 7 differences game with your variables values. Maybe you will find it that way.

         
        • matthew - 2022-03-06

          It seems to be intermittent, will sometimes reconnect fine and as soon as it doesn't the only way to recover is restart the CodeSys runtime. Seems odd the ClientSerial has no errors. I do see there is a reset method browsing through the variables, but don't know how to access or use that. I don't think it is from requests or anything. Do you know if there are any other examples available?

           
        • matthew - 2022-03-06

          It seems to be intermittent, will sometimes reconnect fine and as soon as it doesn't the only way to recover is restart the CodeSys runtime. Seems odd the ClientSerial has no errors. I do see there is a reset method browsing through the variables, but don't know how to access or use that. I don't think it is from requests or anything. Do you know if there are any other examples available?

           

Log in to post a comment.