From 28efc5a0b63d338bd976306460d7f6324fc0d1fb Mon Sep 17 00:00:00 2001 From: daid Date: Thu, 22 Aug 2013 16:44:45 +0200 Subject: [PATCH] Try to implement the TCGETS2 patch for linux to workaround the pyserial problem for 250000 baud. --- Cura/util/machineCom.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/Cura/util/machineCom.py b/Cura/util/machineCom.py index 045aed85..db9ed8c6 100644 --- a/Cura/util/machineCom.py +++ b/Cura/util/machineCom.py @@ -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: -- 2.30.2