Hi folks,
There’s a really, really simple way to implement “disaster recovery” if we log the last line of gcode sent to a printer over USB, dupe the gcode associated with the print and strip any code above the ‘last line sent’… it might not be perfect, but it would probably work 99% of the
time. Even if it doesn’t make it into the main build, I’d like to add this functionality to a fork of Cura. How would I go about doing this?
I snaked through the Github and eventually found where the serialized gcode commands are being sent.
It seems like we could, at the start of the print, serialize/write all of the gcode to a file. While iterating through
try:
command = (cmd + "\n").encode()
self._serial.write(b"\n")
self._serial.write(command)
except serial.SerialTimeoutException:
Logger.log("w","Serial timeout while writing to serial port, trying again.")
try:
time.sleep(0.5)
self._serial.write((cmd + "\n").encode())
except Exception as e:
Logger.log("e","Unexpected error while writing serial port %s " % e)
self._setErrorState("Unexpected error while writing serial port %s " % e)
self.close()
except Exception as e:
Logger.log("e","Unexpected error while writing serial port %s" % e)
self._setErrorState("Unexpected error while writing serial port %s " % e)
self.close()
I propose we add a “finally” to cache the last sent command… either just in a variable or written to a file.
finally:
self._last_command = command
How would I add a button to Cura that, assuming a print is in a paused/canceled/non-printing state, would read from this last command, manipulate the cached gcode file and remove everything up to and including this _last_command, then send the modified gcode to the printer?