Sending GCODE commands from within a plugin

What’s the preferred method for sending a gcode command (such as “M117 Hello World”) from Python from within a Klipper plug-in? I could shell out and write to /tmp/printer, but that doesn’t seem very elegant.

Thanks :slight_smile:

1 Like

That code is the opposite of what I need – this shows how to use gcode commands to interact w/the plugin.

How do I use the plugin to issue gcode commands back to Klipper? e.g. change the display text with M117?

I think they meant to point to later in the file, where run_script_from_command() is used:

    def cmd_G11(self, gcmd):
        if self.is_retracted:
            self.gcode.run_script_from_command(
                "SAVE_GCODE_STATE NAME=_retract_state\n"
                "G91\n"
                "G1 E%.5f F%d\n"
                "RESTORE_GCODE_STATE NAME=_retract_state"
                % (self.unretract_length, self.unretract_speed*60))
            self.is_retracted = False

(klipper/pause_resume.py at master · Klipper3d/klipper · GitHub is a better example, since it also demonstrates run_script())

2 Likes

Thanks @flowerysong – that worked perfectly.