Add quiet option if statusrepor=True.

master
kliment 2011-05-23 15:39:24 +02:00
parent 5161eb1ae5
commit 7113ab99fb
1 changed files with 20 additions and 10 deletions

View File

@ -3,26 +3,26 @@ from serial import Serial
from threading import Thread from threading import Thread
import time import time
import getopt, sys import getopt, sys
loud=False
class printcore(): class printcore():
def __init__(self,port=None,baud=None): def __init__(self,port=None,baud=None):
"""Initializes a printcore instance. Pass the port and baud rate to connect immediately """Initializes a printcore instance. Pass the port and baud rate to connect immediately
""" """
self.baud=None self.baud=None
self.port=None self.port=None
self.printer=None self.printer=None #Serial instance connected to the printer, None when disconnected
self.clear=0 self.clear=0 #clear to send, enabled after responses
self.mainqueue=[] self.online=False #The printer has responded to the initial command and is active
self.printing=False #is a print currently running, true if printing, false if paused
self.mainqueue=[]
self.priqueue=[] self.priqueue=[]
self.readthread=None
self.queueindex=0 self.queueindex=0
self.lineno=0 self.lineno=0
self.resendfrom=-1 self.resendfrom=-1
self.online=False
self.printing=False
self.sentlines={} self.sentlines={}
self.log=[] self.log=[]
self.sent=[] self.sent=[]
self.loud=False#emit sent and received lines to terminal
if port is not None and baud is not None: if port is not None and baud is not None:
#print port, baud #print port, baud
self.connect(port, baud) self.connect(port, baud)
@ -63,7 +63,7 @@ class printcore():
line=self.printer.readline() line=self.printer.readline()
if(len(line)>1): if(len(line)>1):
self.log+=[line] self.log+=[line]
if loud: if self.loud:
print "RECV: ",line print "RECV: ",line
if(line.startswith('start')): if(line.startswith('start')):
self.clear=True self.clear=True
@ -186,7 +186,8 @@ class printcore():
self.sentlines[lineno]=command self.sentlines[lineno]=command
if(self.printer): if(self.printer):
self.sent+=[command] self.sent+=[command]
print "SENT: ",command if self.loud:
print "SENT: ",command
self.printer.write(command+"\n") self.printer.write(command+"\n")
if __name__ == '__main__': if __name__ == '__main__':
@ -197,8 +198,10 @@ if __name__ == '__main__':
print "Printing: "+filename print "Printing: "+filename
else: else:
print "Usage: python printcore.py filename.gcode" print "Usage: python printcore.py filename.gcode"
loud=True #sys.exit(2)
p=printcore('/dev/ttyUSB0',115200) p=printcore('/dev/ttyUSB0',115200)
p.loud=True
statusreport=False
time.sleep(2) time.sleep(2)
testdata=[i.replace("\n","") for i in open(filename)] testdata=[i.replace("\n","") for i in open(filename)]
p.startprint(testdata) p.startprint(testdata)
@ -208,7 +211,14 @@ if __name__ == '__main__':
#time.sleep(5) #time.sleep(5)
#p.resume() #p.resume()
try: try:
if statusreport:
p.loud=False
sys.stdout.write("Progress: 00.0%")
sys.stdout.flush()
while(p.printing): while(p.printing):
time.sleep(1) time.sleep(1)
if statusreport:
sys.stdout.write("\b\b\b\b%02.1f%%" % (100*float(p.queueindex)/len(p.mainqueue),) )
sys.stdout.flush()
except: except:
p.disconnect() p.disconnect()