Skip to content

Commit

Permalink
fix regex for gcodes
Browse files Browse the repository at this point in the history
  • Loading branch information
ahiuchingau committed Nov 22, 2024
1 parent c823a34 commit b822f58
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ class MoveParams:

def __str__(self) -> str:
"""Convert to string."""
v = "V:" + str(self.max_speed) if self.max_speed else ""
a = "A:" + str(self.acceleration) if self.acceleration else ""
d = "D:" + str(self.max_speed_discont) if self.max_speed_discont else ""
v = "V" + str(self.max_speed) if self.max_speed else ""
a = "A" + str(self.acceleration) if self.acceleration else ""
d = "D" + str(self.max_speed_discont) if self.max_speed_discont else ""
return f"{v} {a} {d}".strip()


Expand Down Expand Up @@ -121,7 +121,7 @@ def __init__(self, port: str, simulating: bool = False) -> None:

def _send_and_recv(self, msg: str, guard_ret: str = "") -> str:
"""Internal utility to send a command and receive the response."""
assert self._simulating
assert not self._simulating
self._serial.write(msg.encode())
ret = self._serial.readline()
if guard_ret:
Expand Down Expand Up @@ -163,7 +163,7 @@ def get_limit_switch(self, axis: StackerAxis, direction: Direction) -> bool:
if self._simulating:
return True

_LS_RE = re.compile(rf"^M119 .*{axis.name}{direction.name[0]}:(\d) .* OK\n")
_LS_RE = re.compile(rf"^M119 .*{axis.name}{direction.name[0]}:(\d).* OK\n")
res = self._send_and_recv("M119\n", "M119 XE:")
match = _LS_RE.match(res)
assert match, f"Incorrect Response for limit switch: {res}"
Expand All @@ -177,8 +177,8 @@ def get_platform_sensor(self, direction: Direction) -> bool:
if self._simulating:
return True

_LS_RE = re.compile(rf"^M121 .*{direction.name[0]}:(\d) .* OK\n")
res = self._send_and_recv("M121\n", "M119 E:")
_LS_RE = re.compile(rf"^M121 .*{direction.name[0]}:(\d).* OK\n")
res = self._send_and_recv("M121\n", "M121 E:")
match = _LS_RE.match(res)
assert match, f"Incorrect Response for platform sensor: {res}"
return bool(int(match.group(1)))
Expand Down Expand Up @@ -237,7 +237,7 @@ def move_to_limit_switch(
if self._simulating:
return
self._send_and_recv(
f"G5 {axis.name}{direction.value} {params or ''}\n", "G0 OK"
f"G5 {axis.name}{direction.value} {params or ''}\n", "G5 OK"
)

def __del__(self) -> None:
Expand Down

0 comments on commit b822f58

Please sign in to comment.