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"
15 from Cura.util import machineCom
17 class serialComm(object):
19 The serialComm class is the interface class which handles the communication between stdin/stdout and the machineCom class.
20 This interface class is used to run the (USB) serial communication in a different process then the GUI.
22 def __init__(self, portName):
26 self._comm = machineCom.MachineCom(portName, callbackObject=self)
28 def mcLog(self, message):
29 sys.stdout.write('log:%s\n' % (message))
31 def mcTempUpdate(self, temp, bedTemp, targetTemp, bedTargetTemp):
32 sys.stdout.write('temp:%s:%s:%f:%f\n' % (json.dumps(temp), json.dumps(targetTemp), bedTemp, bedTargetTemp))
34 def mcStateChange(self, state):
35 if self._comm is None:
37 sys.stdout.write('state:%d:%s\n' % (state, self._comm.getStateString()))
39 def mcMessage(self, message):
40 sys.stdout.write('message:%s\n' % (message))
42 def mcProgress(self, lineNr):
43 sys.stdout.write('progress:%d\n' % (lineNr))
45 def mcZChange(self, newZ):
46 sys.stdout.write('changeZ:%d\n' % (newZ))
48 def monitorStdin(self):
49 while not self._comm.isClosed():
50 line = sys.stdin.readline().strip()
51 line = line.split(':', 1)
53 self._comm.cancelPrint()
54 self._gcodeList = ['M110']
56 self._gcodeList.append(line[1])
58 self._comm.sendCommand(line[1])
59 elif line[0] == 'START':
60 self._comm.printGCode(self._gcodeList)
62 sys.stderr.write(str(line))
64 def startMonitor(portName):
65 sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
66 comm = serialComm(portName)
70 if len(sys.argv) != 2:
72 portName = sys.argv[1]
73 startMonitor(portName)
75 if __name__ == '__main__':