3 Stream g-code to Smoothie telnet connection
5 Based on GRBL stream.py
8 from __future__
import print_function
14 def write_raw_sequence(tn
, seq
):
15 sock
= tn
.get_socket()
19 # Define command line argument interface
20 parser
= argparse
.ArgumentParser(description
='Stream g-code file to Smoothie over telnet.')
21 parser
.add_argument('gcode_file', type=argparse
.FileType('r'),
22 help='g-code filename to be streamed')
23 parser
.add_argument('ipaddr',
24 help='Smoothie IP address')
25 parser
.add_argument('-q','--quiet',action
='store_true', default
=False,
26 help='suppress output text')
27 parser
.add_argument('-l','--log',action
='store_true', default
=False,
28 help='suppress output text and output to file (gcode file with .log appended)')
29 args
= parser
.parse_args()
32 verbose
= not (args
.quiet
or args
.log
)
34 # Stream g-code to Smoothie
35 print("Streaming " + args
.gcode_file
.name
+ " to " + args
.ipaddr
)
38 outlog
= open(args
.gcode_file
.name
+ ".log", 'w')
40 tn
= telnetlib
.Telnet(args
.ipaddr
)
42 #write_raw_sequence(tn, telnetlib.IAC + telnetlib.DO + "\x55")
45 tn
.read_until("Smoothie command shell")
53 okcnt
+= rep
.count("ok")
54 if verbose
: print("SND " + str(linecnt
) + ": " + line
.strip() + " - " + str(okcnt
))
55 if args
.log
: outlog
.write("SND " + str(linecnt
) + ": " + line
.strip() + " - " + str(okcnt
) + "\n" )
56 print("Waiting for complete...")
58 while okcnt
< linecnt
:
60 okcnt
+= rep
.count("ok")
61 if verbose
: print(str(linecnt
) + " - " + str(okcnt
) )
62 if args
.log
: outlog
.write(str(linecnt
) + " - " + str(okcnt
) + "\n" )
65 if args
.log
: outlog
.close()