Try to remove timing issues when preparing next line to send

master
Gina Häußge 2013-05-23 22:37:02 +02:00
parent 245d9651b6
commit da90b2d738
1 changed files with 29 additions and 27 deletions

View File

@ -205,6 +205,7 @@ class MachineCom(object):
self._resendDelta = None self._resendDelta = None
self._lastLines = [] self._lastLines = []
self._sendNextLock = threading.Lock()
self._sendingLock = threading.Lock() self._sendingLock = threading.Lock()
self.thread = threading.Thread(target=self._monitor) self.thread = threading.Thread(target=self._monitor)
@ -644,31 +645,32 @@ class MachineCom(object):
self.close(True) self.close(True)
def _sendNext(self): def _sendNext(self):
if self._gcodePos >= len(self._gcodeList): with self._sendNextLock:
self._changeState(self.STATE_OPERATIONAL) if self._gcodePos >= len(self._gcodeList):
return self._changeState(self.STATE_OPERATIONAL)
if self._gcodePos == 100: return
self._printStartTime100 = time.time() if self._gcodePos == 100:
line = self._gcodeList[self._gcodePos] self._printStartTime100 = time.time()
if type(line) is tuple: line = self._gcodeList[self._gcodePos]
self._printSection = line[1] if type(line) is tuple:
line = line[0] self._printSection = line[1]
try: line = line[0]
if line == 'M0' or line == 'M1': try:
self.setPause(True) if line == 'M0' or line == 'M1':
line = 'M105' #Don't send the M0 or M1 to the machine, as M0 and M1 are handled as an LCD menu pause. self.setPause(True)
if self._printSection in self._feedRateModifier: line = 'M105' #Don't send the M0 or M1 to the machine, as M0 and M1 are handled as an LCD menu pause.
line = re.sub('F([0-9]*)', lambda m: 'F' + str(int(int(m.group(1)) * self._feedRateModifier[self._printSection])), line) if self._printSection in self._feedRateModifier:
if ('G0' in line or 'G1' in line) and 'Z' in line: line = re.sub('F([0-9]*)', lambda m: 'F' + str(int(int(m.group(1)) * self._feedRateModifier[self._printSection])), line)
z = float(re.search('Z([0-9\.]*)', line).group(1)) if ('G0' in line or 'G1' in line) and 'Z' in line:
if self._currentZ != z: z = float(re.search('Z([0-9\.]*)', line).group(1))
self._currentZ = z if self._currentZ != z:
self._callback.mcZChange(z) self._currentZ = z
except: self._callback.mcZChange(z)
self._log("Unexpected error: %s" % (getExceptionString())) except:
self._sendCommand(line, True) self._log("Unexpected error: %s" % (getExceptionString()))
self._gcodePos += 1 self._sendCommand(line, True)
self._callback.mcProgress(self._gcodePos) self._gcodePos += 1
self._callback.mcProgress(self._gcodePos)
def sendCommand(self, cmd): def sendCommand(self, cmd):
cmd = cmd.encode('ascii', 'replace') cmd = cmd.encode('ascii', 'replace')
@ -686,8 +688,8 @@ class MachineCom(object):
self._printSection = 'CUSTOM' self._printSection = 'CUSTOM'
self._changeState(self.STATE_PRINTING) self._changeState(self.STATE_PRINTING)
self._printStartTime = time.time() self._printStartTime = time.time()
for i in xrange(0, 6): #for i in xrange(0, 6):
self._sendNext() self._sendNext()
def cancelPrint(self): def cancelPrint(self):
if self.isOperational(): if self.isOperational():