GcodeInterpreter 0.1.0

dotnet add package GcodeInterpreter --version 0.1.0
NuGet\Install-Package GcodeInterpreter -Version 0.1.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="GcodeInterpreter" Version="0.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add GcodeInterpreter --version 0.1.0
#r "nuget: GcodeInterpreter, 0.1.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install GcodeInterpreter as a Cake Addin
#addin nuget:?package=GcodeInterpreter&version=0.1.0

// Install GcodeInterpreter as a Cake Tool
#tool nuget:?package=GcodeInterpreter&version=0.1.0

G-code Interpreter

Nuget Nuget

Simple .NET G-code interpreter

The G-code interpreter will read a G-code file and produce a GcodeProgram from it.

Setup

Install the GcodeInterpreter package from NuGet.

Install-Package GcodeInterpreter

Add services to DI

services.AddGcodeInterpreter();

Using the interpreter

Inject IGcodeInterpreter into a class and use it to produce a GcodeProgram

public class Class1
{
    private readonly IGcodeInterpreter _interpreter;

    public Class1(IGcodeInterpreter interpreter)
    {
        _interpreter = interpreter;
    }

    public async Task<GcodeProgram> Build(string path)
    {
        return await _interpreter.ParseAsync(path);
    }
}

A produced GcodeProgram contains a Lines property that contains the parsed lines of the G-code file. Each Line contains a Command and Parameters property. A Command is of type Field and the Parameters is of type List<Field>. A Field contains a FieldLetter and Code property that represents a G-code command or parameter.

// Loop through the G-code lines while printing each
// lines command
foreach (var line in program.Lines)
{
    Console.WriteLine(line.Command.ToString());
}
// Print a line as it was in the G-code file
var line = program.Lines[0].ToString();
//M190 S60.000000
// Run the program somehow
foreach (var line in program.Lines)
{
    switch (line.Command.FieldLetter.Letter)
    {
        case 'G':
            DoSomething(line.Command.Code, line.Parameters);
            break;
        case 'M':
            DoSomething(line.Command.Code, line.Parameters);
            break;
    }
}

References

https://reprap.org/wiki/G-code

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.1.0 395 11/10/2021
0.0.1 328 9/26/2021