gcode_reader.read

Functions

apply_word_abstractions(→ dict)

Translates a dictionary of G-code words into abstract command concepts.

read_gcode_file(filepath[, flavor, encoding])

Reads a G-code file into a set of clean dictionaries of words

read_gcode_line(line[, named_parameters, flavor])

Reads a G-code line into a clean dictionary of words and comments

Module Contents

gcode_reader.read.apply_word_abstractions(word_map: dict, words: dict) dict[source]

Translates a dictionary of G-code words into abstract command concepts.

Uses a word map to reverse-map concrete G-code words (e.g., ‘X’, ‘F’) into their abstract representations (e.g., ‘location’, ‘feed_rate’). Modifies words in-place by adding the abstract keys, then returns it.

Parameters:
  • word_map (dict) – A dictionary mapping abstract concepts to their G-code word representations. See syntax.flavors for examples.

  • words (dict) – Parsed G-code words from a single line.

Returns:

The same words dict, with abstract keys added.

Return type:

dict

gcode_reader.read.read_gcode_file(filepath: str, flavor: str = 'default', encoding='utf-8')[source]

Reads a G-code file into a set of clean dictionaries of words

Parameters:
  • filepath (str) – Path (absolute or relative) to a G-code program file

  • flavor (str, optional) – Syntax definition for line. Defaults to “default”.

  • encoding (str, optional) – File encoding. Defaults to ‘utf-8’.

Returns:

All lines as clean dictionary of words

Return type:

Generator[dict]

gcode_reader.read.read_gcode_line(line: str, named_parameters: dict = {}, flavor: str = 'default')[source]

Reads a G-code line into a clean dictionary of words and comments

Parameters:
  • line (str) – Un-processed line (block) from a G-code program

  • flavor (str, optional) – Syntax definition for line. Defaults to “default”.

Returns:

Words and comments

Return type:

dict