-
Notifications
You must be signed in to change notification settings - Fork 947
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
Function code 0x15 fails because of incomplete receival of bytes #1183
Comments
Looks like you found a problem, pull requests are welcome. |
This problem still seems to exist, but it can occur occasionally when transferring large files. def _wait_for_data(self):
"""Wait for data."""
size = 0
more_data = False
if self.params.timeout is not None and self.params.timeout:
condition = partial(
lambda start, timeout: (time.time() - start) <= timeout,
timeout=self.params.timeout,
)
else:
condition = partial(lambda dummy1, dummy2: True, dummy2=None)
start = time.time()
while condition(start):
available = self._in_waiting()
if (more_data and not available) or (more_data and available == size):
break
if available and available != size:
more_data = True
size = available
time.sleep(0.01)
return size |
You do not mention which version you are testing with ? nor do you say which file you talk about, It sounds like a good idea to have this delay depending on the baudrate, please submit a pull request, so we can review your suggested changes (you suggested another change originally). |
Sorry for the lack of clarity. I just tried the latest version, 3.1.2, and it's the same problem I described. Modify _wait_for_data in pymodbus/client/serial.py. |
Yeah I do not think we made any changes to that logic. As I wrote earlier please submit a pull request, since you believe you have a solution. |
1 Modbus rtu function unavailable def recv(self, size):
"""Read data from the underlying descriptor."""
super().recv(size)
if not self.socket:
raise ConnectionException(
self.__str__() # pylint: disable=unnecessary-dunder-call
)
if size is None:
size = self._wait_for_data()
if size > self._in_waiting():
size = self._wait_for_data() ### can not change size
result = self.socket.read(size)
return result And as I've indicated, if do that, here's what happens.
2 The delay problem mentioned above |
Please as pr documentation add some debug log, so we can see what happens just before the problem. What do you mean be a RTU function unavailable ? which one ? The stress test you made is that with the code you included ? it is not very clear to me, it so please submit a pull request. |
* fix: Serial changes the receiving interval by baudrate.(#1183) Co-authored-by: sunlinjie <[email protected]> Co-authored-by: Sun <[email protected]> Co-authored-by: jan iversen <[email protected]>
I suppose this can be closed. |
Versions
Pymodbus Specific
Description
What were you trying, what has happened, what went wrong, and what did you expect?
We were trying to send many bytes data to slave by function code 0x15. Finally, we found that serial received data is incomplete, especially when the baud rate is low. In function recv of pymodbus/client/serial.py, when size if not None, serial does not wait data.
Code and Logs
When I modify the recv in this way, there is no problem. I don't know if there will be any other problems with this change. I hope you can help me review. Thank you.
The text was updated successfully, but these errors were encountered: