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 | ||
48a0fdb6 JM |
13 | def write_raw_sequence(tn, seq): |
14 | sock = tn.get_socket() | |
15 | if sock is not None: | |
16 | sock.send(seq) | |
17 | ||
d4ee6ee2 JM |
18 | # Define command line argument interface |
19 | parser = argparse.ArgumentParser(description='Stream g-code file to Smoothie over telnet.') | |
20 | parser.add_argument('gcode_file', type=argparse.FileType('r'), | |
21 | help='g-code filename to be streamed') | |
22 | parser.add_argument('ipaddr', | |
23 | help='Smoothie IP address') | |
24 | parser.add_argument('-q','--quiet',action='store_true', default=False, | |
25 | help='suppress output text') | |
26 | args = parser.parse_args() | |
27 | ||
28 | f = args.gcode_file | |
29 | verbose = not args.quiet | |
30 | ||
31 | # Stream g-code to Smoothie | |
32 | print("Streaming " + args.gcode_file.name + " to " + args.ipaddr) | |
33 | ||
34 | tn = telnetlib.Telnet(args.ipaddr) | |
48a0fdb6 JM |
35 | # turn on prompt |
36 | #write_raw_sequence(tn, telnetlib.IAC + telnetlib.DO + "\x55") | |
37 | ||
d4ee6ee2 | 38 | # read startup prompt |
48a0fdb6 | 39 | tn.read_until("Smoothie command shell") |
d4ee6ee2 JM |
40 | |
41 | okcnt= 0 | |
42 | linecnt= 0 | |
43 | for line in f: | |
44 | tn.write(line) | |
45 | linecnt+=1 | |
46 | rep= tn.read_eager() | |
47 | okcnt += rep.count("ok") | |
48 | if verbose: print("SND " + str(linecnt) + ": " + line.strip() + " - " + str(okcnt)) | |
49 | ||
50 | print("Waiting for complete...") | |
51 | ||
52 | while okcnt < linecnt: | |
53 | rep= tn.read_some() | |
54 | okcnt += rep.count("ok") | |
55 | if verbose: print(str(linecnt) + " - " + str(okcnt) ) | |
56 | ||
57 | tn.write("exit\n") | |
58 | tn.read_all() | |
59 | ||
60 | print("Done") | |
61 | ||
62 | ||
63 |