Skip to content

Add retries to ModbusPDU class #2672

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

Merged
merged 1 commit into from
May 23, 2025

Conversation

mdeneen
Copy link
Contributor

@mdeneen mdeneen commented May 22, 2025

I tried doing this before by adding another return value, but it would break many things.

This time I have added an integer representing the number of retries to the ModbusPDU class and setting that value in both the async and sync transaction execute code path.

Copy link
Collaborator

@janiversen janiversen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks

@janiversen janiversen merged commit 59fc0e2 into pymodbus-dev:dev May 23, 2025
16 checks passed
@mdeneen
Copy link
Contributor Author

mdeneen commented May 23, 2025

Hey, Jan, one downside to this is that if you enable logging it will show retries as zero with the string representation of the PDU, since the decoder action happens before the retry is set.

@janiversen
Copy link
Collaborator

I actually considered asking not to include it in the string representation. Feel free to submit a PR.

@mdeneen
Copy link
Contributor Author

mdeneen commented Jun 9, 2025

Other things, like device id, are also incorrect in the trace. I guess I am okay with the way it currently is.

@janiversen
Copy link
Collaborator

janiversen commented Jun 9, 2025

device id is correctly 0 in the response, signaling broadcast... but in general it might be better to remove all variables and just return the class name.

You seem to forget that these classes are not used exclusively in the client.

@mdeneen
Copy link
Contributor Author

mdeneen commented Jun 9, 2025

You're right, I am using them solely from the client's perspective, my apologies.

In my case, the device I am communicating with has a device id of 2. When I read holding registers I must set device_id (or slave, for older versions) to 2. The debug trace shows 0, but the actual returned object is set to 2.

Am I look at this incorrectly?

@janiversen
Copy link
Collaborator

janiversen commented Jun 10, 2025

In the client you know what you requested (since you can only do one request at a time) so it does not really matter what is being returned.

The main purpose of the debug log is to help the developers to find problems, it is not meant for end users.

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 this pull request may close these issues.

2 participants