X-Git-Url: http://git.hcoop.net/clinton/Smoothieware.git/blobdiff_plain/faffe1c2c449e9d429a12d40b97d689a0e4abbe1..54f0098a4f3c67440d5273da31acb4a376e18d6f:/fast-stream.py diff --git a/fast-stream.py b/fast-stream.py index b71bfd68..8eeb08d0 100644 --- a/fast-stream.py +++ b/fast-stream.py @@ -2,7 +2,7 @@ """\ Stream g-code to Smoothie USB serial connection -Based on GRBL stream.py +Based on GRBL stream.py, but completely different """ from __future__ import print_function @@ -11,6 +11,18 @@ import argparse import serial import threading import time +import signal +import sys + +errorflg= False +intrflg= False + +def signal_term_handler(signal, frame): + global intrflg + print('got SIGTERM...') + intrflg= True + +signal.signal(signal.SIGTERM, signal_term_handler) # Define command line argument interface parser = argparse.ArgumentParser(description='Stream g-code file to Smoothie over telnet.') @@ -39,13 +51,16 @@ okcnt= 0 def read_thread(): """thread worker function""" - global okcnt + global okcnt, errorflg flag= 1 while flag : rep= s.readline() n= rep.count("ok") if n == 0 : print("Incoming: " + rep) + if "error" in rep or "!!" in rep or "ALARM" in rep or "ERROR" in rep: + errorflg= True + break else : okcnt += n @@ -58,29 +73,43 @@ t.daemon = True t.start() linecnt= 0 -for line in f: - # strip comments - if line.startswith(';') : - continue - l= line.strip() - s.write(l + '\n') - linecnt+=1 - if verbose: print("SND " + str(linecnt) + ": " + line.strip() + " - " + str(okcnt)) - -print("Waiting for complete...") - -while okcnt < linecnt: - if verbose: print(str(linecnt) + " - " + str(okcnt) ) - time.sleep(1) +try: + for line in f: + if errorflg : + break + # strip comments + if line.startswith(';') : + continue + l= line.strip() + s.write(l + '\n') + linecnt+=1 + if verbose: print("SND " + str(linecnt) + ": " + line.strip() + " - " + str(okcnt)) + +except KeyboardInterrupt: + print("Interrupted...") + intrflg= True + +if intrflg : + # We need to consume oks otherwise smoothie will deadlock on a full tx buffer + print("Sending Abort - this may take a while...") + s.write('\x18') # send halt + +if errorflg : + print("Target halted due to errors") + +else : + print("Waiting for complete...") + while okcnt < linecnt : + if verbose: print(str(linecnt) + " - " + str(okcnt) ) + if errorflg : + s.read(s.inWaiting()) # rad all remaining characters + break + time.sleep(1) + + # Wait here until finished to close serial port and file. + raw_input(" Press to exit") -# Wait here until grbl is finished to close serial port and file. -raw_input(" Press to exit") # Close file and serial port f.close() s.close() - -print("Done") - - -