Welcome! Log In Create A New Profile

Advanced

How do I know which line of Gcode my printer is currently executing?

Posted by CharlesDesign 
How do I know which line of Gcode my printer is currently executing?
October 04, 2018 06:37AM
Hi All,

I'm writing a custom print host in Python using PySerial, very similar to Printcore but with some added features.

Currently, I'm sending line-by-line as I receive the 'ok' back from the board which is pretty much instant.

I therefore understand that the lines are getting buffered in the board waiting to be executed.

However, from my python code I need to know which line is currently being executed, how can I do so?

A workaround could be to send a 'M114' but this just gives me coordinates and not line number.

Can someone clarify?

Thanks,
Charles
Re: How do I know which line of Gcode my printer is currently executing?
October 04, 2018 07:55AM
Marlin doesnt count line numbers as such when accepting data over usb/serial (as far as I know)

It does watch line number if you send them ie N field and checksum, wont match actual line number in text file as comments are not counted

"Spit balling here"

SERIAL_PROTOCOLLN(gcode_LastN); will print the current N field

but as you say things are buffered. so that would just show last sent line, not last actioned

looking in the power recovery code I see the following

job_recovery_info.cmd_queue_index_r = cmd_queue_index_r;
job_recovery_info.commands_in_queue = commands_in_queue;

so you might try adding all this to M114

find in Marlin_main.cpp
void report_current_position() {
  SERIAL_PROTOCOLPAIR("X:", LOGICAL_X_POSITION(current_position[X_AXIS]));
  SERIAL_PROTOCOLPAIR(" Y:", LOGICAL_Y_POSITION(current_position[Y_AXIS]));
  SERIAL_PROTOCOLPAIR(" Z:", LOGICAL_Z_POSITION(current_position[Z_AXIS]));
  SERIAL_PROTOCOLPAIR(" E:", current_position[E_CART]);
and add the line
  SERIAL_PROTOCOLPAIR(" Line:", gcode_LastN-commands_in_queue+ cmd_queue_index_r);

NB It compiles, but I haven't tried it... It may be out by 1, depends if the ring buffer starts 0 or 1. Or it may not work at all.

I do notice your still at this... and your still slowly getting us to do all your work for you...

Edited 3 time(s). Last edit at 10/04/2018 08:03AM by Dust.
Re: How do I know which line of Gcode my printer is currently executing?
October 04, 2018 11:35AM
That's very helpful @Dust, once again: Thanks for your help.
Re: How do I know which line of Gcode my printer is currently executing?
October 05, 2018 12:58AM
Thinking on it... its not quite right...

its a ring buffer, you need to know current position, and current start position and length...

my off the cuff doesn't take into account start position, and then you have to make sure the ring part is taken into account... wrapping around and all that.

So thats something to work on smiling smiley
Sorry, only registered users may post in this forum.

Click here to login