chiark / gitweb /
Fixed #779 - Code was always defaulting to auto-detect baudrate.
authordaid <daid303@gmail.com>
Tue, 11 Mar 2014 08:01:35 +0000 (09:01 +0100)
committerdaid <daid303@gmail.com>
Tue, 11 Mar 2014 08:01:35 +0000 (09:01 +0100)
Cura/serialCommunication.py
Cura/util/machineCom.py
Cura/util/printerConnection/serialConnection.py

index 7447f83afd163e87389f768a6d1d7e7a1f3ce711..e94574d174679828dec2b23ea4a1ab7c99e6dbe8 100644 (file)
@@ -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()
index b0cac8bb8a5b75895da6a47dc5f07747d38a89f0..13b94f5087e5879db54830fb4966f493e4b59e8a 100644 (file)
@@ -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)
index 88e3047afda447c0d596e936a213dd88ec35f47f..721b772558e8ccfd5c609f5c74d2be266050cfd5 100644 (file)
@@ -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