-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimpleserial.py
More file actions
33 lines (27 loc) · 856 Bytes
/
Copy pathsimpleserial.py
File metadata and controls
33 lines (27 loc) · 856 Bytes
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
#!/usr/bin/env python
"""\
Simple g-code streaming script for grbl
"""
import serial
import time
# Open grbl serial port
s = serial.Serial('/dev/tty.usbmodem1D1241', 115200, timeout=None)
# Open g-code file
f = open('../testwrite.nc', 'r');
# Wake up grbl
s.write("\r\n\r\n")
time.sleep(2) # Wait for grbl to initialize
s.flushInput() # Flush startup text in serial input
print "starting"
# Stream g-code to grbl
for line in f:
l = line.strip() # Strip all EOL characters for streaming
print 'Sending: ' + l,
s.write(l + '\n') # Send g-code block to grbl
grbl_out = s.readline() # Wait for grbl response with carriage return
print ' : ' + grbl_out.strip()
# Wait here until grbl is finished to close serial port and file.
raw_input(" Press <Enter> to exit and disable grbl.")
# Close file and serial port
f.close()
s.close()