Hook to halt operations?

Hello all,

I'm wondering if Octorpint has a method to halt all operations meaning send gcode commands, process files and so meanwhile a subprocess finishes. Basically I'm looking to pause the print Job when an API trigger a Job directly or the User press the Print button directly from the GUI.

When an API or User send the direct print job the system does automatically:

  1. octoprint.printer.standard.job - INFO - Print job selected.... data of the job....

  2. Then "FileSelected" event is rasied -> octoprint.plugins - INFO - >>>>>> Event detected: FileSelected

  3. Then Printer state changes to starting -> octoprint.util.comm - INFO - Changing monitoring state from "Operational" to "Starting"

  4. Then Printer state changes to Printer -> octoprint.util.comm - INFO - Changing monitoring state from "Starting" to "Printing"

  5. Finally the "PrintStarted" event is rasised -> octoprint.plugins - INFO - >>>>>> Event detected: PrintStarted

At step 3(State STARTING) of the above flow, the printer starts to parse the selected file and sends GCode commands. What I want here is to pause everything one step earlier, during the event "FileSelected" to make some subprocesses and when it finish allow to continnue the print.

I already have a file preprocessor to obtain the desired data before the file is saved in the system, thats one step of the plugin; but this data is going to be transmitted to the printer only if the Job starts. So if the Job starts I need to halt everything until the printer acknowledge the reception of this data. That is already working and in place, the issue is that while sending this data the printer start working and it start mixing File Gcodes and the Data Custom Gcodes making erratic responses from the printer.

To halt the processes I've tried with Locks, didn't worked. Pause and Resume the print programatically and sometimes works some other not, and thats why I'm looking for a reliable method to do everything before the actual job starts.

Maybe job_on_hold is what you are looking for. That will stop any lines from the job to be sent while held by a plugin:

https://docs.octoprint.org/en/master/modules/printer.html#octoprint.printer.PrinterInterface.job_on_hold

1 Like

Awesome thanks, I'll take a look on that.

Here's a working example for my bed ready plugin, that when a specific @ command is sent through start gcode it will check the camera against a reference image.

Thanks,

I was giving a shot but seems like it even stop my function or I would say any GCODE commands to be sent or receive.

     if event == "FileSelected":  # If file selected gather all data
         try:
             self.file_name = payload.get("name")
             self.file_path = payload.get("path")
             
             with self._printer.job_on_hold():
                 self.get_print_metadata(self.file_name)
                
             ......... Everything stop here. 
 

The function get_print_metadata retreive info and send Gcodes but using the job_on_hold affects those gcodes too. I just need to stop the current job to continue printing while sending that data.
I have a buggy version using pause_print() and presume_print() but i dont like because look so unreliable in the movements of the printer.

File selected is not printing state, so you probably need to move your function inside print start event.