X-Git-Url: https://git.hcoop.net/clinton/Smoothieware.git/blobdiff_plain/d5c301789d3ac90452bd999ee7e538d7a479400c..01b2e1512ef6767132902c6c0420245629034cfb:/smoothie-stream.py diff --git a/smoothie-stream.py b/smoothie-stream.py index 54564a69..8a8a7bc7 100644 --- a/smoothie-stream.py +++ b/smoothie-stream.py @@ -8,8 +8,14 @@ Based on GRBL stream.py from __future__ import print_function import sys import telnetlib +import re import argparse +def write_raw_sequence(tn, seq): + sock = tn.get_socket() + if sock is not None: + sock.send(seq) + # Define command line argument interface parser = argparse.ArgumentParser(description='Stream g-code file to Smoothie over telnet.') parser.add_argument('gcode_file', type=argparse.FileType('r'), @@ -18,17 +24,25 @@ parser.add_argument('ipaddr', help='Smoothie IP address') parser.add_argument('-q','--quiet',action='store_true', default=False, help='suppress output text') +parser.add_argument('-l','--log',action='store_true', default=False, + help='suppress output text and output to file (gcode file with .log appended)') args = parser.parse_args() f = args.gcode_file -verbose = not args.quiet +verbose = not (args.quiet or args.log) # Stream g-code to Smoothie print("Streaming " + args.gcode_file.name + " to " + args.ipaddr) +outlog = None +if args.log: + outlog = open(args.gcode_file.name + ".log", 'w') tn = telnetlib.Telnet(args.ipaddr) +# turn on prompt +#write_raw_sequence(tn, telnetlib.IAC + telnetlib.DO + "\x55") + # read startup prompt -tn.read_until("> ") +tn.read_until("Smoothie command shell") okcnt= 0 linecnt= 0 @@ -38,14 +52,17 @@ for line in f: rep= tn.read_eager() okcnt += rep.count("ok") if verbose: print("SND " + str(linecnt) + ": " + line.strip() + " - " + str(okcnt)) - + if args.log: outlog.write("SND " + str(linecnt) + ": " + line.strip() + " - " + str(okcnt) + "\n" ) print("Waiting for complete...") while okcnt < linecnt: rep= tn.read_some() okcnt += rep.count("ok") if verbose: print(str(linecnt) + " - " + str(okcnt) ) + if args.log: outlog.write(str(linecnt) + " - " + str(okcnt) + "\n" ) + +if args.log: outlog.close() tn.write("exit\n") tn.read_all()