raydriver.grbl.parser
Pure parsers for GRBL response data: status reports, build info, settings, WCS offsets, probe results and raw-output classification. All functions are side-effect free.
Functions
alarm_code_to_device_error()
alarm_code_to_device_error(alarm_code: str) -> types.DeviceError
Look up an alarm code in the GRBL alarm table.
| Parameter | Type | Description |
|---|---|---|
alarm_code | str | |
| Returns | types.DeviceError |
detect_unit_system_from_settings()
detect_unit_system_from_settings(
settings_lines: Sequence[str],
) -> Optional[str]
Infer the unit system ("metric"/"imperial") from $$ lines.
| Parameter | Type | Description |
|---|---|---|
settings_lines | Sequence[str] | |
| Returns | Optional[str] |
error_code_to_device_error()
error_code_to_device_error(error_code: str) -> types.DeviceError
Look up an error code in the GRBL error table.
| Parameter | Type | Description |
|---|---|---|
error_code | str | |
| Returns | types.DeviceError |
extract_device_name()
extract_device_name(build_info: Sequence[str]) -> str
Extract a human-readable device name from build info lines.
| Parameter | Type | Description |
|---|---|---|
build_info | Sequence[str] | |
| Returns | str |
extract_device_name_from_output()
extract_device_name_from_output(data: Sequence[int]) -> Optional[str]
Extract a device name from raw serial output, falling back to the first informative banner line.
| Parameter | Type | Description |
|---|---|---|
data | Sequence[int] | |
| Returns | Optional[str] |
gcode_to_p_number()
gcode_to_p_number(wcs_slot: str) -> Optional[int]
Convert a G-code WCS name (e.g. "G54") to its P-number.
| Parameter | Type | Description |
|---|---|---|
wcs_slot | str | |
| Returns | Optional[int] |
is_grbl_output()
is_grbl_output(data: Sequence[int]) -> bool
True when raw serial output identifies a Grbl device.
| Parameter | Type | Description |
|---|---|---|
data | Sequence[int] | |
| Returns | bool |
is_report_in_inches()
is_report_in_inches(settings_lines: Sequence[str]) -> bool
True when the $13 (Report in inches) flag is set.
| Parameter | Type | Description |
|---|---|---|
settings_lines | Sequence[str] | |
| Returns | bool |
parse_grbl_parser_state()
parse_grbl_parser_state(response_lines: Sequence[str]) -> Optional[str]
Parse $G response lines to find the active WCS (G54-G59).
| Parameter | Type | Description |
|---|---|---|
response_lines | Sequence[str] | |
| Returns | Optional[str] |
parse_grbl_settings()
parse_grbl_settings(lines: Sequence[str]) -> dict[str, float]
Parse $$ lines into {key: value} floats.
| Parameter | Type | Description |
|---|---|---|
lines | Sequence[str] | |
| Returns | dict[str, float] |
parse_msg()
parse_msg(line: str) -> Optional[tuple[str, str]]
Parse a [MSG:key:value] line into (key, value).
| Parameter | Type | Description |
|---|---|---|
line | str | |
| Returns | Optional[tuple[str, str]] |
parse_opt_flags()
parse_opt_flags(line: str) -> Optional[str]
Extract the compile option flags from an [OPT:...] line.
| Parameter | Type | Description |
|---|---|---|
line | str | |
| Returns | Optional[str] |
parse_opt_info()
parse_opt_info(line: str) -> Optional[int]
Extract the RX buffer size from an [OPT:...] line.
| Parameter | Type | Description |
|---|---|---|
line | str | |
| Returns | Optional[int] |
parse_probe_line()
parse_probe_line(
line: str,
) -> Optional[tuple[tuple[float, float, float], bool]]
Parse a [PRB:x,y,z:success] line into (pos, success).
| Parameter | Type | Description |
|---|---|---|
line | str | |
| Returns | Optional[tuple[tuple[float, float, float], bool]] |
parse_setting_pairs()
parse_setting_pairs(lines: Sequence[str]) -> list[tuple[str, str]]
Parse $$ lines into ordered (key, raw_value) pairs.
| Parameter | Type | Description |
|---|---|---|
lines | Sequence[str] | |
| Returns | list[tuple[str, str]] |
parse_state()
parse_state(
state_str: str,
default: Optional[types.DeviceState] = None,
report_in_inches: bool = False,
) -> types.DeviceState
Parse a GRBL status string like <Idle|MPos:10,20,30> into a DeviceState, using default as the
base. When report_in_inches is true, positions are converted back to mm.
| Parameter | Type | Description |
|---|---|---|
state_str | str | |
default | Optional[types.DeviceState] = None | |
report_in_inches | bool = False | |
| Returns | types.DeviceState |
parse_ver()
parse_ver(line: str) -> Optional[tuple[str, Optional[str]]]
Parse a [VER:...] line into (version, build_name).
| Parameter | Type | Description |
|---|---|---|
line | str | |
| Returns | Optional[tuple[str, Optional[str]]] |
parse_version()
parse_version(response_lines: Sequence[str]) -> Optional[str]
Parse $I response lines to extract the firmware version.
| Parameter | Type | Description |
|---|---|---|
response_lines | Sequence[str] | |
| Returns | Optional[str] |
parse_wcs_line()
parse_wcs_line(line: str) -> Optional[tuple[str, tuple[float, float, float]]]
Parse a [G5x:x,y,z] line from $# output.
| Parameter | Type | Description |
|---|---|---|
line | str | |
| Returns | Optional[tuple[str, tuple[float, float, float]]] |
split_realtime_commands()
split_realtime_commands(lines: Sequence[str]) -> tuple[list[str], list[str]]
Split command lines into (gcode, realtime) groups.
| Parameter | Type | Description |
|---|---|---|
lines | Sequence[str] | |
| Returns | tuple[list[str], list[str]] |
strip_gcode_comments()
strip_gcode_comments(line: str) -> str
Strip G-code comments from a line.
| Parameter | Type | Description |
|---|---|---|
line | str | |
| Returns | str |
version_supports_single_axis_homing()
version_supports_single_axis_homing(
version_num: float,
version_letter: str = '',
) -> bool
True if a GRBL version supports single-axis homing (> 1.1 or 1.1g and newer).
| Parameter | Type | Description |
|---|---|---|
version_num | float | |
version_letter | str = '' | |
| Returns | bool |