chiark / gitweb /
Try to implement the TCGETS2 patch for linux to workaround the pyserial problem for...
authordaid <daid303@gmail.com>
Thu, 22 Aug 2013 14:44:45 +0000 (16:44 +0200)
committerdaid <daid303@gmail.com>
Thu, 22 Aug 2013 14:44:45 +0000 (16:44 +0200)
Cura/util/machineCom.py

index 045aed8589405647c2582abb2d1d7271277668ff..db9ed8c6ebf6e53b64d1dcab3d4a2fad91372d95 100644 (file)
@@ -376,7 +376,7 @@ class MachineCom(object):
                                        else:
                                                baudrate = self._baudrateDetectList.pop(0)
                                                try:
-                                                       self._serial.baudrate = baudrate
+                                                       self._setBaudrate(baudrate)
                                                        self._serial.timeout = 0.5
                                                        self._log("Trying baudrate: %d" % (baudrate))
                                                        self._baudrateDetectRetry = 5
@@ -440,7 +440,30 @@ class MachineCom(object):
                                                if "rs" in line:
                                                        self._gcodePos = int(line.split()[1])
                self._log("Connection closed, closing down monitor")
-       
+
+       def _setBaudrate(self, baudrate):
+               #For linux the pyserial implementation lacks TCGETS2 support. So do that ourselves
+               if sys.platform.startswith('linux'):
+                       try:
+                               self._serial.baudrate = baudrate
+                       except:
+                               try:
+                                       # set custom speed
+                                       import fcntl, array, termios
+                                       TCGETS2 = 0x802C542A
+                                       TCSETS2 = 0x402C542B
+                                       BOTHER = 0o010000
+                                       buf = array.array('i', [0] * 64)
+                                       fcntl.ioctl(self._serial.fd, TCGETS2, buf)
+                                       buf[2] &= ~termios.CBAUD
+                                       buf[2] |= BOTHER
+                                       buf[9] = buf[10] = baudrate
+                                       fcntl.ioctl(self._serial.fd, TCSETS2, buf)
+                               except:
+                                       print getExceptionString()
+               else:
+                       self._serial.baudrate = baudrate
+
        def _log(self, message):
                self._callback.mcLog(message)
                try: