chiark / gitweb /
Make error detection less "all inclusive" to fix #690
[cura.git] / Cura / util / machineCom.py
index a39654a240a30d2ec9a88ee9042e699e2bdee0a9..11b4dfca359025d72f4ccc7c333781787ad44f52 100644 (file)
@@ -41,12 +41,12 @@ def serialList(forAutoDetect=False):
        if forAutoDetect:
                baselist = baselist + glob.glob('/dev/ttyUSB*') + glob.glob('/dev/ttyACM*') + glob.glob("/dev/cu.usb*")
                baselist = filter(lambda s: not 'Bluetooth' in s, baselist)
+               prev = profile.getMachineSetting('serial_port_auto')
+               if prev in baselist:
+                       baselist.remove(prev)
+                       baselist.insert(0, prev)
        else:
                baselist = baselist + glob.glob('/dev/ttyUSB*') + glob.glob('/dev/ttyACM*') + glob.glob("/dev/cu.*") + glob.glob("/dev/tty.usb*") + glob.glob("/dev/rfcomm*")
-       prev = profile.getMachineSetting('serial_port_auto')
-       if prev in baselist:
-               baselist.remove(prev)
-               baselist.insert(0, prev)
        if version.isDevVersion() and not forAutoDetect:
                baselist.append('VIRTUAL')
        return baselist
@@ -116,7 +116,7 @@ class VirtualPrinter():
                                return ''
                        if self.readList is None:
                                return ''
-               time.sleep(0.1)
+               time.sleep(0.001)
                #print "Recv: %s" % (self.readList[0].rstrip())
                return self.readList.pop(0)
        
@@ -291,7 +291,7 @@ class MachineCom(object):
                                        self._log("Connecting to: %s" % (p))
                                        programmer.connect(p)
                                        self._serial = programmer.leaveISP()
-                                       profile.putPreference('serial_port_auto', p)
+                                       profile.putMachineSetting('serial_port_auto', p)
                                        break
                                except ispBase.IspError as (e):
                                        self._log("Error while connecting to %s: %s" % (p, str(e)))
@@ -312,7 +312,7 @@ class MachineCom(object):
                                        self._serial = serial.Serial(str(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:
+               if self._serial is None:
                        self._log("Failed to open serial port (%s)" % (self._port))
                        self._errorValue = 'Failed to autodetect serial port.'
                        self._changeState(self.STATE_ERROR)
@@ -334,7 +334,8 @@ class MachineCom(object):
                        if line is None:
                                break
                        
-                       #No matter the state, if we see an error, goto the error state and store the error for reference.
+                       #No matter the state, if we see an fatal error, goto the error state and store the error for reference.
+                       # Only goto error on known fatal errors.
                        if line.startswith('Error:'):
                                #Oh YEAH, consistency.
                                # Marlin reports an MIN/MAX temp error as "Error:x\n: Extruder switched off. MAXTEMP triggered !\n"
@@ -343,11 +344,10 @@ class MachineCom(object):
                                if re.match('Error:[0-9]\n', line):
                                        line = line.rstrip() + self._readline()
                                #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 or 'No Checksum with line number' in line:
-                                       pass
-                               elif not self.isError():
-                                       self._errorValue = line[6:]
-                                       self._changeState(self.STATE_ERROR)
+                               if 'Extruder switched off' in line or 'Temperature heated bed switched off' in line or 'Something is wrong, please turn off the printer.' in line:
+                                       if not self.isError():
+                                               self._errorValue = line[6:]
+                                               self._changeState(self.STATE_ERROR)
                        if ' T:' in line or line.startswith('T:'):
                                self._temp[self._temperatureRequestExtruder] = float(re.search("[0-9\.]*", line.split('T:')[1]).group(0))
                                if ' B:' in line:
@@ -358,7 +358,7 @@ class MachineCom(object):
                                        t = time.time()
                                        self._heatupWaitTimeLost = t - self._heatupWaitStartTime
                                        self._heatupWaitStartTime = t
-                       elif line.strip() != '' and line.strip() != 'ok' and not line.startswith('Resend:') and line != 'echo:Unknown command:""\n' and self.isOperational():
+                       elif line.strip() != '' and line.strip() != 'ok' and not line.startswith('Resend:') and not line.startswith('Error:checksum mismatch') and not line.startswith('Error:Line Number is not Last Line Number+1') and line != 'echo:Unknown command:""\n' and self.isOperational():
                                self._callback.mcMessage(line)
 
                        if self._state == self.STATE_DETECT_BAUDRATE:
@@ -395,12 +395,12 @@ class MachineCom(object):
                                        else:
                                                self._sendCommand("M999")
                                                self._serial.timeout = 2
-                                               profile.putPreference('serial_baud_auto', self._serial.baudrate)
+                                               profile.putMachineSetting('serial_baud_auto', self._serial.baudrate)
                                                self._changeState(self.STATE_OPERATIONAL)
                                else:
                                        self._testingBaudrate = False
                        elif self._state == self.STATE_CONNECTING:
-                               if line == '':
+                               if line == '' or 'wait' in line:        # wait needed for Repetier (kind of watchdog)
                                        self._sendCommand("M105")
                                elif 'ok' in line:
                                        self._changeState(self.STATE_OPERATIONAL)