Skip to content

Commit

Permalink
Resets input buffer on exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
gfrn committed Aug 5, 2022
1 parent 8cc3e97 commit 15f35ea
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/pydrs/pydrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def _get_reply(self, size: int = None) -> bytes:
if payload[0] == ETH_ANSWER_ERR:
raise TimeoutError("Server timed out waiting for serial response")
except IndexError:
self._reset_input_buffer()
raise SerialErrPckgLen(
"Received empty response, check if the controller is on and connected"
)
Expand Down
2 changes: 2 additions & 0 deletions src/pydrs/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,13 @@ def wrapper(*args, **kwargs):
if len(reply) > 5:
check_serial_error(reply[offset:])

args[0]._reset_input_buffer()
raise SerialErrPckgLen(
"Expected {} bytes, received {} bytes".format(args[2], len(reply) - offset)
)

if reply != checksum(reply[:-1]):
args[0]._reset_input_buffer()
raise SerialErrCheckSum(
"Expected {} as checksum, received {}".format(
checksum(reply[:-1])[-1], reply[-1]
Expand Down

0 comments on commit 15f35ea

Please sign in to comment.