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, baudrate):
27 baudrate = int(baudrate)
30 self._comm = machineCom.MachineCom(portName, baudrate, callbackObject=self)
32 def mcLog(self, message):
33 sys.stdout.write('log:%s\n' % (message))
35 def mcTempUpdate(self, temp, bedTemp, targetTemp, bedTargetTemp):
36 sys.stdout.write('temp:%s:%s:%f:%f\n' % (json.dumps(temp), json.dumps(targetTemp), bedTemp, bedTargetTemp))
38 def mcStateChange(self, state):
39 if self._comm is None:
41 sys.stdout.write('state:%d:%s\n' % (state, self._comm.getStateString()))
43 def mcMessage(self, message):
44 sys.stdout.write('message:%s\n' % (message))
46 def mcProgress(self, lineNr):
47 sys.stdout.write('progress:%d\n' % (lineNr))
49 def mcZChange(self, newZ):
50 sys.stdout.write('changeZ:%d\n' % (newZ))
52 def monitorStdin(self):
53 while not self._comm.isClosed():
54 line = sys.stdin.readline().strip()
55 line = line.split(':', 1)
57 self._comm.cancelPrint()
58 self._gcodeList = ['M110']
60 self._gcodeList.append(line[1])
62 self._comm.sendCommand(line[1])
63 elif line[0] == 'START':
64 self._comm.printGCode(self._gcodeList)
66 sys.stderr.write(str(line))
68 def startMonitor(portName, baudrate):
69 sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
70 comm = serialComm(portName, baudrate)
74 if len(sys.argv) != 3:
76 portName, baudrate = sys.argv[1], sys.argv[2]
77 startMonitor(portName, baudrate)
79 if __name__ == '__main__':