Back to Supported G-Codes

M114 - Get Current Position

DMC File Mode: Not Supported
Streaming Mode: Supported

Description

M114 reports the current position of all configured linear axes. Unlike most G-code commands, M114 returns data through the command result callback.

The result contains a key-value pair for each configured linear axis, where the key is the axis letter (e.g., "X", "Y", "Z") and the value is the current position in user units. Spindle axes are excluded from the result.

Result Payload: M114 returns a result with type GCODE_RESULT_POSITION. Use the result accessor functions to read axis positions from inside the command result callback.

Syntax

M114

Parameters

M114 takes no parameters.

Result Data

FieldValue
Result TypeGCODE_RESULT_POSITION (1)
KeysAxis letters for each configured linear axis (e.g., "X", "Y", "Z")
Value Typedouble — position in user units (inches or mm)
CountNumber of configured linear axes (excludes spindle axes)

Examples

G-Code Usage

; Move to a known position
G90
G1 X10 Y20 Z5 F500
; Report current position
M114

Reading Position in the Callback (C API)

#include "gcode_api.h"
#include <stdio.h>

void on_result(const char* cmd, GCodeResultHandle result, void* data) {
    if (gcode_result_get_type(result) == GCODE_RESULT_POSITION) {
        int count = gcode_result_get_count(result);
        printf("Position reported (%d axes):\n", count);

        double val;
        if (gcode_result_get_double(result, "X", &val) == GCODE_OK)
            printf("  X = %.4f\n", val);
        if (gcode_result_get_double(result, "Y", &val) == GCODE_OK)
            printf("  Y = %.4f\n", val);
        if (gcode_result_get_double(result, "Z", &val) == GCODE_OK)
            printf("  Z = %.4f\n", val);
    }
}

int main() {
    const char* key = getenv("GCODE_LICENSE_KEY");
    GCodeHandle h = gcode_create(key);
    gcode_set_command_result_callback(h, on_result, NULL);

    gcode_connect(h, "192.168.1.100");

    gcode_configure_linear_axis(h, 'X', 'A', 1000.0, 100.0);
    gcode_configure_linear_axis(h, 'Y', 'B', 1000.0, 100.0);
    gcode_configure_linear_axis(h, 'Z', 'C', 1000.0, 50.0);

    gcode_add_command(h, "G1 X10 Y20 Z5 F500");
    gcode_add_command(h, "M114");

    gcode_start(h);
    gcode_wait_for_queue_empty(h, 30000);

    gcode_disconnect(h);
    gcode_destroy(h);
    return 0;
}

Expected output:

Position reported (3 axes):
  X = 10.0000
  Y = 20.0000
  Z = 5.0000

Notes

  • Positions are reported in user units (inches or millimeters), based on the counts_per_user_unit value set during gcode_configure_linear_axis().
  • Spindle axes (configured via gcode_configure_spindle()) are not included in the result.
  • The GCodeResultHandle is only valid during the callback invocation. Copy any values you need before the callback returns.
  • If no linear axes are configured, the result will have type GCODE_RESULT_POSITION with a count of 0.