Aller au contenu principal

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.

ParameterTypeDescription
alarm_codestr
Returnstypes.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.

ParameterTypeDescription
settings_linesSequence[str]
ReturnsOptional[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.

ParameterTypeDescription
error_codestr
Returnstypes.DeviceError

extract_device_name()​

extract_device_name(build_info: Sequence[str]) -> str

Extract a human-readable device name from build info lines.

ParameterTypeDescription
build_infoSequence[str]
Returnsstr

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.

ParameterTypeDescription
dataSequence[int]
ReturnsOptional[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.

ParameterTypeDescription
wcs_slotstr
ReturnsOptional[int]

is_grbl_output()​

is_grbl_output(data: Sequence[int]) -> bool

True when raw serial output identifies a Grbl device.

ParameterTypeDescription
dataSequence[int]
Returnsbool

is_report_in_inches()​

is_report_in_inches(settings_lines: Sequence[str]) -> bool

True when the $13 (Report in inches) flag is set.

ParameterTypeDescription
settings_linesSequence[str]
Returnsbool

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).

ParameterTypeDescription
response_linesSequence[str]
ReturnsOptional[str]

parse_grbl_settings()​

parse_grbl_settings(lines: Sequence[str]) -> dict[str, float]

Parse $$ lines into {key: value} floats.

ParameterTypeDescription
linesSequence[str]
Returnsdict[str, float]

parse_msg()​

parse_msg(line: str) -> Optional[tuple[str, str]]

Parse a [MSG:key:value] line into (key, value).

ParameterTypeDescription
linestr
ReturnsOptional[tuple[str, str]]

parse_opt_flags()​

parse_opt_flags(line: str) -> Optional[str]

Extract the compile option flags from an [OPT:...] line.

ParameterTypeDescription
linestr
ReturnsOptional[str]

parse_opt_info()​

parse_opt_info(line: str) -> Optional[int]

Extract the RX buffer size from an [OPT:...] line.

ParameterTypeDescription
linestr
ReturnsOptional[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).

ParameterTypeDescription
linestr
ReturnsOptional[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.

ParameterTypeDescription
linesSequence[str]
Returnslist[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.

ParameterTypeDescription
state_strstr
defaultOptional[types.DeviceState] = None
report_in_inchesbool = False
Returnstypes.DeviceState

parse_ver()​

parse_ver(line: str) -> Optional[tuple[str, Optional[str]]]

Parse a [VER:...] line into (version, build_name).

ParameterTypeDescription
linestr
ReturnsOptional[tuple[str, Optional[str]]]

parse_version()​

parse_version(response_lines: Sequence[str]) -> Optional[str]

Parse $I response lines to extract the firmware version.

ParameterTypeDescription
response_linesSequence[str]
ReturnsOptional[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.

ParameterTypeDescription
linestr
ReturnsOptional[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.

ParameterTypeDescription
linesSequence[str]
Returnstuple[list[str], list[str]]

strip_gcode_comments()​

strip_gcode_comments(line: str) -> str

Strip G-code comments from a line.

ParameterTypeDescription
linestr
Returnsstr

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).

ParameterTypeDescription
version_numfloat
version_letterstr = ''
Returnsbool