Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ModbusTcpClient doesn't do reconnects? #2320

Closed
camtarn opened this issue Sep 14, 2024 · 7 comments · Fixed by #2321
Closed

ModbusTcpClient doesn't do reconnects? #2320

camtarn opened this issue Sep 14, 2024 · 7 comments · Fixed by #2321

Comments

@camtarn
Copy link
Contributor

camtarn commented Sep 14, 2024

Versions

  • Python: N/A
  • OS: N/A
  • Pymodbus: 3.7.2
  • Modbus Hardware (if used): N/A

Pymodbus Specific

  • Client: tcp - sync

Description

On:
https://github.com/pymodbus-dev/pymodbus/blob/dcbcfd7f16fb3be82525bccf9699855a06f900c5/pymodbus/client/tcp.py#L129C1-L129C74

there is the comment:
Remark: There are no automatic reconnect as with AsyncModbusTcpClient

Is this true? The docs say:

client = ModbusTcpClient('MyDevice.lan')   # Create client object
client.connect()                           # connect to device, reconnect automatically

which seems to contradict this.

This also suggests that this part of the docstring for ModbusTcpClient might be incorrect, if there is no automatic reconnection:

    .. tip::
        **reconnect_delay** doubles automatically with each unsuccessful connect, from
        **reconnect_delay** to **reconnect_delay_max**.
        Set `reconnect_delay=0` to avoid automatic reconnection.

Not a problem if it's not supported, I was just surprised to find this.

@janiversen
Copy link
Collaborator

the async client do automatic reconnect, wh6 do you think there are no automatic reconnect?

If you think there is a bug, then please add a debug log so we can see what happens.

@janiversen
Copy link
Collaborator

Of course it seems to be a wrong documentation, 8n that case a pull request is welcome.

@camtarn
Copy link
Contributor Author

camtarn commented Sep 14, 2024

This is specifically for the sync client.

Happy to make a pull request if you confirm the sync client also does reconnects.

@janiversen
Copy link
Collaborator

The sync client do not do automatic reconnect, as far as I remember.

@janiversen
Copy link
Collaborator

sync uses a different approach, it connects if a request is sent and it's not connected.

@camtarn
Copy link
Contributor Author

camtarn commented Sep 14, 2024

Ah, yes, I think I see -

if not self.connect():
causes the client to try connecting, which returns immediately if it's already connected, or kicks off a new connection.

I'll see if there's a better way to word the documentation.

@camtarn
Copy link
Contributor Author

camtarn commented Sep 14, 2024

I've found a different way to phrase the docs.

However, it seems like it would make sense to remove the reconnect_delay/reconnect_delay_max params from the sync clients, since they don't use them. I'm guessing that removing those would be an API change? For the moment I can flag them as 'not used in the sync client'.

camtarn pushed a commit to camtarn/pymodbus that referenced this issue Sep 14, 2024
Sync clients don't do reconnection in the same way as async clients, and should
have a little more explanation as to what they do.

See issue pymodbus-dev#2320
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants