Back to Supported G-Codes

M118 - Send Message

DMC File Mode: Not Supported
Streaming Mode: Supported

Description

M118 sends a string message through the command completed callback via a result payload. Everything after M118 is treated as the message text.

This command is useful for sending status updates, debug information, or progress messages from a G-code program back to the host application. The original casing and special characters in the message are preserved.

Result Payload: M118 returns a result with type GCODE_RESULT_MESSAGE. Use the result accessor functions to read the message string from inside the command completed callback.

Syntax

M118 <message text>

Parameters

ParameterDescription
<message text>Everything after M118 is the message. Special characters, spaces, and mixed casing are all preserved. If omitted, an empty message is sent.

Result Data

FieldValue
Result TypeGCODE_RESULT_MESSAGE (2)
Key"message"
Value Typestring — the message text
Count1

Examples

G-Code Usage

; Send a status message
M118 Starting drill cycle
G81 X10 Y10 Z-5 R1 F100
; Send completion message
M118 Drill cycle complete!

Reading the Message in the Callback (C API)

void on_completed(int index, int total, const char* cmd,
                  GCodeResultHandle result, void* data) {
    if (gcode_result_get_type(result) == GCODE_RESULT_MESSAGE) {
        const char* message = NULL;
        if (gcode_result_get_string(result, "message", &message) == GCODE_OK) {
            printf("G-code message: %s\n", message);
        }
    }
}

Expected output for M118 Starting drill cycle:

G-code message: Starting drill cycle

Notes

  • The message preserves its original casing — M118 Hello World delivers "Hello World", not "HELLO WORLD".
  • Special characters (!, @, #, %, etc.) are allowed and preserved in the message.
  • If no message text is provided (just M118), an empty string is delivered.
  • The GCodeResultHandle is only valid during the callback invocation. Copy the message string before the callback returns.