Commit | Line | Data |
---|---|---|
d4ee6ee2 JM |
1 | #!/usr/bin/env python |
2 | """\ | |
3 | Stream g-code to Smoothie telnet connection | |
4 | ||
5 | Based on GRBL stream.py | |
6 | """ | |
7 | ||
8 | from __future__ import print_function | |
9 | import sys | |
10 | import telnetlib | |
11 | import argparse | |
12 | ||
13 | # Define command line argument interface | |
14 | parser = argparse.ArgumentParser(description='Stream g-code file to Smoothie over telnet.') | |
15 | parser.add_argument('gcode_file', type=argparse.FileType('r'), | |
16 | help='g-code filename to be streamed') | |
17 | parser.add_argument('ipaddr', | |
18 | help='Smoothie IP address') | |
19 | parser.add_argument('-q','--quiet',action='store_true', default=False, | |
20 | help='suppress output text') | |
21 | args = parser.parse_args() | |
22 | ||
23 | f = args.gcode_file | |
24 | verbose = not args.quiet | |
25 | ||
26 | # Stream g-code to Smoothie | |
27 | print("Streaming " + args.gcode_file.name + " to " + args.ipaddr) | |
28 | ||
29 | tn = telnetlib.Telnet(args.ipaddr) | |
30 | # read startup prompt | |
31 | tn.read_until("> ") | |
32 | ||
33 | okcnt= 0 | |
34 | linecnt= 0 | |
35 | for line in f: | |
36 | tn.write(line) | |
37 | linecnt+=1 | |
38 | rep= tn.read_eager() | |
39 | okcnt += rep.count("ok") | |
40 | if verbose: print("SND " + str(linecnt) + ": " + line.strip() + " - " + str(okcnt)) | |
41 | ||
42 | print("Waiting for complete...") | |
43 | ||
44 | while okcnt < linecnt: | |
45 | rep= tn.read_some() | |
46 | okcnt += rep.count("ok") | |
47 | if verbose: print(str(linecnt) + " - " + str(okcnt) ) | |
48 | ||
49 | tn.write("exit\n") | |
50 | tn.read_all() | |
51 | ||
52 | print("Done") | |
53 | ||
54 | ||
55 |