From db6c7eaa6781aad4d2ddf3e76db42564f41e2424 Mon Sep 17 00:00:00 2001 From: Daid Date: Wed, 9 May 2012 22:47:27 +0200 Subject: [PATCH] Better catch errors in first run wizard. --- Cura/gui/configWizard.py | 17 +++++++++++++++-- Cura/gui/machineCom.py | 10 +++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/Cura/gui/configWizard.py b/Cura/gui/configWizard.py index 812b073f..50f84989 100644 --- a/Cura/gui/configWizard.py +++ b/Cura/gui/configWizard.py @@ -174,6 +174,11 @@ class UltimakerCheckupPage(InfoPage): def OnRun(self): wx.CallAfter(self.AddProgressText, "Connecting to machine...") self.comm = machineCom.MachineCom() + + if not self.comm.isOpen(): + wx.CallAfter(self.AddProgressText, "Error: Failed to open serial port to machine") + wx.CallAfter(self.AddProgressText, "If this keeps happening, try disconnecting and reconnecting the USB cable") + return wx.CallAfter(self.AddProgressText, "Checking start message...") if self.DoCommCommandWithTimeout(None, 'start') == False: @@ -288,10 +293,10 @@ class UltimakerCheckupPage(InfoPage): t.start() while True: line = self.comm.readline() - if line == '': + if line == '' or line == None: self.comm.close() return False - print line + print line.rstrip() if line.startswith(replyStart): break t.cancel() @@ -369,6 +374,10 @@ class UltimakerCalibrateStepsPerEPage(InfoPage): self.extrudeButton.Enable(False) currentEValue = float(self.stepsPerEInput.GetValue()) self.comm = machineCom.MachineCom() + if not self.comm.isOpen(): + wx.CallAfter(self.AddProgressText, "Error: Failed to open serial port to machine") + wx.CallAfter(self.AddProgressText, "If this keeps happening, try disconnecting and reconnecting the USB cable") + return while True: line = self.comm.readline() if line == '': @@ -392,6 +401,10 @@ class UltimakerCalibrateStepsPerEPage(InfoPage): def OnHeatRun(self): self.comm = machineCom.MachineCom() + if not self.comm.isOpen(): + wx.CallAfter(self.AddProgressText, "Error: Failed to open serial port to machine") + wx.CallAfter(self.AddProgressText, "If this keeps happening, try disconnecting and reconnecting the USB cable") + return while True: line = self.comm.readline() if line == '': diff --git a/Cura/gui/machineCom.py b/Cura/gui/machineCom.py index 5157fbe8..73837d48 100644 --- a/Cura/gui/machineCom.py +++ b/Cura/gui/machineCom.py @@ -153,12 +153,13 @@ class MachineCom(): programmer = stk500v2.Stk500v2() for port in serialList(): try: + print "Connecting to: %s %i" % (port, baudrate) programmer.connect(port) programmer.close() - print "Connecting to: %s %i" % (port, baudrate) self.serial = Serial(port, baudrate, timeout=2) break except ispBase.IspError: + print "Error while connecting to %s %i" % (port, baudrate) pass except: print "Unexpected error while connecting to serial port:" + port, sys.exc_info()[0] @@ -170,6 +171,7 @@ class MachineCom(): self.serial = Serial(port, baudrate, timeout=2) except: print "Unexpected error while connecting to serial port:" + port, sys.exc_info()[0] + print self.serial def readline(self): if self.serial == None: @@ -184,6 +186,12 @@ class MachineCom(): self.serial.close() self.serial = None + def __del__(self): + self.close() + + def isOpen(self): + return self.serial != None + def sendCommand(self, cmd): if self.serial == None: return -- 2.30.2