From 2aa03de4ea55110d3cef30ee2d39201b8cc48707 Mon Sep 17 00:00:00 2001 From: Justin Nesselrotte Date: Sat, 20 Dec 2014 14:01:11 -0600 Subject: [PATCH] Modifying serial communication to use a thread 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 | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Cura/serialCommunication.py b/Cura/serialCommunication.py index c1ec18dc..cf6a0aec 100644 --- a/Cura/serialCommunication.py +++ b/Cura/serialCommunication.py @@ -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: -- 2.30.2