GCodeStreamer Documentation

Introduction

GCodeStreamer is a C++ library for managing and streaming G-code commands to DMC controllers for CNC and 3D printing applications. It provides an interface for connecting to a device, setting various parameters, and sending G-code commands.

📏 Units Support

The API works seamlessly with G-Code specified in inches or millimeters

Simply ensure your project maintains consistent units throughout all commands and configurations.

Installation

Before using the GCodeStreamer library, you'll need to download and install the latest version of the software package.

Setup

To use the GCodeStreamer library in your project, you need to:

  1. Add gcode_streamer.h to your include path.
  2. Link against gcode_api.lib.

Both of these files are located in the root of your GCodeStreamer installation. This path is provided to you with the GALIL_GCODES environment variable upon installation. Make sure to set up your project's include directories and linker settings accordingly.

Methods

Constructor and Destructor

GCodeStreamer();
~GCodeStreamer();

Connect

bool Connect(const std::string& ip_address);

Establishes a connection to the device at the specified IP address. Returns true if the connection is successful.

Disconnect

void Disconnect();

Disconnects from the motion controller.

ConfigureLinearAxis

void ConfigureLinearAxis(
    char gcode_axis,
    char dmc_axis,
    double counts_per_user_unit,
    double forward_limit = std::numeric_limits<double>::infinity()
);

Configures mapping between G-code axis and physical controller axis. Sets the conversion factor from user units to controller counts and optionally sets a forward travel limit. The forward limit is specified in the user's units (inches or millimeters). This method only works if the device is connected.

ConfigureSpindle

void ConfigureSpindle(
    char dmc_axis,
    double counts_per_revolution
);

Configures the dmc axis that controls the spindle. Sets the conversion factor from revolutions to controller counts. This method only works if the device is connected.

AddGCodeCommand

void AddGCodeCommand(const std::string& gcode_string);

Adds a single G-code command to the execution queue. This method only works if the device is connected.

AddGCodeFile

void AddGCodeFile(const std::string& file_path);

Loads and adds all G-code commands from a file to the execution queue. This method only works if the device is connected.

Start

void Start();

Starts processing the queued G-code commands. This method only works if the device is connected.

WaitForQueueEmpty

void WaitForQueueEmpty();

Waits until all queued commands have been processed. This method only works if the device is connected.

Stop

void Stop();

Stops processing G-code commands.

Resume

void Resume();

Resumes processing after an M0 pause command.

Usage Example

Visual Studio Project Setup

  1. Create a new Visual Studio C++ Console Application Project
  2. Right-click on your project in Solution Explorer and select "Properties"
  3. Under "C/C++" → "General" → "Additional Include Directories", add $(GALIL_GCODES)
  4. Under "Linker" → "General" → "Additional Library Directories", add $(GALIL_GCODES)
  5. Under "Linker" → "Input" → "Additional Dependencies", add the appropriate library:
    • gcode_apid.lib for Debug builds
    • gcode_api.lib for Release builds

Example Code

// main.cpp
#include <iostream>
#include "gcode_streamer.h"

int main() {
    GCodeStreamer streamer;
    
    // Connect to the device
    std::string ip_address = "192.168.1.100";  // Replace with your device's IP
    if (!streamer.Connect(ip_address)) {
        std::cerr << "Failed to connect to device at " << ip_address << std::endl;
        return 1;
    }
    
    std::cout << "Successfully connected to device" << std::endl;

    try {
        // Configure axes (G-code axis, DMC axis, counts per unit, optional limit)
        streamer.ConfigureLinearAxis('X', 'A', 1000.0);
        streamer.ConfigureLinearAxis('Y', 'B', 2000.0);
        streamer.ConfigureLinearAxis('Z', 'C', 1000.0, 100.0);  // Z with 100mm limit

        // Add G-code commands to queue
        std::cout << "Adding G-code commands to queue..." << std::endl;
        streamer.AddGCodeCommand("G1 X100 Y100 F1000");
        streamer.AddGCodeCommand("G1 Z10");

        // Add G-code file to queue
        std::cout << "Adding G-code file to queue..." << std::endl;
        streamer.AddGCodeFile("C:/path/to/your/file.gcode");

        // Start processing the queue
        std::cout << "Starting G-code execution..." << std::endl;
        streamer.Start();

        // Wait for all commands to complete
        std::cout << "Waiting for commands to complete..." << std::endl;
        streamer.WaitForQueueEmpty();
        
        std::cout << "All commands completed!" << std::endl;
    }
    catch (const std::exception& e) {
        std::cerr << "Error: " << e.what() << std::endl;
        streamer.Stop();  // Stop on error
        return 1;
    }

    // Disconnect when done
    streamer.Disconnect();
    return 0;
}

Building and Running

  1. Make sure the GCodeStreamer software package is installed and the GALIL_GCODES environment variable is set
  2. Set the build configuration to Release/x64 or Debug/x64 as needed
  3. Press F5 to build and run the program, or Ctrl+F5 to run without debugging
  4. The program will attempt to connect to the device and execute the commands

Note: Remember to replace the IP address and G-code file path with your actual values. Make sure your device is powered on and accessible on the network before running the program.