Replace M600 with M118 //action:pause - edit: wrong question / solved

Hi,

I want to use the octoprint pause script for changing the material.
searched for a plugin where I could replace a certain gcode for another code, but couldn't find it.
However, I did find this plugin that replaces G29

So I changed it into my needs, but octoprint tells me this python is not compatible (2.7,>3).

I am not a coder, but what should I change to make ik python3 compatible?
Or is there a more generic plugin that can change certain gcodes?

cheers / joris

script:

coding=utf-8

import octoprint.plugin

class ToggleM600Plugin(octoprint.plugin.OctoPrintPlugin):
def rewrite_m600(self, comm_instance, phase, cmd, cmd_type, gcode, *args, **kwargs):
if gcode and gcode == "M600":
cmd = "M118 //action:pause"
return cmd,

def sent_m600(self, comm_instance, phase, cmd, cmd_type, gcode, *args, **kwargs):
	if gcode and gcode == "M118 //action:pause":
		self._logger.info("Just replaced M600: {cmd}".format(**locals()))

plugin_name = "Toggle M600"
def plugin_load():
global plugin_implementation
plugin_implementation = ToggleM600Plugin()

global __plugin_hooks__
__plugin_hooks__ = {
	"octoprint.comm.protocol.gcode.queuing": __plugin_implementation__.rewrite_m600,
	"octoprint.comm.protocol.gcode.sent": __plugin_implementation__.sent_m600
}

Put M600 in the list of 'Pausing Commands' (Settings > Serial connection). Then it should pause OctoPrint. That's the easiest solution...

Alternatively, you could configure whatever is entering the M600 command to use @pause, or the one you have there. @pause is generally preferred as it doesn't need to go to the printer. For example PrusaSlicer will allow you to set custom gcode.

Or, finally, if you still want to learn what needs to be done for a plugin, you need to add the line __plugin_pythoncompat__ = ">=2.7,<4" & make sure the indentation is all consistent, like:

# coding=utf-8
import octoprint.plugin

class ToggleM600Plugin(octoprint.plugin.OctoPrintPlugin):
    def rewrite_m600(self, comm_instance, phase, cmd, cmd_type, gcode, *args, **kwargs):
        if gcode and gcode == "M600":
           cmd = "M118 //action:pause"
        return cmd,

    def sent_m600(self, comm_instance, phase, cmd, cmd_type, gcode, *args, **kwargs):
        if gcode and gcode == "M118 //action:pause":
        self._logger.info("Just replaced M600: {cmd}".format(**locals()))

__plugin_name__ = "Toggle M600"
__plugin_pythoncompat__ = ">=2.7,<4"`
def __plugin_load__():
    global __plugin_implementation__
    __plugin_implementation__ = ToggleM600Plugin()

    global __plugin_hooks__
    __plugin_hooks__ = {
        "octoprint.comm.protocol.gcode.queuing": __plugin_implementation__.rewrite_m600,
        "octoprint.comm.protocol.gcode.sent": __plugin_implementation__.sent_m600
}
1 Like

If you do this, you may also want to consider using the nifty pause/resume scripts in OctoPrint's gcode scripts section. GCODE Scripts — OctoPrint master documentation

That's a good one...! cannot try at the moment, but will it never send the M600 to the firmware then?

Alternatively, you could configure whatever is entering the M600 command to use @pause , or the one you have there. @pause is generally preferred as it doesn't need to go to the printer. For example PrusaSlicer will allow you to set custom gcode.

Thats plan B, but don't want to change the firmware at this moment
The M600 is triggered by a filament sensor. I already have adjusted the firmware (but didn't upload yet) that it will not send a M600 anymore, but M118 //action:pause. Together with the action commends plugin

Will also try to alter the plugin. Always nice to learn things...

If you do this, you may also want to consider using the nifty pause/resume scripts in OctoPrint's gcode scripts section. GCODE Scripts — OctoPrint master documentation

Yes, I already use that. works good!

If the M600 is sent by the printer firmware, it will never reach OctoPrint. OctoPrint can only rewrite what it sends itself, so it won't make a difference here.

What I think you may be looking for, is already a feature in the firmware & in OctoPrint. There's no need to be creating your own solutions if I understand what you are doing.

Enabling the HOST_ACTION_COMMANDS in Marlin (configuration_adv.h), then it will send the action command for you when filament runs out. And OctoPrint has built in support for receiving it, no need for any other work. Enabling HOST_PROMPT_SUPPORT and you can interact with the change filament prompts without needing to go to the printer's LCD, built in to OctoPrint & Marlin.

Ah, of coarse. Could think of that by myself, duh....

This is not enabled yet. Will do that, together with HOST_PROMPT_SUPPORT
I now made a button with a M108 command as alternative to a LCD panel (which I don't have on that printer)

What I don't get is: Do I still need this line in configuration.h
#define FILAMENT_RUNOUT_SCRIPT "M600"

My initial change (before your suggestion!) was to replace that with
#define FILAMENT_RUNOUT_SCRIPT "M118 //action:pause"

(hmmm... its getting more like a marlin topic now... : )