import subprocess
import json
+from Cura.util import profile
from Cura.util import machineCom
from Cura.util.printerConnection import printerConnectionBase
self._connectionMap = {}
def getAvailableConnections(self):
- serialList = machineCom.serialList(True)
- for port in machineCom.serialList(True):
+ if profile.getMachineSetting('serial_port') == 'AUTO':
+ serialList = machineCom.serialList(True)
+ else:
+ serialList = [profile.getMachineSetting('serial_port')]
+ for port in serialList:
if port not in self._connectionMap:
self._connectionMap[port] = serialConnection(port)
for key in self._connectionMap.keys():
self._commState = None
self._commStateString = None
self._gcodeData = []
+ self._printProgress = 0
+ self._ZPosition = 0
#Load the data into memory for printing, returns True on success
def loadGCodeData(self, dataStream):
self._process.stdin.write('G:%s\n' % (line))
self._process.stdin.write('START\n')
self._printProgress = 0
+ self._ZPosition = 0
+
+ def coolDown(self):
+ cooldown_toolhead = "M104 S0"
+ for i in range(0,3):
+ change_toolhead = "T%d".format(i)
+ self.sendCommand(change_toolhead)
+ self.sendCommand(cooldown_toolhead)
+ self.sendCommand("M140 S0") #Bed
+
+ def disableSteppers(self):
+ self.sendCommand("M18")
#Abort the previously loaded print file
def cancelPrint(self):
- if not self.isPrinting()or self._process is None:
+ if (not self.isPrinting() and not self.isPaused()) or \
+ self._process is None:
return
self._process.stdin.write('STOP\n')
self._printProgress = 0
+ self.coolDown()
+ self.disableSteppers()
def isPrinting(self):
return self._commState == machineCom.MachineCom.STATE_PRINTING
+ #Returns true if we have the ability to pause the file printing.
+ def hasPause(self):
+ return True
+
+ def isPaused(self):
+ return self._commState == machineCom.MachineCom.STATE_PAUSED
+
+ #Pause or unpause the printing depending on the value, if supported.
+ def pause(self, value):
+ if not (self.isPrinting() or self.isPaused()) or self._process is None:
+ return
+ if value:
+ self._process.stdin.write("PAUSE\n")
+ else:
+ self._process.stdin.write("RESUME\n")
+
#Amount of progression of the current print file. 0.0 to 1.0
def getPrintProgress(self):
- if len(self._gcodeData) < 1:
- return 0.0
- return float(self._printProgress) / float(len(self._gcodeData))
+ return (self._printProgress, len(self._gcodeData), self._ZPosition)
# Return if the printer with this connection type is available
def isAvailable(self):
def _serialCommunicationThread(self):
if platform.system() == "Darwin" and hasattr(sys, 'frozen'):
cmdList = [os.path.join(os.path.dirname(sys.executable), 'Cura'), '--serialCommunication']
+ cmdList += [self._portName + ':' + profile.getMachineSetting('serial_baud')]
else:
cmdList = [sys.executable, '-m', 'Cura.serialCommunication']
- cmdList += [self._portName]
+ cmdList += [self._portName, profile.getMachineSetting('serial_baud')]
if platform.system() == "Darwin":
if platform.machine() == 'i386':
cmdList = ['arch', '-i386'] + cmdList
line = line[1].split(':', 1)
self._commState = int(line[0])
self._commStateString = line[1]
- self._doCallback()
+ self._doCallback('')
elif line[0] == 'progress':
self._printProgress = int(line[1])
self._doCallback()
+ elif line[0] == 'changeZ':
+ self._ZPosition = float(line[1])
+ self._doCallback()
else:
print line
line = self._process.stdout.readline()