2011-06-09 14:43:03 +00:00
|
|
|
#!/usr/bin/env python
|
2012-01-23 11:36:49 +00:00
|
|
|
|
|
|
|
# This file is part of the Printrun suite.
|
2012-08-08 06:39:50 +00:00
|
|
|
#
|
2012-01-23 11:36:49 +00:00
|
|
|
# Printrun is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
2012-08-08 06:39:50 +00:00
|
|
|
#
|
2012-01-23 11:36:49 +00:00
|
|
|
# Printrun is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
2012-08-08 06:39:50 +00:00
|
|
|
#
|
2012-01-23 11:36:49 +00:00
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with Printrun. If not, see <http://www.gnu.org/licenses/>.
|
2011-12-18 13:54:09 +00:00
|
|
|
|
2012-02-25 21:35:48 +00:00
|
|
|
from serial import Serial, SerialException
|
2011-05-10 07:59:28 +00:00
|
|
|
from threading import Thread
|
2011-11-16 04:03:18 +00:00
|
|
|
from select import error as SelectError
|
2011-12-18 13:54:09 +00:00
|
|
|
import time, getopt, sys
|
2012-08-03 21:20:41 +00:00
|
|
|
import platform, os
|
|
|
|
|
|
|
|
def control_ttyhup(port, disable_hup):
|
|
|
|
"""Controls the HUPCL"""
|
|
|
|
if platform.system() == "Linux":
|
|
|
|
if disable_hup:
|
|
|
|
os.system("stty -F %s -hup" % port)
|
|
|
|
else:
|
|
|
|
os.system("stty -F %s hup" % port)
|
|
|
|
|
|
|
|
def enable_hup(port):
|
|
|
|
control_ttyhup(port, False)
|
|
|
|
|
|
|
|
def disable_hup(port):
|
|
|
|
control_ttyhup(port, True)
|
2011-05-23 13:39:24 +00:00
|
|
|
|
2011-05-10 07:59:28 +00:00
|
|
|
class printcore():
|
2012-08-03 21:25:51 +00:00
|
|
|
def __init__(self, port = None, baud = None):
|
2011-05-11 15:28:35 +00:00
|
|
|
"""Initializes a printcore instance. Pass the port and baud rate to connect immediately
|
|
|
|
"""
|
2012-08-03 21:25:51 +00:00
|
|
|
self.baud = None
|
|
|
|
self.port = None
|
|
|
|
self.printer = None #Serial instance connected to the printer, None when disconnected
|
|
|
|
self.clear = 0 #clear to send, enabled after responses
|
|
|
|
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
|
2012-08-08 06:39:50 +00:00
|
|
|
self.mainqueue = []
|
2012-08-03 21:25:51 +00:00
|
|
|
self.priqueue = []
|
|
|
|
self.queueindex = 0
|
|
|
|
self.lineno = 0
|
|
|
|
self.resendfrom = -1
|
|
|
|
self.paused = False
|
|
|
|
self.sentlines = {}
|
|
|
|
self.log = []
|
|
|
|
self.sent = []
|
|
|
|
self.tempcb = None #impl (wholeline)
|
|
|
|
self.recvcb = None #impl (wholeline)
|
|
|
|
self.sendcb = None #impl (wholeline)
|
|
|
|
self.errorcb = None #impl (wholeline)
|
|
|
|
self.startcb = None #impl ()
|
|
|
|
self.endcb = None #impl ()
|
|
|
|
self.onlinecb = None #impl ()
|
|
|
|
self.loud = False #emit sent and received lines to terminal
|
|
|
|
self.greetings = ['start','Grbl ']
|
|
|
|
self.wait = 0 # default wait period for send(), send_now()
|
|
|
|
self.read_thread = None
|
|
|
|
self.stop_read_thread = False
|
2012-08-03 21:43:11 +00:00
|
|
|
self.print_thread = None
|
2011-05-22 18:23:29 +00:00
|
|
|
if port is not None and baud is not None:
|
|
|
|
self.connect(port, baud)
|
2012-08-08 06:39:50 +00:00
|
|
|
|
2011-05-10 07:59:28 +00:00
|
|
|
def disconnect(self):
|
2011-05-11 15:28:35 +00:00
|
|
|
"""Disconnects from printer and pauses the print
|
|
|
|
"""
|
2012-08-02 21:48:40 +00:00
|
|
|
if self.printer:
|
|
|
|
if self.read_thread:
|
|
|
|
self.stop_read_thread = True
|
|
|
|
self.read_thread.join()
|
|
|
|
self.read_thread = None
|
2011-05-10 07:59:28 +00:00
|
|
|
self.printer.close()
|
2012-08-03 21:25:51 +00:00
|
|
|
self.printer = None
|
|
|
|
self.online = False
|
|
|
|
self.printing = False
|
2012-08-08 06:39:50 +00:00
|
|
|
|
2012-08-08 07:38:48 +00:00
|
|
|
def connect(self, port = None, baud = None):
|
2011-05-11 15:28:35 +00:00
|
|
|
"""Set port and baudrate if given, then connect to printer
|
|
|
|
"""
|
2012-08-03 21:25:51 +00:00
|
|
|
if self.printer:
|
2011-05-10 07:59:28 +00:00
|
|
|
self.disconnect()
|
|
|
|
if port is not None:
|
2012-08-03 21:25:51 +00:00
|
|
|
self.port = port
|
2011-05-10 07:59:28 +00:00
|
|
|
if baud is not None:
|
2012-08-03 21:25:51 +00:00
|
|
|
self.baud = baud
|
2011-05-10 07:59:28 +00:00
|
|
|
if self.port is not None and self.baud is not None:
|
2012-08-03 21:20:41 +00:00
|
|
|
disable_hup(self.port)
|
2012-08-06 21:25:37 +00:00
|
|
|
self.printer = Serial(port = self.port, baudrate = self.baud, timeout = 0.25)
|
2012-08-02 21:48:40 +00:00
|
|
|
self.stop_read_thread = False
|
2012-08-08 07:38:48 +00:00
|
|
|
self.read_thread = Thread(target = self._listen)
|
2012-08-02 21:48:40 +00:00
|
|
|
self.read_thread.start()
|
2012-08-08 06:39:50 +00:00
|
|
|
|
2011-06-06 17:46:25 +00:00
|
|
|
def reset(self):
|
|
|
|
"""Reset the printer
|
|
|
|
"""
|
2012-08-02 21:48:40 +00:00
|
|
|
if self.printer:
|
2011-06-06 17:46:25 +00:00
|
|
|
self.printer.setDTR(1)
|
2012-08-03 21:56:52 +00:00
|
|
|
time.sleep(0.2)
|
2011-06-06 17:46:25 +00:00
|
|
|
self.printer.setDTR(0)
|
2012-08-08 06:39:50 +00:00
|
|
|
|
2012-08-03 21:54:35 +00:00
|
|
|
def _readline(self):
|
|
|
|
try:
|
|
|
|
line = self.printer.readline()
|
2012-08-04 08:57:44 +00:00
|
|
|
if len(line) > 1:
|
|
|
|
self.log.append(line)
|
|
|
|
if self.recvcb:
|
|
|
|
try: self.recvcb(line)
|
|
|
|
except: pass
|
|
|
|
if self.loud: print "RECV: ", line.rstrip()
|
2012-08-03 21:54:35 +00:00
|
|
|
return line
|
|
|
|
except SelectError, e:
|
|
|
|
if 'Bad file descriptor' in e.args[1]:
|
|
|
|
print "Can't read from printer (disconnected?)."
|
|
|
|
return None
|
|
|
|
else:
|
|
|
|
raise
|
|
|
|
except SerialException, e:
|
|
|
|
print "Can't read from printer (disconnected?)."
|
|
|
|
return None
|
|
|
|
except OSError, e:
|
|
|
|
print "Can't read from printer (disconnected?)."
|
|
|
|
return None
|
|
|
|
|
2012-08-04 08:57:44 +00:00
|
|
|
def _listen_can_continue(self):
|
|
|
|
return not self.stop_read_thread and self.printer and self.printer.isOpen()
|
|
|
|
|
|
|
|
def _listen_until_online(self):
|
|
|
|
while not self.online and self._listen_can_continue():
|
|
|
|
self._send("M105")
|
2012-08-11 07:33:40 +00:00
|
|
|
empty_lines = 0
|
2012-08-04 08:57:44 +00:00
|
|
|
while self._listen_can_continue():
|
|
|
|
line = self._readline()
|
2012-08-11 07:33:40 +00:00
|
|
|
if line == None: break # connection problem
|
|
|
|
# workaround cases where M105 was sent before printer Serial
|
|
|
|
# was online an empty line means read timeout was reached,
|
|
|
|
# meaning no data was received thus we count those empty lines,
|
|
|
|
# and once we have seen 5 in a row, we just break and send a
|
|
|
|
# new M105
|
|
|
|
if not line: empty_lines += 1
|
|
|
|
else: empty_lines = 0
|
|
|
|
if empty_lines == 5: break
|
2012-08-04 08:57:44 +00:00
|
|
|
if line.startswith(tuple(self.greetings)) or line.startswith('ok'):
|
|
|
|
if self.onlinecb:
|
|
|
|
try: self.onlinecb()
|
|
|
|
except: pass
|
|
|
|
self.online = True
|
|
|
|
return
|
2012-08-06 21:25:37 +00:00
|
|
|
time.sleep(0.25)
|
2012-08-04 08:57:44 +00:00
|
|
|
|
2011-05-10 07:59:28 +00:00
|
|
|
def _listen(self):
|
|
|
|
"""This function acts on messages from the firmware
|
|
|
|
"""
|
2012-08-03 21:54:35 +00:00
|
|
|
self.clear = True
|
|
|
|
if not self.printing:
|
2012-08-06 17:35:58 +00:00
|
|
|
self._listen_until_online()
|
2012-08-04 08:57:44 +00:00
|
|
|
while self._listen_can_continue():
|
2012-08-03 21:54:35 +00:00
|
|
|
line = self._readline()
|
|
|
|
if line == None:
|
2012-03-16 03:37:43 +00:00
|
|
|
break
|
2012-08-03 21:54:35 +00:00
|
|
|
if line.startswith('DEBUG_'):
|
2011-07-12 08:42:00 +00:00
|
|
|
continue
|
2012-08-03 21:54:35 +00:00
|
|
|
if line.startswith(tuple(self.greetings)) or line.startswith('ok'):
|
|
|
|
self.clear = True
|
2012-08-04 08:57:44 +00:00
|
|
|
if line.startswith('ok') and "T:" in line and self.tempcb:
|
|
|
|
#callback for temp, status, whatever
|
2012-08-08 06:39:50 +00:00
|
|
|
try: self.tempcb(line)
|
|
|
|
except: pass
|
2012-08-03 21:54:35 +00:00
|
|
|
elif line.startswith('Error'):
|
2012-08-04 08:57:44 +00:00
|
|
|
if self.errorcb:
|
2012-08-08 06:39:50 +00:00
|
|
|
#callback for errors
|
2012-08-03 21:54:35 +00:00
|
|
|
try: self.errorcb(line)
|
|
|
|
except: pass
|
2012-09-05 07:56:16 +00:00
|
|
|
# Teststrings for resend parsing # Firmware exp. result
|
|
|
|
# line="rs N2 Expected checksum 67" # Teacup 2
|
2011-11-22 20:32:16 +00:00
|
|
|
if line.lower().startswith("resend") or line.startswith("rs"):
|
2012-09-05 07:56:16 +00:00
|
|
|
line = line.replace("N:"," ").replace("N"," ").replace(":"," ")
|
|
|
|
linewords = line.split()
|
|
|
|
while len(linewords) != 0:
|
|
|
|
try:
|
|
|
|
toresend = int(linewords.pop(0))
|
|
|
|
self.resendfrom = toresend
|
|
|
|
#print str(toresend)
|
|
|
|
break
|
|
|
|
except:
|
|
|
|
pass
|
2012-08-03 21:54:35 +00:00
|
|
|
self.clear = True
|
|
|
|
self.clear = True
|
2012-08-08 06:39:50 +00:00
|
|
|
|
2012-08-03 22:02:16 +00:00
|
|
|
def _checksum(self, command):
|
2012-08-08 07:38:48 +00:00
|
|
|
return reduce(lambda x, y:x^y, map(ord, command))
|
2012-08-08 06:39:50 +00:00
|
|
|
|
2012-08-04 21:15:50 +00:00
|
|
|
def startprint(self, data, startindex = 0):
|
2011-05-11 15:28:35 +00:00
|
|
|
"""Start a print, data is an array of gcode commands.
|
|
|
|
returns True on success, False if already printing.
|
|
|
|
The print queue will be replaced with the contents of the data array, the next line will be set to 0 and the firmware notified.
|
|
|
|
Printing will then start in a parallel thread.
|
|
|
|
"""
|
2012-08-03 21:25:51 +00:00
|
|
|
if self.printing or not self.online or not self.printer:
|
2011-05-10 07:59:28 +00:00
|
|
|
return False
|
2012-08-03 22:02:16 +00:00
|
|
|
self.printing = True
|
|
|
|
self.mainqueue = [] + data
|
|
|
|
self.lineno = 0
|
2012-08-04 21:15:50 +00:00
|
|
|
self.queueindex = startindex
|
2012-08-03 22:02:16 +00:00
|
|
|
self.resendfrom = -1
|
|
|
|
self._send("M110", -1, True)
|
|
|
|
if len(data) == 0:
|
2011-05-28 17:08:22 +00:00
|
|
|
return True
|
2012-08-03 22:02:16 +00:00
|
|
|
self.clear = False
|
2012-08-03 21:43:11 +00:00
|
|
|
self.print_thread = Thread(target = self._print)
|
|
|
|
self.print_thread.start()
|
2011-05-10 07:59:28 +00:00
|
|
|
return True
|
2012-08-08 06:39:50 +00:00
|
|
|
|
2011-05-10 07:59:28 +00:00
|
|
|
def pause(self):
|
2011-05-11 15:28:35 +00:00
|
|
|
"""Pauses the print, saving the current position.
|
|
|
|
"""
|
2013-02-17 21:14:02 +00:00
|
|
|
return False if !self.printing
|
2012-08-03 21:26:47 +00:00
|
|
|
self.paused = True
|
|
|
|
self.printing = False
|
2012-08-03 21:43:11 +00:00
|
|
|
self.print_thread.join()
|
|
|
|
self.print_thread = None
|
2012-08-08 06:39:50 +00:00
|
|
|
|
2011-05-10 07:59:28 +00:00
|
|
|
def resume(self):
|
2011-05-11 15:28:35 +00:00
|
|
|
"""Resumes a paused print.
|
|
|
|
"""
|
2013-02-17 21:09:38 +00:00
|
|
|
return False if !self.paused
|
2012-08-03 21:26:47 +00:00
|
|
|
self.paused = False
|
|
|
|
self.printing = True
|
2012-08-03 21:43:11 +00:00
|
|
|
self.print_thread = Thread(target = self._print)
|
|
|
|
self.print_thread.start()
|
2012-08-08 06:39:50 +00:00
|
|
|
|
2012-08-03 21:51:41 +00:00
|
|
|
def send(self, command, wait = 0):
|
2011-05-11 15:28:35 +00:00
|
|
|
"""Adds a command to the checksummed main command queue if printing, or sends the command immediately if not printing
|
|
|
|
"""
|
2012-08-08 06:39:50 +00:00
|
|
|
|
2012-08-03 21:51:41 +00:00
|
|
|
if self.online:
|
|
|
|
if self.printing:
|
|
|
|
self.mainqueue.append(command)
|
2012-06-28 15:23:52 +00:00
|
|
|
else:
|
2012-08-03 21:51:41 +00:00
|
|
|
while self.printer and self.printing and not self.clear:
|
2012-06-28 15:23:52 +00:00
|
|
|
time.sleep(0.001)
|
2012-08-03 21:51:41 +00:00
|
|
|
if wait == 0 and self.wait > 0:
|
2012-06-28 15:23:52 +00:00
|
|
|
wait = self.wait
|
2012-08-03 21:51:41 +00:00
|
|
|
if wait > 0:
|
|
|
|
self.clear = False
|
|
|
|
self._send(command, self.lineno, True)
|
2012-08-04 08:35:56 +00:00
|
|
|
self.lineno += 1
|
2012-08-04 08:49:31 +00:00
|
|
|
while wait > 0 and self.printer and self.printing and not self.clear:
|
2012-06-28 15:23:52 +00:00
|
|
|
time.sleep(0.001)
|
2012-08-03 21:51:41 +00:00
|
|
|
wait -= 1
|
2011-05-11 15:28:35 +00:00
|
|
|
else:
|
2012-06-28 15:23:52 +00:00
|
|
|
print "Not connected to printer."
|
2012-08-08 06:39:50 +00:00
|
|
|
|
2012-08-03 21:51:41 +00:00
|
|
|
def send_now(self, command, wait = 0):
|
2011-05-11 15:28:35 +00:00
|
|
|
"""Sends a command to the printer ahead of the command queue, without a checksum
|
|
|
|
"""
|
2012-08-03 21:51:41 +00:00
|
|
|
if self.online or force:
|
|
|
|
if self.printing:
|
|
|
|
self.priqueue.append(command)
|
2012-06-15 06:41:54 +00:00
|
|
|
else:
|
2012-08-03 21:51:41 +00:00
|
|
|
while self.printer and self.printing and not self.clear:
|
2012-06-15 06:41:54 +00:00
|
|
|
time.sleep(0.001)
|
2012-08-03 21:51:41 +00:00
|
|
|
if wait == 0 and self.wait > 0:
|
2012-06-28 15:09:09 +00:00
|
|
|
wait = self.wait
|
2012-08-03 21:51:41 +00:00
|
|
|
if wait > 0:
|
|
|
|
self.clear = False
|
2012-06-15 06:41:54 +00:00
|
|
|
self._send(command)
|
2012-08-03 21:51:41 +00:00
|
|
|
while (wait > 0) and self.printer and self.printing and not self.clear:
|
2012-06-28 15:09:09 +00:00
|
|
|
time.sleep(0.001)
|
2012-08-03 21:51:41 +00:00
|
|
|
wait -= 1
|
2012-06-15 19:58:03 +00:00
|
|
|
else:
|
2012-06-15 06:41:54 +00:00
|
|
|
print "Not connected to printer."
|
2012-08-08 06:39:50 +00:00
|
|
|
|
2011-05-10 07:59:28 +00:00
|
|
|
def _print(self):
|
2012-08-04 08:48:36 +00:00
|
|
|
if self.startcb:
|
2012-08-03 21:47:58 +00:00
|
|
|
#callback for printing started
|
|
|
|
try: self.startcb()
|
|
|
|
except: pass
|
|
|
|
while self.printing and self.printer and self.online:
|
2011-05-11 15:28:35 +00:00
|
|
|
self._sendnext()
|
2012-08-03 21:47:58 +00:00
|
|
|
self.sentlines = {}
|
|
|
|
self.log = []
|
|
|
|
self.sent = []
|
2012-08-04 08:48:36 +00:00
|
|
|
if self.endcb:
|
2012-08-03 21:47:58 +00:00
|
|
|
#callback for printing done
|
|
|
|
try: self.endcb()
|
|
|
|
except: pass
|
2012-08-08 06:39:50 +00:00
|
|
|
|
2011-05-11 15:28:35 +00:00
|
|
|
def _sendnext(self):
|
2012-08-03 21:47:03 +00:00
|
|
|
if not self.printer:
|
2011-05-10 07:59:28 +00:00
|
|
|
return
|
2012-08-03 21:43:11 +00:00
|
|
|
while self.printer and self.printing and not self.clear:
|
2011-05-22 18:23:29 +00:00
|
|
|
time.sleep(0.001)
|
2012-08-03 21:47:03 +00:00
|
|
|
self.clear = False
|
2011-05-22 18:23:29 +00:00
|
|
|
if not (self.printing and self.printer and self.online):
|
2012-08-03 21:47:03 +00:00
|
|
|
self.clear = True
|
2011-05-22 18:23:29 +00:00
|
|
|
return
|
2012-08-03 21:47:03 +00:00
|
|
|
if self.resendfrom < self.lineno and self.resendfrom > -1:
|
2012-08-08 07:58:09 +00:00
|
|
|
self._send(self.sentlines[self.resendfrom], self.resendfrom, False)
|
2012-08-03 21:47:03 +00:00
|
|
|
self.resendfrom += 1
|
2011-05-22 18:23:29 +00:00
|
|
|
return
|
2012-08-03 21:47:03 +00:00
|
|
|
self.resendfrom = -1
|
2011-05-10 07:59:28 +00:00
|
|
|
for i in self.priqueue[:]:
|
|
|
|
self._send(i)
|
2012-08-03 21:47:03 +00:00
|
|
|
del self.priqueue[0]
|
2011-05-22 18:23:29 +00:00
|
|
|
return
|
2012-08-03 21:47:03 +00:00
|
|
|
if self.printing and self.queueindex < len(self.mainqueue):
|
|
|
|
tline = self.mainqueue[self.queueindex]
|
|
|
|
tline = tline.split(";")[0]
|
|
|
|
if len(tline) > 0:
|
|
|
|
self._send(tline, self.lineno, True)
|
|
|
|
self.lineno += 1
|
2011-05-22 18:23:29 +00:00
|
|
|
else:
|
2012-08-03 21:47:03 +00:00
|
|
|
self.clear = True
|
|
|
|
self.queueindex += 1
|
2011-05-10 07:59:28 +00:00
|
|
|
else:
|
2012-08-03 21:47:03 +00:00
|
|
|
self.printing = False
|
|
|
|
self.clear = True
|
|
|
|
if not self.paused:
|
|
|
|
self.queueindex = 0
|
|
|
|
self.lineno = 0
|
|
|
|
self._send("M110", -1, True)
|
2012-08-08 06:39:50 +00:00
|
|
|
|
2012-08-03 21:47:03 +00:00
|
|
|
def _send(self, command, lineno = 0, calcchecksum = False):
|
|
|
|
if calcchecksum:
|
|
|
|
prefix = "N" + str(lineno) + " " + command
|
|
|
|
command = prefix + "*" + str(self._checksum(prefix))
|
|
|
|
if "M110" not in command:
|
|
|
|
self.sentlines[lineno] = command
|
|
|
|
if self.printer:
|
|
|
|
self.sent.append(command)
|
2011-05-23 13:39:24 +00:00
|
|
|
if self.loud:
|
2012-08-04 08:48:36 +00:00
|
|
|
print "SENT: ", command
|
|
|
|
if self.sendcb:
|
2012-08-03 21:47:03 +00:00
|
|
|
try: self.sendcb(command)
|
|
|
|
except: pass
|
2012-02-25 21:35:48 +00:00
|
|
|
try:
|
|
|
|
self.printer.write(str(command+"\n"))
|
|
|
|
except SerialException, e:
|
|
|
|
print "Can't write to printer (disconnected?)."
|
2011-05-10 07:59:28 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2011-12-18 13:54:09 +00:00
|
|
|
baud = 115200
|
|
|
|
loud = False
|
2012-08-04 08:40:44 +00:00
|
|
|
statusreport = False
|
2011-12-18 13:54:09 +00:00
|
|
|
try:
|
2012-08-04 08:40:44 +00:00
|
|
|
opts, args = getopt.getopt(sys.argv[1:], "h,b:,v,s",
|
|
|
|
["help", "baud", "verbose", "statusreport"])
|
2012-08-04 08:44:32 +00:00
|
|
|
except getopt.GetoptError, err:
|
2012-08-04 08:40:44 +00:00
|
|
|
print str(err)
|
|
|
|
sys.exit(2)
|
|
|
|
for o, a in opts:
|
|
|
|
if o in ('-h', '--help'):
|
|
|
|
# FIXME: Fix help
|
|
|
|
print "Opts are: --help , -b --baud = baudrate, -v --verbose, -s --statusreport"
|
|
|
|
sys.exit(1)
|
|
|
|
if o in ('-b', '--baud'):
|
|
|
|
baud = int(a)
|
|
|
|
if o in ('-v','--verbose'):
|
|
|
|
loud = True
|
2011-12-18 13:54:09 +00:00
|
|
|
elif o in ('-s','--statusreport'):
|
2012-08-04 08:40:44 +00:00
|
|
|
statusreport = True
|
2011-12-18 13:54:09 +00:00
|
|
|
|
2012-08-04 08:40:44 +00:00
|
|
|
if len (args) > 1:
|
|
|
|
port = args[-2]
|
|
|
|
filename = args[-1]
|
|
|
|
print "Printing: %s on %s with baudrate %d" % (filename, port, baud)
|
2011-05-22 20:52:57 +00:00
|
|
|
else:
|
2011-12-18 13:54:09 +00:00
|
|
|
print "Usage: python [-h|-b|-v|-s] printcore.py /dev/tty[USB|ACM]x filename.gcode"
|
2011-12-16 20:46:24 +00:00
|
|
|
sys.exit(2)
|
2012-08-04 08:40:44 +00:00
|
|
|
p = printcore(port, baud)
|
2011-12-18 13:54:09 +00:00
|
|
|
p.loud = loud
|
2011-05-22 18:23:29 +00:00
|
|
|
time.sleep(2)
|
2012-08-08 07:58:09 +00:00
|
|
|
gcode = [i.replace("\n", "") for i in open(filename)]
|
2011-12-18 13:54:09 +00:00
|
|
|
p.startprint(gcode)
|
|
|
|
|
2011-05-22 20:52:57 +00:00
|
|
|
try:
|
2011-05-23 13:39:24 +00:00
|
|
|
if statusreport:
|
2012-08-08 07:38:48 +00:00
|
|
|
p.loud = False
|
2011-05-23 13:39:24 +00:00
|
|
|
sys.stdout.write("Progress: 00.0%")
|
|
|
|
sys.stdout.flush()
|
2012-08-04 08:40:44 +00:00
|
|
|
while p.printing:
|
2011-05-22 20:52:57 +00:00
|
|
|
time.sleep(1)
|
2011-05-23 13:39:24 +00:00
|
|
|
if statusreport:
|
2013-01-13 12:27:14 +00:00
|
|
|
sys.stdout.write("%02.1f%%\r" % (100 * float(p.queueindex) / len(p.mainqueue),) )
|
2011-05-23 13:39:24 +00:00
|
|
|
sys.stdout.flush()
|
2011-12-19 17:39:10 +00:00
|
|
|
p.disconnect()
|
|
|
|
sys.exit(0)
|
2011-05-22 20:52:57 +00:00
|
|
|
except:
|
|
|
|
p.disconnect()
|