Repository navigation
Conversation
First attempt at only reading the expected size of the modbus requests, should block until we get the data. Should fix AdvancedClimateSystems#49, and be a stepping stone towards AdvancedClimateSystems#39 of upstream.
If there is a timeout waiting for the response do raise a ValueError rather than letting the parse_response_adu fail with bad errors.
|
Many thanks for your PR! Later this weekend I'll look into it. |
|
Appreciate it. I know how I am planning to fix up the tests. I should be able to do so tomorrow. Also wanted to say a big thank you for putting out this library. We use it to talk to several different pieces of hardware and it is the most non-confrontational python library for modbus. Thanks again! |
And single writes (to not depend on input length, but just be static)
Need to send a real request (so we know how much data to wait for), use a request that has more response data than the request (in terms of bytes) to trigger when a Timeout should be detected properly.
Works better with py2.7 and timeouts of underlying sockets.
|
Great patch. I actually learned something new from the page you link in the docstring of But I've some placed some comments. |
| data. | ||
| """ | ||
| s = serial_for_url('loop://', timeout=0) | ||
| # as we are using a loop, we need the request will be read back as response |
There was a problem hiding this comment.
Can you capitalize the first letter of the sentence and end the sentence with a dot?
There was a problem hiding this comment.
Sure, thing. If there is anything else that hits your eye, let me know. Open to any requested changes.
Based on PR review comment.
|
Fixed the comment, if there is anything else let me know. More than happy to make any further changes needed. Thanks for being so quick with the review. :) |
|
I've added 2 other comments about handling expection responses. Have you seen them? |
|
@OrangeTux, no I don't see them as comments against the diff. GitHub seems to drop them sometimes (if you comment as part of a review, but don't submit at the very bottom) |
| if len(response) == 0: | ||
| raise ValueError | ||
| serial_port.flush() | ||
| response = recv_exactly(serial_port.read, expected_response_size) |
There was a problem hiding this comment.
I think this would fail if the server responds with a Modbus exception code. In this case the PDU is only 5 bytes long. See http://www.simplymodbus.ca/exceptions.htm
Could you update the code so that this case is handled?
| sock.sendall(adu) | ||
| expected_response_size = \ | ||
| expected_response_pdu_size_from_request_pdu(adu[7:]) + 7 | ||
| response = recv_exactly(sock.recv, expected_response_size) |
There was a problem hiding this comment.
This edit has the same problem as the RTU client. It fails when the server responds with an expection code. The PDU is in this case 9 bytes, but recv_exactly is expecting more. Could you edit the code so this case is handled?
|
I think my comments should be visible now. |
For both RTU and TCP client cases. The exception ADU is only 2 bytes (shorter than all the other ADUs), so we can read those bytes first, check that there is no error, recv the rest of the expected ADU size, and concatenate the two for further parsing into the correct response.
|
Indeed, thanks for checking that, I didn't know about the error handling. The code is a bit more verbose now on the send_message side, but I think I made it as clear as possible. If you have a better idea on how to make it easier to read, I can take another attempt at it. Hope that it covers your concerns. Thanks for the eagle-eyed review! |
|
I've merged your changes into 1.0.1. Note that 1.0.1 isn't uploaded to Pypi. I forgot to update the version number in Again. thanks for your effort. |
…gfix/add-missing-issues-template-and-rp2-rtu-usage-examples Add missing issues template and RP2 RTU usage examples
This should fix #49
It works by checking exactly how many bytes are expected to be returned, and waiting until we receive that many... or a timeout (where we will receive fewer bytes than requested).
This was a problem with us either on slow serial devices (when setting up the connection... parity) or tcp connections that were slow to respond (as the recv call will bail out early sometimes if there is nothing already in the buffer).
I haven't tested manually, so using your travis to see what falls out and we will fix it up.
Thanks!