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):
18 def __init__(self, portName):
22 self._comm = machineCom.MachineCom(portName, callbackObject=self)
24 def mcLog(self, message):
25 sys.stdout.write('log:%s\n' % (message))
27 def mcTempUpdate(self, temp, bedTemp, targetTemp, bedTargetTemp):
28 sys.stdout.write('temp:%s\n' % json.dumps(temp))
30 def mcStateChange(self, state):
31 if self._comm is None:
33 sys.stdout.write('state:%d:%s\n' % (state, self._comm.getStateString()))
35 def mcMessage(self, message):
36 sys.stdout.write('message:%s\n' % (message))
38 def mcProgress(self, lineNr):
39 sys.stdout.write('progress:%d\n' % (lineNr))
41 def mcZChange(self, newZ):
42 sys.stdout.write('changeZ:%d\n' % (newZ))
44 def monitorStdin(self):
45 while not self._comm.isClosed():
46 line = sys.stdin.readline().strip()
47 line = line.split(':', 1)
49 self._comm.cancelPrint()
50 self._gcodeList = ['M110']
52 self._gcodeList.append(line[1])
53 elif line[0] == 'START':
54 self._comm.printGCode(self._gcodeList)
56 sys.stderr.write(str(line))
59 if len(sys.argv) != 2:
61 sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
62 portName = sys.argv[1]
63 comm = serialComm(portName)
66 if __name__ == '__main__':