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.

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_streamer.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.

Constants

The library defines the following constants:

  • X_AXIS, Y_AXIS, Z_AXIS, E_AXIS: Character constants for different axes
  • INCHES, MILLIMETERS: String constants for units

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.

SetAxisResolution

void SetAxisResolution(Axis axis, double resolution);

Sets the resolution for the specified axis. This method only works if the device is connected.

SetForwardLimit

void SetForwardLimit(Axis axis, double limit);

Sets the forward limit for the specified axis. This method only works if the device is connected.

SetFeedrate

void SetFeedrate(double feedrate);

Sets the feedrate for the device. This method only works if the device is connected.

SetUnits

void SetUnits(Units units);

Sets the units (inches or millimeters) for the device. This method only works if the device is connected.

SendGCode

void SendGCode(const std::string& gcode);

Sends a G-code command to the device. This method only works if the device is connected.

ExecuteGCodeFile

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

Loads and executes a G-code file from the specified file path. This method only works if the device is connected.

Stop

void Stop();

Immediately stops the processing of any G-Code Command or G-Code File.

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 gcode_streamer.lib

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 {
        // Set parameters
        streamer.SetUnits(MILLIMETERS);
        streamer.SetAxisResolution(X_AXIS, 1000);
        streamer.SetAxisResolution(Y_AXIS, 2000);
        streamer.SetFeedrate(1000);        

        // Send a simple G-code command
        std::cout << "Moving to position (100,100)..." << std::endl;
        streamer.SendGCode("G1 X100 Y100");

        // Execute a G-code file
        std::cout << "Executing G-code file..." << std::endl;
        streamer.ExecuteGCodeFile("C:/path/to/your/file.gcode");
    }
    catch (const std::exception& e) {
        std::cerr << "Error: " << e.what() << std::endl;
        return 1;
    }

    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.