chiark / gitweb /
Modifying serial communication to use a thread
authorJustin Nesselrotte <jnesselr@harding.edu>
Sat, 20 Dec 2014 20:01:11 +0000 (14:01 -0600)
committerJustin Nesselrotte <jnesselr@harding.edu>
Sat, 20 Dec 2014 20:01:11 +0000 (14:01 -0600)
This helps with the application not responding, with closing the
application without an error (Since it now seems to free the serial
port correctly), and with overall startup cost for the connecting
process.

Cura/serialCommunication.py

index c1ec18dc5e6c4fc0234bd5fe7ce443b1f9f8317f..cf6a0aec0079f8120f7c63ca650f46994dab46e0 100644 (file)
@@ -8,6 +8,7 @@ And handles all communication with the initial process.
 
 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
 import sys
+import threading
 import time
 import os
 import json
@@ -46,8 +47,8 @@ class serialComm(object):
        def mcProgress(self, lineNr):
                sys.stdout.write('progress:%d\n' % (lineNr))
 
-       #def mcZChange(self, newZ):
-       #       sys.stdout.write('changeZ:%d\n' % (newZ))
+       def mcZChange(self, newZ):
+               pass
 
        def monitorStdin(self):
                while not self._comm.isClosed():
@@ -68,7 +69,10 @@ class serialComm(object):
 def startMonitor(portName, baudrate):
        sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
        comm = serialComm(portName, baudrate)
-       comm.monitorStdin()
+       thread = threading.Thread(target=comm.monitorStdin)
+       thread.start()
+       while thread.is_alive():
+               time.sleep(0)
 
 def main():
        if len(sys.argv) != 3: