diff --git a/Marlin/src/core/language.h b/Marlin/src/core/language.h index 82ed6cc549b2..ad84966453f1 100644 --- a/Marlin/src/core/language.h +++ b/Marlin/src/core/language.h @@ -135,6 +135,7 @@ #define STR_BUSY_PAUSED_FOR_USER "busy: paused for user" #define STR_BUSY_PAUSED_FOR_INPUT "busy: paused for input" #define STR_Z_MOVE_COMP "Z_move_comp" +#define STR_LINE_NO "Line: " #define STR_RESEND "Resend: " #define STR_UNKNOWN_COMMAND "Unknown command: \"" #define STR_ACTIVE_EXTRUDER "Active Extruder: " diff --git a/Marlin/src/gcode/gcode.h b/Marlin/src/gcode/gcode.h index 8004187903dd..1e3ec7c7f168 100644 --- a/Marlin/src/gcode/gcode.h +++ b/Marlin/src/gcode/gcode.h @@ -143,7 +143,7 @@ * R Wait for extruder current temp to reach target temp. ** Wait for heating or cooling. ** * If AUTOTEMP is enabled, S B F. Exit autotemp by any M109 without F * - * M110 - Set the current line number. (Used by host printing) + * M110 - Get or set the current line number. (Used by host printing) * M111 - Set debug flags: "M111 S". See flag bits defined in enum.h. * M112 - Full Shutdown. * diff --git a/Marlin/src/gcode/host/M110.cpp b/Marlin/src/gcode/host/M110.cpp index 2634b198978d..c2655dfd20ea 100644 --- a/Marlin/src/gcode/host/M110.cpp +++ b/Marlin/src/gcode/host/M110.cpp @@ -24,11 +24,19 @@ #include "../queue.h" // for last_N /** - * M110: Set Current Line Number + * M110: Get or set Current Line Number + * + * Parameters: + * N Number to set as last-processed command + * + * Without parameters: + * Report the last-processed (not last-received or last-enqueued) command + * (To purge the queue and resume from this line, the host should use 'M999' instead.) */ void GcodeSuite::M110() { if (parser.seenval('N')) queue.set_current_line_number(parser.value_long()); - + else + SERIAL_ECHOLNPGM(STR_LINE_NO, queue.get_current_line_number()); } diff --git a/Marlin/src/gcode/queue.h b/Marlin/src/gcode/queue.h index 7281a48bb702..07e08493d1de 100644 --- a/Marlin/src/gcode/queue.h +++ b/Marlin/src/gcode/queue.h @@ -212,6 +212,11 @@ class GCodeQueue { */ static void set_current_line_number(long n) { serial_state[ring_buffer.command_port().index].last_N = n; } + /** + * Get the current line number for the last received command + */ + static long get_current_line_number() { return serial_state[ring_buffer.command_port().index].last_N; } + #if ENABLED(BUFFER_MONITORING) private: