Skip to content

If RTU response is empty, don't validate CRC but fail earlier. #50

Closed

Description

@petonic

Hi -- I fired this up really quick to see if I could use it in a home-rolled program, and correct me if I'm wrong, but there doesn't seem to be any error checking (specifically around validate_crc()) on the responses, right?

I'm firing a write_multiple_registers command with no RS485 devices on the serial bus. Output is fine, I guess, but my simple driver program just craps out because of an exception in validate_crc().

Can you confirm? Also, good luck on further developing this. I like the approach!

Activity

  1. OrangeTux commented on Jan 30, 2017

    @OrangeTux
    Collaborator

    If I understand you correctly the validate_crc of a response failes? Could you post a stacktrace/error?

  2. petonic commented on Jan 30, 2017

    @petonic
    Author

    Hi! Thanks for responding.

    I can dig up the exception, but it has to do with the fact that write_multiple_registers() is expecting a response and when it times out, it still calls validate_crc() with an empty buffer, which then gives the exception. Should I trap for that and then handle exceptions that way?

    Do you still need a stack trace or is that expected behavior?

  3. OrangeTux commented on Jan 30, 2017

    @OrangeTux
    Collaborator

    I understand the case and I agree that the raising the exception in validate_crc is a bit weird. Earlier in the process an error should be raised.

    def send_message(adu, serial_port):
        """ Send Modbus message over serial port and parse response. """
        serial_port.write(adu)
        response = serial_port.read(serial_port.in_waiting)
    
        if len(response) == 0:
            raise TimeoutError
    
        return parse_response_adu(response, adu)
  4. petonic commented on Jan 30, 2017

    @petonic
    Author
  5. changed the title [-]Error checking on receiving (or not) responses?[/-] [+]If RTU response is empty, don't validate CRC.[/+] on Jan 30, 2017
  6. changed the title [-]If RTU response is empty, don't validate CRC.[/-] [+]If RTU response is empty, don't validate CRC but fail earlier.[/+] on Jan 30, 2017
  7. OrangeTux commented on Jan 30, 2017

    @OrangeTux
    Collaborator

    If you want to fix it I'm happy to receive a pull request.

  8. petonic commented on Jan 31, 2017

    @petonic
    Author
  9. OrangeTux commented on Jan 31, 2017

    @OrangeTux
    Collaborator

    Good finding. I don't think that validate_crc is a proper place to do the length check. What would be
    good error tho raise in this place and how should both rtu client and server handle it?

    I think rtu.RTUServer.serve_once should check if length of request_adu. If length is 0 the method must not return the try to process the request and return a response, like you said, but it should raise an error. I think a TimeoutError fits best.

  10. clevert-pretto commented on Jan 1, 2018

    @clevert-pretto

    Hi there,
    Is this issue is still unsolved?

  11. OrangeTux commented on Jan 3, 2018

    @OrangeTux
    Collaborator

    No, it isn't yet. But the solution already thought trough in the above comments. So it's very easy to implement. I'll try to fix in somewhere this week.

  12. OrangeTux commented on Jan 5, 2018

    @OrangeTux
    Collaborator

    This has been fixed in the 1.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions