2 Serial communication with the printer for printing is done from a separate process,
3 this to ensure that the PIL does not block the serial printing.
5 This file is the 2nd process that is started to handle communication with the printer.
6 And handles all communication with the initial process.
9 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
16 from Cura.util import machineCom
18 class serialComm(object):
20 The serialComm class is the interface class which handles the communication between stdin/stdout and the machineCom class.
21 This interface class is used to run the (USB) serial communication in a different process then the GUI.
23 def __init__(self, portName, baudrate):
28 baudrate = int(baudrate)
31 self._comm = machineCom.MachineCom(portName, baudrate, callbackObject=self)
33 def mcLog(self, message):
34 sys.stdout.write('log:%s\n' % (message))
36 def mcTempUpdate(self, temp, bedTemp, targetTemp, bedTargetTemp):
37 sys.stdout.write('temp:%s:%s:%f:%f\n' % (json.dumps(temp), json.dumps(targetTemp), bedTemp, bedTargetTemp))
39 def mcStateChange(self, state):
40 if self._comm is None:
42 sys.stdout.write('state:%d:%s\n' % (state, self._comm.getStateString()))
44 def mcMessage(self, message):
45 sys.stdout.write('message:%s\n' % (message))
47 def mcProgress(self, lineNr):
48 sys.stdout.write('progress:%d\n' % (lineNr))
50 def mcZChange(self, newZ):
53 def monitorStdin(self):
54 while not self._comm.isClosed():
55 line = sys.stdin.readline().strip()
56 line = line.split(':', 1)
58 self._comm.cancelPrint()
59 self._gcodeList = ['M110']
61 self._gcodeList.append(line[1])
63 self._comm.sendCommand(line[1])
64 elif line[0] == 'START':
65 self._comm.printGCode(self._gcodeList)
67 sys.stderr.write(str(line))
69 def startMonitor(portName, baudrate):
70 sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
71 comm = serialComm(portName, baudrate)
72 thread = threading.Thread(target=comm.monitorStdin)
74 while thread.is_alive():
78 if len(sys.argv) != 3:
80 portName, baudrate = sys.argv[1], sys.argv[2]
81 startMonitor(portName, baudrate)
83 if __name__ == '__main__':