From: daid303 Date: Thu, 4 Oct 2012 12:05:09 +0000 (+0200) Subject: Add extrude/retract images for printing interface. Made exception handling a bit... X-Git-Tag: 13.03~283 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=bc275ccdc29b616e6a099c67f49752758a04b914;p=cura.git Add extrude/retract images for printing interface. Made exception handling a bit more rubust in machine comunication. --- diff --git a/Cura/gui/printWindow.py b/Cura/gui/printWindow.py index e2df8b2e..a648dccc 100644 --- a/Cura/gui/printWindow.py +++ b/Cura/gui/printWindow.py @@ -188,8 +188,8 @@ class printWindow(wx.Frame): sizer.Add(PrintCommandButton(self, ['G91', 'G1 Z-1 F200', 'G90'], 'print-move-z-1.png'), pos=(5,8)) sizer.Add(PrintCommandButton(self, ['G91', 'G1 Z-10 F200', 'G90'], 'print-move-z-10.png'), pos=(6,8)) - sizer.Add(PrintCommandButton(self, ['G92 E0', 'G1 E2 F120'], 'question.png'), pos=(8,1)) - sizer.Add(PrintCommandButton(self, ['G92 E0', 'G1 E-2 F120'], 'question.png'), pos=(8,2)) + sizer.Add(PrintCommandButton(self, ['G92 E0', 'G1 E2 F120'], 'extrude.png', size=(60,20)), pos=(1,10), span=(1,3), flag=wx.EXPAND) + sizer.Add(PrintCommandButton(self, ['G92 E0', 'G1 E-2 F120'], 'retract.png', size=(60,20)), pos=(2,10), span=(1,3), flag=wx.EXPAND) nb.AddPage(self.directControlPanel, 'Jog') diff --git a/Cura/gui/webcam.py b/Cura/gui/webcam.py index 1f309983..d4fe69c5 100644 --- a/Cura/gui/webcam.py +++ b/Cura/gui/webcam.py @@ -80,13 +80,16 @@ class webcam(object): self._bitmap = wx.BitmapFromBuffer(frame.width, frame.height, frame.imageData) elif win32vidcap != None: buffer, width, height = self._cam.getbuffer() - wxImage = wx.EmptyImage(width, height) - wxImage.SetData(buffer[::-1]) - if self._bitmap != None: - del self._bitmap - self._bitmap = wxImage.ConvertToBitmap() - del wxImage - del buffer + try: + wxImage = wx.EmptyImage(width, height) + wxImage.SetData(buffer[::-1]) + if self._bitmap != None: + del self._bitmap + self._bitmap = wxImage.ConvertToBitmap() + del wxImage + del buffer + except: + pass if self._doTimelaps: filename = os.path.normpath(os.path.join(os.path.split(__file__)[0], "../__tmp_snap", "__tmp_snap_%04d.jpg" % (self._snapshotCount))) diff --git a/Cura/images/extrude.png b/Cura/images/extrude.png new file mode 100644 index 00000000..2af4a5ae Binary files /dev/null and b/Cura/images/extrude.png differ diff --git a/Cura/images/retract.png b/Cura/images/retract.png new file mode 100644 index 00000000..cefd1f7c Binary files /dev/null and b/Cura/images/retract.png differ diff --git a/Cura/util/machineCom.py b/Cura/util/machineCom.py index 6ea4ad0a..1c0e60ee 100644 --- a/Cura/util/machineCom.py +++ b/Cura/util/machineCom.py @@ -4,7 +4,7 @@ import __init__ import os, glob, sys, time, math, re, traceback, threading import Queue as queue -from serial import Serial +import serial from avr_isp import stk500v2 from avr_isp import ispBase @@ -197,11 +197,16 @@ class MachineCom(object): if self._state == self.STATE_CLOSED: return "Closed" if self._state == self.STATE_ERROR: - return "Error: %s" % (self._errorValue) + return "Error: %s" % (self.getShortErrorString()) if self._state == self.STATE_CLOSED_WITH_ERROR: - return "Error: %s" % (self._errorValue) + return "Error: %s" % (self.getShortErrorString()) return "?%d?" % (self._state) + def getShortErrorString(self): + if len(self._errorValue) < 20: + return self._errorValue + return self._errorValue[:20] + "..." + def isClosedOrError(self): return self._state == self.STATE_ERROR or self._state == self.STATE_CLOSED_WITH_ERROR or self._state == self.STATE_CLOSED @@ -264,9 +269,9 @@ class MachineCom(object): try: self._log("Connecting to: %s" % (self._port)) if self._baudrate == 0: - self._serial = Serial(self._port, 115200, timeout=0.1, writeTimeout=10000) + self._serial = serial.Serial(self._port, 115200, timeout=0.1, writeTimeout=10000) else: - self._serial = Serial(self._port, self._baudrate, timeout=2, writeTimeout=10000) + self._serial = serial.Serial(self._port, self._baudrate, timeout=2, writeTimeout=10000) except: self._log("Unexpected error while connecting to serial port: %s %s" % (self._port, getExceptionString())) if self._serial == None: @@ -299,7 +304,7 @@ class MachineCom(object): #Skip the communication errors, as those get corrected. if 'checksum mismatch' in line or 'Line Number is not Last Line Number' in line or 'No Line Number with checksum' in line: pass - else: + elif not self.isError(): self._errorValue = line[6:] self._changeState(self.STATE_ERROR) if ' T:' in line or line.startswith('T:'): @@ -312,18 +317,21 @@ class MachineCom(object): t = time.time() self._heatupWaitTimeLost = t - self._heatupWaitStartTime self._heatupWaitStartTime = t - elif line.strip() != '' and line.strip() != 'ok' and self.isOperational(): + elif line.strip() != '' and line.strip() != 'ok' and not line.startswith('Resend:') and line != 'echo:Unknown command:""\n' and self.isOperational(): self._callback.mcMessage(line) if self._state == self.STATE_DETECT_BAUDRATE: if line == '' or time.time() > timeout: if len(self._baudrateDetectList) < 1: - self._log("No more baudrates to test, and no suitable baudrate found.") self.close() + self._errorValue = "No more baudrates to test, and no suitable baudrate found." + self._changeState(self.STATE_ERROR) elif self._baudrateDetectRetry > 0: self._baudrateDetectRetry -= 1 self._serial.write('\n') + self._log("Baudrate test retry: %d" % (self._baudrateDetectRetry)) self._sendCommand("M105") + self._testingBaudrate = True else: baudrate = self._baudrateDetectList.pop(0) try: @@ -331,16 +339,25 @@ class MachineCom(object): self._serial.timeout = 0.5 self._log("Trying baudrate: %d" % (baudrate)) self._baudrateDetectRetry = 5 + self._baudrateDetectTestOk = 0 timeout = time.time() + 5 self._serial.write('\n') self._sendCommand("M105") + self._testingBaudrate = True except: self._log("Unexpected error while setting baudrate: %d %s" % (baudrate, getExceptionString())) - elif 'ok' in line: - self._sendCommand("M999") - self._serial.timeout = 2 - profile.putPreference('serial_baud_auto', self._serial.baudrate) - self._changeState(self.STATE_OPERATIONAL) + elif 'ok' in line and 'T:' in line: + self._baudrateDetectTestOk += 1 + if self._baudrateDetectTestOk < 10: + self._log("Baudrate test ok: %d" % (self._baudrateDetectTestOk)) + self._sendCommand("M105") + else: + self._sendCommand("M999") + self._serial.timeout = 2 + profile.putPreference('serial_baud_auto', self._serial.baudrate) + self._changeState(self.STATE_OPERATIONAL) + else: + self._testingBaudrate = False elif self._state == self.STATE_CONNECTING: if line == '': self._sendCommand("M105") @@ -430,7 +447,7 @@ class MachineCom(object): self._log('Send: %s' % (cmd)) try: self._serial.write(cmd + '\n') - except SerialTimeoutException: + except serial.SerialTimeoutException: self._log("Serial timeout while writing to serial port, trying again.") try: self._serial.write(cmd + '\n') @@ -505,4 +522,3 @@ class MachineCom(object): def getExceptionString(): locationInfo = traceback.extract_tb(sys.exc_info()[2])[0] return "%s: '%s' @ %s:%s:%d" % (str(sys.exc_info()[0].__name__), str(sys.exc_info()[1]), os.path.basename(locationInfo[0]), locationInfo[2], locationInfo[1]) -