Skip to content

Commit

Permalink
add response_required arg to conditionally ignore serial responses
Browse files Browse the repository at this point in the history
  • Loading branch information
vegano1 committed Nov 27, 2024
1 parent d0b9805 commit 07d3ce6
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,15 @@ def __init__(self, port: str, simulating: bool = False) -> None:
if not self._simulating:
self._serial = serial.Serial(port, baudrate=STACKER_FREQ, timeout=60)

def _send_and_recv(self, msg: str, guard_ret: str = "") -> str:
def _send_and_recv(
self, msg: str, guard_ret: str = "", response_required=True
) -> str:
"""Internal utility to send a command and receive the response."""
assert not self._simulating
self._serial.reset_input_buffer()
self._serial.write(msg.encode())
if not response_required:
return "OK\n"
ret = self._serial.readline()
if guard_ret:
if not ret.startswith(guard_ret.encode()):
Expand Down Expand Up @@ -160,7 +164,7 @@ def stop_motor(self) -> None:
"""Stop motor movement."""
if self._simulating:
return
self._send_and_recv("M0\n")
self._send_and_recv("M0\n", response_required=False)

def get_limit_switch(self, axis: StackerAxis, direction: Direction) -> bool:
"""Get limit switch status.
Expand Down

0 comments on commit 07d3ce6

Please sign in to comment.