-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpyplotter.py
More file actions
executable file
·46 lines (37 loc) · 1.1 KB
/
pyplotter.py
File metadata and controls
executable file
·46 lines (37 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python
import argparse
import serial
try:
import readline # noqa
except ImportError:
pass
parser = argparse.ArgumentParser(
description='CNC Import tool for Makeblock XY Plotter')
parser.add_argument('device', help="Serial device to connect")
parser.add_argument('-f', '--file',
help="File to send")
parser.add_argument('-b', '--baud', default=115200, help="Baud rate")
def main():
arg = parser.parse_args()
ser = serial.Serial(arg.device, arg.baud, timeout=1)
wait_for(ser, "start")
if not arg.file:
while(True):
inp = raw_input("> ")
ser.write(inp)
else:
f = open(arg.file, 'r')
for line in f:
if line.rstrip() == "" or line.startswith("("):
continue
print "> %s" % line
ser.write(line)
wait_for(ser, "ok", "start")
def wait_for(ser, *args):
line = ""
while line not in args:
line = ser.readline().rstrip()
if line is not None and line != "":
print "< %s" % line
if __name__ == "__main__":
main()