I can answer this, no need to bother @foosel. The reason that gcode sent was that it was queued before (or while) you paused the print. I hadn't thought about that, but Octolapse needs to deal with this too. Here's an outline of what might work, but note that I typed this in without checking for errors of logic or syntax:
def __init__(self, printer):
self.job_is_on_hold = False
# save a reference to the octoprint printer object
self.printer = printer
# member to hold a command that will need to be sent when we unpause
self.save_command = None
# set this to true somewhere to pause the print, wherever that is
self.pausing = False
# I think you'll need to deal with cancelling as well. Not sure
self.cancelling = False
# you would call this from an event handler that is looking for cancelling events.
# Probably from your main __init__ file
def print_cancelling(self):
# we only need to handle this if the job is on hold.
if self.job_is_on_hold:
# just in case, clear the pausing flag
self.pausing = False
# release the lock. This is really important
self.printer.set_job_on_hold(False)
# you may have to reset the axis mode here if you've changed it in pause print
reset_axis_mode_gcode = self.get_reset_axis_mode_gcode()
# only send commands if there are commands to send.
if len(reset_axis_mode_gcode) > 0:
# Since I'd expect cancel/end gcode to work at this point, reset the axis mode.
# also, FYI, if the extruder is cold, and the end gcode moves the E axis at all (retract maybe)
# you could get jams here. Not sure what you want to do here exactly, but I think this is
# surmountable. You could probably just suppress the end/cancel gcode since that would be simpler.
self.printer.commands(reset_axis_mode_gcode, tags=set(['TSD']))
def get_reset_axis_modes_gcode(self):
# need to implement this
return []
def get_set_axis_modes_gcode(self):
# need to implement this
return []
def pause_print(self, save_command):
# why the mutex here? I admit I haven't looked at the rest of your source though, so maybe you need it?
with self.mutex:
self.printer.set_job_on_hold(True)
self.job_is_on_hold = True
self.pausing = False
# you need to save any commands that are queuing, else they will be lost
self.save_command = save_command
# send your pause commands now, you'll get no interference
self.printer.commands(self.get_pause_gcode(), tags=set(['TSD']))
# now this might not work. Octolapse used to use the pause function, but I ran into issues.
# It might work in your case. If not, you can just deal with the pause button manually.
# do this last so that you can get that retract command to the printer ASAP!
self.printer.pause_print()
def get_pause_gcode(self):
# create your pause gcode array here
# set the axis mode
pause_gcode = self.get_set_axis_modes_gcode()
# some gcode generation code you'll need to write goes here
pause_gcode.extend(GCODES_NEEDED_TO_PAUSE)
return pause_gcode
def resume_print(self):
# send your resume commands now, you'll get no interference
self.printer.commands(self.get_resume_gcode(), tags=set(['TSD']))
# whatever the resume command is, send it here. I can't recall off the top of my head either :)
# The same caveats apply to resume as I mentioned for pause above.
self.printer.resume_print()
# why the mutex here? I admit I haven't looked at the rest of your source though, so maybe you need it?
# release the lock last so that you can be assured all of your gcodes have sent
with self.mutex:
self.printer.set_job_on_hold(False)
self.job_is_on_hold = False
def get_resume_gcode(self):
# some gcode generation code you'll need to write goes here
resume_gcode = [GCODES_YOU_NEED_TO_RESUME]
# reset the axis mode to what it was before you paused.
resume_gcode.extend(self.get_reset_axis_modes_gcode())
# Send the command that was queuing when you paused.
resume_gcode.append(self.save_command)
return resume_gcode
def on_gcode_queuing(self, comm_instance, phase, cmd, cmd_type, gcode, subcode=None, tags=None, *args, **kwargs):
# you may need to rethink this part if you decide to reset the axis mode on cancel. In that case
# your axis mode tracking will need to know that you switched axis modes, but your code below won't
# see any of the G90/G91 M82/M83 commands. There are other ways to handle this, of course, like just
# storing the original axis mode when you pause.
if 'TSD' in tags:
return
# somewhere in your code you will set self.pausing = True to indicate you want to pause.
# the actual pause will occur when the next gcode is queuing. You may have to deal with an edge case
# where you pause AFTER the last line of gcode is sent to the printer. That would be extremely unlikely
# though :)
# need to check for for pause BEFORE you do any axis mode checks since
# this command will be suppressed if we are pausing
if self.pausing:
# you may need a reference to the printer here, not sure where that is coming from
self.pause_print(cmd)
# suppress the gcode command so that it doesn't send (this prevents the problem you were having)
# you will have to send it when you resume
return (None ,)
# you might have to check for and suppress cancel/end gcode here if the print was cancelled while your
# plugin is paused. Depends on how you handle cancelling.
# now you can track the axis mode!
with self.mutex: # why are you using a mutex here? I admit I haven't looked at the calling code though.
if re.match('G9[01]', cmd, flags=re.IGNORECASE):
self.last_g9x = cmd
print('commander setting: {}'.format(self.last_g9x))
if re.match('M8[23]', cmd, flags=re.IGNORECASE):
self.last_m8x = cmd
It's not complete, but it should get you started. I tried to comment everything as much as possible.