Send M112 to printer immediately
Address #1031 with an immediate send of M112 followed by closing the
serial connection to reset the host state
(cherry picked from commit 3d1d745)
This commit is contained in:
parent
0e863ad776
commit
948e20b269
1 changed files with 50 additions and 7 deletions
|
|
@ -214,7 +214,7 @@ class MachineCom(object):
|
|||
self._temp = {}
|
||||
self._bedTemp = None
|
||||
self._tempOffsets = dict()
|
||||
self._commandQueue = queue.Queue()
|
||||
self._commandQueue = ClearableQueue()
|
||||
self._currentZ = None
|
||||
self._heatupWaitStartTime = None
|
||||
self._heatupWaitTimeLost = 0.0
|
||||
|
|
@ -1755,8 +1755,30 @@ class MachineCom(object):
|
|||
self._lastLines.clear()
|
||||
self._resendDelta = None
|
||||
|
||||
def _gcode_M112_queuing(self, cmd, cmd_type=None): # It's an emergency what todo? Canceling the print should be the minimum
|
||||
self.cancelPrint()
|
||||
def _gcode_M112_queuing(self, cmd, cmd_type=None):
|
||||
# emergency stop, tell the printer right now and clear the queues
|
||||
# jump the queue with the M112
|
||||
self._doSendWithoutChecksum("M112")
|
||||
self._doSendWithChecksum("M112", self._currentLine)
|
||||
|
||||
# of course, these clears are too late to get the one that another thread
|
||||
# is in between get and task_done
|
||||
self._commandQueue.clear()
|
||||
self._send_queue.clear()
|
||||
|
||||
# close to reset host state
|
||||
self._errorValue = "Closing serial port due to emergency stop M112."
|
||||
self._log(self._errorValue)
|
||||
self.close(is_error=True)
|
||||
|
||||
# fire the M112 event since we sent it and we're going to prevent the caller from seeing it
|
||||
gcode = "M112"
|
||||
if gcode in gcodeToEvent:
|
||||
eventManager().fire(gcodeToEvent[gcode])
|
||||
|
||||
# return None 1-tuple to eat the one that is queuing because we don't want to send it twice
|
||||
# I hope it got it the first time because as far as I can tell, there is no way to know
|
||||
return None,
|
||||
|
||||
def _gcode_G4_sent(self, cmd, cmd_type=None):
|
||||
# we are intending to dwell for a period of time, increase the timeout to match
|
||||
|
|
@ -1980,10 +2002,27 @@ class StreamingGcodeFileInformation(PrintingGcodeFileInformation):
|
|||
return self._remoteFilename
|
||||
|
||||
|
||||
class TypedQueue(queue.Queue):
|
||||
class ClearableQueue(queue.Queue):
|
||||
def clear(self):
|
||||
self.all_tasks_done.acquire()
|
||||
try:
|
||||
self._clear()
|
||||
finally:
|
||||
self.all_tasks_done.release()
|
||||
|
||||
def _clear(self):
|
||||
count = len(self.queue)
|
||||
self.queue.clear()
|
||||
self.unfinished_tasks -= count
|
||||
if (self.unfinished_tasks <= 0):
|
||||
self.all_tasks_done.notify_all();
|
||||
self.not_full.notify()
|
||||
|
||||
|
||||
class TypedQueue(ClearableQueue):
|
||||
|
||||
def __init__(self, maxsize=0):
|
||||
queue.Queue.__init__(self, maxsize=maxsize)
|
||||
ClearableQueue.__init__(self, maxsize=maxsize)
|
||||
self._lookup = []
|
||||
|
||||
def _put(self, item):
|
||||
|
|
@ -1995,10 +2034,10 @@ class TypedQueue(queue.Queue):
|
|||
else:
|
||||
self._lookup.append(cmd_type)
|
||||
|
||||
queue.Queue._put(self, item)
|
||||
ClearableQueue._put(self, item)
|
||||
|
||||
def _get(self):
|
||||
item = queue.Queue._get(self)
|
||||
item = ClearableQueue._get(self)
|
||||
|
||||
if isinstance(item, tuple) and len(item) == 3:
|
||||
cmd, line, cmd_type = item
|
||||
|
|
@ -2007,6 +2046,10 @@ class TypedQueue(queue.Queue):
|
|||
|
||||
return item
|
||||
|
||||
def _clear(self):
|
||||
ClearableQueue._clear(self)
|
||||
self._lookup = []
|
||||
|
||||
|
||||
class TypeAlreadyInQueue(Exception):
|
||||
def __init__(self, t, *args, **kwargs):
|
||||
|
|
|
|||
Loading…
Reference in a new issue