From 23b0726eb65d33b8aca64df20cd204c91908f086 Mon Sep 17 00:00:00 2001 From: daid Date: Tue, 11 Mar 2014 09:01:35 +0100 Subject: [PATCH] Fixed #779 - Code was always defaulting to auto-detect baudrate. --- Cura/serialCommunication.py | 18 +++++++++------ Cura/util/machineCom.py | 23 +++---------------- .../printerConnection/serialConnection.py | 2 +- 3 files changed, 15 insertions(+), 28 deletions(-) diff --git a/Cura/serialCommunication.py b/Cura/serialCommunication.py index 7447f83a..e94574d1 100644 --- a/Cura/serialCommunication.py +++ b/Cura/serialCommunication.py @@ -19,11 +19,15 @@ class serialComm(object): The serialComm class is the interface class which handles the communication between stdin/stdout and the machineCom class. This interface class is used to run the (USB) serial communication in a different process then the GUI. """ - def __init__(self, portName): + def __init__(self, portName, baudrate): self._comm = None self._gcodeList = [] - self._comm = machineCom.MachineCom(portName, callbackObject=self) + try: + baudrate = int(baudrate) + except ValueError: + baudrate = 0 + self._comm = machineCom.MachineCom(portName, baudrate, callbackObject=self) def mcLog(self, message): sys.stdout.write('log:%s\n' % (message)) @@ -61,16 +65,16 @@ class serialComm(object): else: sys.stderr.write(str(line)) -def startMonitor(portName): +def startMonitor(portName, baudrate): sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0) - comm = serialComm(portName) + comm = serialComm(portName, baudrate) comm.monitorStdin() def main(): - if len(sys.argv) != 2: + if len(sys.argv) != 3: return - portName = sys.argv[1] - startMonitor(portName) + portName, baudrate = sys.argv[1], sys.argv[2] + startMonitor(portName, baudrate) if __name__ == '__main__': main() diff --git a/Cura/util/machineCom.py b/Cura/util/machineCom.py index b0cac8bb..13b94f50 100644 --- a/Cura/util/machineCom.py +++ b/Cura/util/machineCom.py @@ -492,27 +492,10 @@ class MachineCom(object): 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: + try: self._serial.baudrate = baudrate + except: + print getExceptionString() def _log(self, message): self._callback.mcLog(message) diff --git a/Cura/util/printerConnection/serialConnection.py b/Cura/util/printerConnection/serialConnection.py index 88e3047a..721b7725 100644 --- a/Cura/util/printerConnection/serialConnection.py +++ b/Cura/util/printerConnection/serialConnection.py @@ -180,7 +180,7 @@ class serialConnection(printerConnectionBase.printerConnectionBase): cmdList = [os.path.join(os.path.dirname(sys.executable), 'Cura'), '--serialCommunication'] else: cmdList = [sys.executable, '-m', 'Cura.serialCommunication'] - cmdList += [self._portName] + cmdList += [self._portName, profile.getMachineSetting('serial_baud')] if platform.system() == "Darwin": if platform.machine() == 'i386': cmdList = ['arch', '-i386'] + cmdList -- 2.30.2