1 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
3 # Serial communication with the printer for printing is done from a separate process,
4 # this to ensure that the PIL does not block the serial printing.
11 from Cura.util import machineCom
13 class serialComm(object):
14 def __init__(self, portName):
18 self._comm = machineCom.MachineCom(portName, callbackObject=self)
20 def mcLog(self, message):
21 sys.stdout.write('log:%s\n' % (message))
23 def mcTempUpdate(self, temp, bedTemp, targetTemp, bedTargetTemp):
24 sys.stdout.write('temp:%s\n' % json.dumps(temp))
26 def mcStateChange(self, state):
27 if self._comm is None:
29 sys.stdout.write('state:%d:%s\n' % (state, self._comm.getStateString()))
31 def mcMessage(self, message):
32 sys.stdout.write('message:%s\n' % (message))
34 def mcProgress(self, lineNr):
35 sys.stdout.write('progress:%d\n' % (lineNr))
37 def mcZChange(self, newZ):
38 sys.stdout.write('changeZ:%d\n' % (newZ))
40 def monitorStdin(self):
41 while not self._comm.isClosed():
42 line = sys.stdin.readline().strip()
43 line = line.split(':', 1)
45 self._comm.cancelPrint()
46 self._gcodeList = ['M110']
48 self._gcodeList.append(line[1])
49 elif line[0] == 'START':
50 self._comm.printGCode(self._gcodeList)
52 sys.stderr.write(str(line))
55 if len(sys.argv) != 2:
57 sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
58 portName = sys.argv[1]
59 comm = serialComm(portName)
62 if __name__ == '__main__':