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 parser
.add_argument('-c','--comment',action
='store_true', default
=False,
30 help='Send gcode comments to printer (text after ;)')
31 args
= parser
.parse_args()
34 verbose
= not (args
.quiet
or args
.log
)
36 # Stream g-code to Smoothie
37 print("Streaming " + args
.gcode_file
.name
+ " to " + args
.ipaddr
)
40 outlog
= open(args
.gcode_file
.name
+ ".log", 'w')
42 tn
= telnetlib
.Telnet(args
.ipaddr
)
44 #write_raw_sequence(tn, telnetlib.IAC + telnetlib.DO + "\x55")
47 tn
.read_until("Smoothie command shell")
53 line
= re
.sub("[ ]*;.*", '', line
) # remove everything after ;
54 line
= line
.strip() #send only the bare necessity.
59 okcnt
+= rep
.count("ok")
60 if verbose
: print("SND " + str(linecnt
) + ": " + line
.strip() + " - " + str(okcnt
))
61 if args
.log
: outlog
.write("SND " + str(linecnt
) + ": " + line
.strip() + " - " + str(okcnt
) + "\n" )
62 print("Waiting for complete...")
64 while okcnt
< linecnt
:
66 okcnt
+= rep
.count("ok")
67 if verbose
: print(str(linecnt
) + " - " + str(okcnt
) )
68 if args
.log
: outlog
.write(str(linecnt
) + " - " + str(okcnt
) + "\n" )
71 if args
.log
: outlog
.close()