Wiki
Clone wikiGCode Editor / gen / GCodeParser
Documentation
public class GCodeParser extends Thread
A gcode parser which accepts either a BufferedReader of lines or may simply execute a series of arbitrary gcodes.
IMPORTANT: this parser will completely ignore M110 (goto gcode line) commands, treating them as another generic command, which could potentially cause big problems.
-
Author: groomblecom
public Command parseLine(String line)
Parses a single line of gcode using the current state of the parser. It will manipulate the state of the parser; beware that this is absolutely not a pure function.
- Parameters:
line
— a single line of gcode - Returns: a Command object representing the command, or null if the line was empty, a comment, or invalid. Some invalid lines may be treated as valid but irrelevant gcode.
public float getFloatFromGCode(String gcode)
Gets the float from a string like "X89.5" or "G92"
- Parameters:
gcode
— the string - Returns: the float
public float[] getVecFromGCode(String[] codes, int beginIndex)
Convenience method which assumes that no NaNs are to be added.
- See also: GCodeParser#getVecFromGCode(String[], int, boolean)
public float[] getVecFromGCode(String[] codes, int beginIndex, boolean NaNsForMissing)
Gets a x-y-z-e vector from a gcode formatted command (split by spaces), ignoring non-xyze values. Uses the parser's settings for units; not a pure function.
- Parameters:
codes
— a gcode command's arguments, split by spacesbeginIndex
— the index to begin looking fromNaNsForMissing
— If true, put a NaN into the array if there is no declaration of the value- Returns: a length 4 float[], each value representing x, y, z,and e respectively. Any values not in the GCode are assumed to be zero. Inches will be converted to mm based on GCodeParser.useImperial
Updated