Gcodes
A basic C# gcode parser and interpreter
Install / Use
/learn @Michael-F-Bryan/GcodesREADME
Gcodes
A basic C# gcode parser and interpreter.
Getting Started
Once you've downloaded a copy of the repository (e.g. as a git submodule), you
should be able to start using the gcodes library by asking Visual Studio to
add a reference to it.
Analysing Gcode Programs
If you just want to inspect a gcode program without doing any simulation you
just need to run the Parser and inspect its output.
Parsing the input text takes place in two steps:
- Tokenizing, using the
Lexerclass to convert source text into a stream ofTokens - Parsing, using a
Parserto convert a stream ofTokens into a bunch ofGcodeobjects.
public static void ParseGcodeFile(string filename) {
string src = File.ReadAllText(filename);
var lexer = new Lexer(src);
List<Token> tokens = lexer.Tokenize().ToList();
var parser = new Parser(tokens);
List<Code> gcodes = parser.Parse().ToList();
// do something with the gcodes
}
Note: For convenience,
Parseralso has a constructor which accepts astringand will tokenize everything for you.
There is no guarantee that every argument is provided to a gcode, therefore
if you want to fetch an argument's value (e.g. X or feed rate) you can use
the ValueFor() method. This will search the arguments provided to a particular
gcode for the specified ArgumentKind, and return its value.
