master
Guillaume Seguin 2012-08-03 23:47:03 +02:00
parent 898a43e5e5
commit 6a006d785f
1 changed files with 31 additions and 33 deletions

View File

@ -292,55 +292,53 @@ class printcore():
#callback for printing done #callback for printing done
def _sendnext(self): def _sendnext(self):
if(not self.printer): if not self.printer:
return return
while self.printer and self.printing and not self.clear: while self.printer and self.printing and not self.clear:
time.sleep(0.001) time.sleep(0.001)
self.clear=False self.clear = False
if not (self.printing and self.printer and self.online): if not (self.printing and self.printer and self.online):
self.clear=True self.clear = True
return return
if(self.resendfrom<self.lineno and self.resendfrom>-1): if self.resendfrom < self.lineno and self.resendfrom > -1:
self._send(self.sentlines[self.resendfrom],self.resendfrom,False) self._send(self.sentlines[self.resendfrom],self.resendfrom,False)
self.resendfrom+=1 self.resendfrom += 1
return return
self.resendfrom=-1 self.resendfrom = -1
for i in self.priqueue[:]: for i in self.priqueue[:]:
self._send(i) self._send(i)
del(self.priqueue[0]) del self.priqueue[0]
return return
if(self.printing and self.queueindex<len(self.mainqueue)): if self.printing and self.queueindex < len(self.mainqueue):
tline=self.mainqueue[self.queueindex] tline = self.mainqueue[self.queueindex]
tline=tline.split(";")[0] tline = tline.split(";")[0]
if(len(tline)>0): if len(tline) > 0:
self._send(tline,self.lineno,True) self._send(tline, self.lineno, True)
self.lineno+=1 self.lineno += 1
else: else:
self.clear=True self.clear = True
self.queueindex+=1 self.queueindex += 1
else: else:
self.printing=False self.printing = False
self.clear=True self.clear = True
if(not self.paused): if not self.paused:
self.queueindex=0 self.queueindex = 0
self.lineno=0 self.lineno = 0
self._send("M110",-1, True) self._send("M110", -1, True)
def _send(self, command, lineno=0, calcchecksum=False): def _send(self, command, lineno = 0, calcchecksum = False):
if(calcchecksum): if calcchecksum:
prefix="N"+str(lineno)+" "+command prefix = "N" + str(lineno) + " " + command
command=prefix+"*"+str(self._checksum(prefix)) command = prefix + "*" + str(self._checksum(prefix))
if("M110" not in command): if "M110" not in command:
self.sentlines[lineno]=command self.sentlines[lineno] = command
if(self.printer): if self.printer:
self.sent+=[command] self.sent.append(command)
if self.loud: if self.loud:
print "SENT: ",command print "SENT: ",command
if self.sendcb is not None: if self.sendcb is not None:
try: try: self.sendcb(command)
self.sendcb(command) except: pass
except:
pass
try: try:
self.printer.write(str(command+"\n")) self.printer.write(str(command+"\n"))
except SerialException, e: except SerialException, e: