-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathuarm.py
71 lines (56 loc) · 1.83 KB
/
uarm.py
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/local/bin/python3
"""\
Stream g-code to the uArm Swift Pro
---------------------
"""
import serial
import time
import os
import argparse
parser = argparse.ArgumentParser(description='Stream g-code file uArm. (pySerial and argparse libraries required)')
parser.add_argument('gcode_file', type=argparse.FileType('r'),
help='g-code file to be streamed')
parser.add_argument('device_file',
help='serial device path')
args = parser.parse_args()
# set when we start running
start = time.time()
# kill uarmcore left running from uArm Studio
os.system('killall uarmcore-2')
time.sleep(2)
# Open serial port at proper baud rate
s = serial.Serial(args.device_file,115200)
# set g-code file to open
f = args.gcode_file
# Wake up grbl
# s.write(str.encode('\r\n\r\n'))
time.sleep(2) # Wait for grbl to initialize
s.flushInput() # Flush startup text in serial input
# Stream g-code to grbl
for line in f:
# we need to skip any blank lines
if line == '\n' :
pass
else :
l = line.strip() # Strip all EOL characters for consistency
print('Sending : ' + l)
s.write(str.encode(l)) # Send g-code block to grbl
s.write(str.encode('\n'))
grbl_out = s.readline() # Wait for grbl response with carriage return
grbl_out_str = grbl_out.decode()
grbl_out_str.strip()
print('RESPONSE: ', end = "")
print(grbl_out_str, end = "")
# Wait here until grbl is finished to close serial port and file.
# next line is broken... fix it later I guess?
#raw_input(" Press <Enter> to exit and disable grbl.")
# Close file and serial port
f.close()
s.close()
# calculate how long it ran
seconds = time.time() - start
if seconds > 60 :
minutes = seconds / 60
print("Drawing took {0:0.1f} minutes".format(minutes))
else :
print("Drawing took {0:0.1f} seconds".format(seconds))