Skip to content

Commit

Permalink
improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Kriechi committed Feb 15, 2018
1 parent 691a31d commit c3aca85
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
35 changes: 35 additions & 0 deletions DuetRRFOutputDevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ def __init__(
self._stream = None
self._cleanupRequest()

if hasattr(self, '_message'):
self._message.hide()
self._message = None


def _timestamp(self):
return ("time", datetime.datetime.now().strftime('%Y-%m-%dT%H:%M:%S'))

Expand Down Expand Up @@ -173,6 +178,9 @@ def onFilenameAccepted(self):
self._send('connect', [("password", self._duet_password), self._timestamp()], self.onConnected)

def onConnected(self):
if self._stage != OutputStage.writing:
return

Logger.log("d", "Connected")
Logger.log("d", "Uploading...")

Expand All @@ -182,6 +190,9 @@ def onConnected(self):
self._send('upload', [("name", "0:/gcodes/" + self._fileName), self._timestamp()], self.onUploadDone, self._postData)

def onUploadDone(self):
if self._stage != OutputStage.writing:
return

Logger.log("d", "Upload done")

self._stream.close()
Expand Down Expand Up @@ -212,10 +223,16 @@ def onUploadDone(self):
self._cleanupRequest()

def onReadyToPrint(self):
if self._stage != OutputStage.writing:
return

Logger.log("d", "Ready to print")
self._send('gcode', [("gcode", "M32 /gcodes/" + self._fileName)], self.onPrintStarted)

def onPrintStarted(self):
if self._stage != OutputStage.writing:
return

Logger.log("d", "Print started")

if self._device_type == DeviceType.simulate:
Expand All @@ -234,16 +251,25 @@ def onPrintStarted(self):
self._cleanupRequest()

def onSimulatedPrintFinished(self):
if self._stage != OutputStage.writing:
return

Logger.log("d", "Simulation print finished")

self._send('gcode', [("gcode", "M37 S0")], self.onSimulationStopped)

def onCheckStatus(self):
if self._stage != OutputStage.writing:
return

Logger.log("d", "Check status")

self._send('status', [("type", "3")], self.onStatusReceived)

def onStatusReceived(self):
if self._stage != OutputStage.writing:
return

Logger.log("d", "Status received")

status_bytes = bytes(self._reply.readAll())
Expand All @@ -260,16 +286,25 @@ def onStatusReceived(self):
self.onSimulatedPrintFinished()

def onSimulationStopped(self):
if self._stage != OutputStage.writing:
return

Logger.log("d", "Simulation stopped")

self._send('gcode', [("gcode", "M37")], self.onReporting)

def onReporting(self):
if self._stage != OutputStage.writing:
return

Logger.log("d", "Reporting")

self._send('reply', [], self.onReported)

def onReported(self):
if self._stage != OutputStage.writing:
return

Logger.log("d", "Reported")

self._send('disconnect')
Expand Down
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"name": "DuetRRF",
"author": "Thomas Kriechbaumer",
"description": "Provides direct upload of gcode to DuetRRF.",
"version": "0.0.5",
"version": "0.0.6",
"api": 4
}

0 comments on commit c3aca85

Please sign in to comment.