Skip to content

Commit

Permalink
Parse the GRBL version and check if supported
Browse files Browse the repository at this point in the history
  • Loading branch information
mmouchous-ledger committed Aug 16, 2024
1 parent c69d67f commit bbe836d
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion pystages/cncrouter.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from enum import Enum
from .grbl import GRBLSetting, InvertMask, StatusReportMask
from .stage import Stage
import re


class CNCStatus(str, Enum):
Expand Down Expand Up @@ -116,6 +117,24 @@ def reset_grbl(self, wait_time: Optional[float] = None) -> bool:
ok = responses[0].startswith("Grbl") and responses[0].endswith("['$' for help]")
if not ok:
return False

# Parse the GRBL version
grbl_match = re.match(
r"(?P<major>\d+).(?P<minor>\d+)(?P<patch>\w*)", responses[0].split(" ")[1]
)

if grbl_match is None:
return False

grp = grbl_match.groupdict()
self.grbl_version = {
"major": int(grp["major"]),
"minor": int(grp["minor"]),
"patch": grp["patch"],
}
if self.grbl_version["major"] < 1:
print(f"This version of GRBL {grbl_match.groups()[0]} is not supported.")

# Unlock if necessary
if "[MSG:'$H'|'$X' to unlock]" in responses:
ok = self.unlock()
Expand All @@ -138,7 +157,7 @@ def sleep(self) -> str:
def unlock(self) -> bool:
"""
Unlock the motor. It may happen when the stage has gone further its limits,
and raised an alarm, or has been disabled when going in sleep mode (`$SLP`)
and raised an alarm, or has been disabled when going in sleep mode (`$SLP`)
:return: `True` if message `[MSG:Caution: Unlock]` has been returned
"""
Expand Down

0 comments on commit bbe836d

Please sign in to comment.