Skip to content

Conversation

@ccatterina
Copy link
Contributor

Socket recv waits until it gets some data from the host but not necessarily the entire response that can be fragmented in many packets. In this case it receives an incomplete frame that is rejected by the frame handler.
This commit solves this issue by recalling socket recv until get a complete modbus response.

''' Checks if the response is a Modbus Exception.
'''
if isinstance(self.client.framer, ModbusSocketFramer):
if len(response) >= 8 and ord(response[7]) > 128:
Copy link
Contributor

Choose a reason for hiding this comment

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

Just an early heads up, do not use ord directly , instead use byte2int from pymodbus.compat module, this way the code works fine in both python version.

Copy link
Contributor Author

@ccatterina ccatterina Jun 8, 2017

Choose a reason for hiding this comment

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

Ok, thanks for the advice.
In these days i'm a bit busy, probably i will submit the final PR by the next week because i still have to test it and review the changes.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, Thanks.

Socket recv waits until it gets some data from the host but
not necessarily the entire response that can be fragmented in
many packets. In this case it receives an incomplete frame
that is rejected by the frame handler.
This commit solves this issue by recalling socket recv until
get a complete modbus response.
@ccatterina
Copy link
Contributor Author

Hi, i tested the patch using RTU and Socket framers and it seems to work.
I have not devices that use Binary or ASCII framers and i don't know much about Modbus ASCII and Modbus Binary, so if someone could test them, that'd be great.

@dhoomakethu
Copy link
Contributor

Thanks @ccatterina , I will give a test and merge if everything seems good.

@dhoomakethu
Copy link
Contributor

@ccatterina I could only test on real device with RTU and TCP modes , I will take the liberty that most of the people out there aren't using the binary/ascii modes and hope it will work for them as well. Thanks for your efforts

@dhoomakethu dhoomakethu merged commit 559c7b8 into pymodbus-dev:master Jun 22, 2017
dhoomakethu pushed a commit that referenced this pull request Nov 28, 2017
Socket recv waits until it gets some data from the host but
not necessarily the entire response that can be fragmented in
many packets. In this case it receives an incomplete frame
that is rejected by the frame handler.
This commit solves this issue by recalling socket recv until
get a complete modbus response.
ccatterina added a commit to ccatterina/pymodbus that referenced this pull request Apr 17, 2018
Socket recv waits until it gets some data from the host but
not necessarily the entire response that can be fragmented in
many packets. In this case it receives an incomplete frame
that is rejected by the frame handler.
This commit solves this issue by recalling socket recv until
get a complete modbus response.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants