Skip to content

Commit

Permalink
fix: serial debugging can break execute
Browse files Browse the repository at this point in the history
  • Loading branch information
GetPsyched committed Jan 17, 2024
1 parent f4f4d39 commit 685053a
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions charachorder/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,23 @@ def execute(self, *args: int | str) -> tuple[str, ...]:

command = " ".join(map(str, args))
self.connection.write(f"{command}\r\n".encode("utf-8"))
output = self.connection.readline().decode("utf-8").strip().split(" ")

# Drop serial header
if output[0] == "01":
output = output[1:]
def bad_output(output: list[str]) -> bool:
if not output:
return True

if output[0] == "UKN":
raise UnknownCommand(command)
# Drop serial header
if output[0] == "01":
output = output[1:]

if output[0] == "UKN":
raise UnknownCommand(command)

return command != " ".join(output[: len(args)])

output = []
while bad_output(output): # Avoid logs/debug messages
output = self.connection.readline().decode("utf-8").strip().split(" ")

return tuple(output[len(args) :])

Expand Down

0 comments on commit 685053a

Please sign in to comment.