3 Stream g-code to Smoothie USB serial connection
5 Based on GRBL stream.py, but completely different
8 from __future__
import print_function
20 def signal_term_handler(signal
, frame
):
22 print('got SIGTERM...')
25 signal
.signal(signal
.SIGTERM
, signal_term_handler
)
27 # Define command line argument interface
28 parser
= argparse
.ArgumentParser(description
='Stream g-code file to Smoothie over telnet.')
29 parser
.add_argument('gcode_file', type=argparse
.FileType('r'),
30 help='g-code filename to be streamed')
31 parser
.add_argument('device',
32 help='Smoothie Serial Device')
33 parser
.add_argument('-q','--quiet',action
='store_true', default
=False,
34 help='suppress output text')
35 args
= parser
.parse_args()
38 verbose
= not args
.quiet
40 # Stream g-code to Smoothie
45 s
= serial
.Serial(dev
, 115200)
46 s
.flushInput() # Flush startup text in serial input
48 print("Streaming " + args
.gcode_file
.name
+ " to " + args
.device
)
53 """thread worker function"""
54 global okcnt
, errorflg
60 print("Incoming: " + rep
)
61 if "error" in rep
or "!!" in rep
or "ALARM" in rep
or "ERROR" in rep
:
67 print("Read thread exited")
71 t
= threading
.Thread(target
=read_thread
)
81 if line
.startswith(';') :
86 if verbose
: print("SND " + str(linecnt
) + ": " + line
.strip() + " - " + str(okcnt
))
88 except KeyboardInterrupt:
89 print("Interrupted...")
93 # We need to consume oks otherwise smoothie will deadlock on a full tx buffer
94 print("Sending Abort - this may take a while...")
95 s
.write('\x18') # send halt
98 print("Target halted due to errors")
101 print("Waiting for complete...")
102 while okcnt
< linecnt
:
103 if verbose
: print(str(linecnt
) + " - " + str(okcnt
) )
105 s
.read(s
.inWaiting()) # rad all remaining characters
109 # Wait here until finished to close serial port and file.
110 raw_input(" Press <Enter> to exit")
113 # Close file and serial port