Committer:
Sergunb
Date:
Mon Sep 04 12:03:42 2017 +0000
Revision:
0:f1834a63f7c1
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Sergunb 0:f1834a63f7c1 1 #!/usr/bin/env python
Sergunb 0:f1834a63f7c1 2 """\
Sergunb 0:f1834a63f7c1 3 Simple g-code streaming script for grbl
Sergunb 0:f1834a63f7c1 4
Sergunb 0:f1834a63f7c1 5 Provided as an illustration of the basic communication interface
Sergunb 0:f1834a63f7c1 6 for grbl. When grbl has finished parsing the g-code block, it will
Sergunb 0:f1834a63f7c1 7 return an 'ok' or 'error' response. When the planner buffer is full,
Sergunb 0:f1834a63f7c1 8 grbl will not send a response until the planner buffer clears space.
Sergunb 0:f1834a63f7c1 9
Sergunb 0:f1834a63f7c1 10 G02/03 arcs are special exceptions, where they inject short line
Sergunb 0:f1834a63f7c1 11 segments directly into the planner. So there may not be a response
Sergunb 0:f1834a63f7c1 12 from grbl for the duration of the arc.
Sergunb 0:f1834a63f7c1 13
Sergunb 0:f1834a63f7c1 14 ---------------------
Sergunb 0:f1834a63f7c1 15 The MIT License (MIT)
Sergunb 0:f1834a63f7c1 16
Sergunb 0:f1834a63f7c1 17 Copyright (c) 2012 Sungeun K. Jeon
Sergunb 0:f1834a63f7c1 18
Sergunb 0:f1834a63f7c1 19 Permission is hereby granted, free of charge, to any person obtaining a copy
Sergunb 0:f1834a63f7c1 20 of this software and associated documentation files (the "Software"), to deal
Sergunb 0:f1834a63f7c1 21 in the Software without restriction, including without limitation the rights
Sergunb 0:f1834a63f7c1 22 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
Sergunb 0:f1834a63f7c1 23 copies of the Software, and to permit persons to whom the Software is
Sergunb 0:f1834a63f7c1 24 furnished to do so, subject to the following conditions:
Sergunb 0:f1834a63f7c1 25
Sergunb 0:f1834a63f7c1 26 The above copyright notice and this permission notice shall be included in
Sergunb 0:f1834a63f7c1 27 all copies or substantial portions of the Software.
Sergunb 0:f1834a63f7c1 28
Sergunb 0:f1834a63f7c1 29 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Sergunb 0:f1834a63f7c1 30 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Sergunb 0:f1834a63f7c1 31 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Sergunb 0:f1834a63f7c1 32 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Sergunb 0:f1834a63f7c1 33 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Sergunb 0:f1834a63f7c1 34 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
Sergunb 0:f1834a63f7c1 35 THE SOFTWARE.
Sergunb 0:f1834a63f7c1 36 ---------------------
Sergunb 0:f1834a63f7c1 37 """
Sergunb 0:f1834a63f7c1 38
Sergunb 0:f1834a63f7c1 39 import serial
Sergunb 0:f1834a63f7c1 40 import time
Sergunb 0:f1834a63f7c1 41
Sergunb 0:f1834a63f7c1 42 # Open grbl serial port
Sergunb 0:f1834a63f7c1 43 s = serial.Serial('/dev/tty.usbmodem1811',115200)
Sergunb 0:f1834a63f7c1 44
Sergunb 0:f1834a63f7c1 45 # Open g-code file
Sergunb 0:f1834a63f7c1 46 f = open('grbl.gcode','r');
Sergunb 0:f1834a63f7c1 47
Sergunb 0:f1834a63f7c1 48 # Wake up grbl
Sergunb 0:f1834a63f7c1 49 s.write("\r\n\r\n")
Sergunb 0:f1834a63f7c1 50 time.sleep(2) # Wait for grbl to initialize
Sergunb 0:f1834a63f7c1 51 s.flushInput() # Flush startup text in serial input
Sergunb 0:f1834a63f7c1 52
Sergunb 0:f1834a63f7c1 53 # Stream g-code to grbl
Sergunb 0:f1834a63f7c1 54 for line in f:
Sergunb 0:f1834a63f7c1 55 l = line.strip() # Strip all EOL characters for consistency
Sergunb 0:f1834a63f7c1 56 print 'Sending: ' + l,
Sergunb 0:f1834a63f7c1 57 s.write(l + '\n') # Send g-code block to grbl
Sergunb 0:f1834a63f7c1 58 grbl_out = s.readline() # Wait for grbl response with carriage return
Sergunb 0:f1834a63f7c1 59 print ' : ' + grbl_out.strip()
Sergunb 0:f1834a63f7c1 60
Sergunb 0:f1834a63f7c1 61 # Wait here until grbl is finished to close serial port and file.
Sergunb 0:f1834a63f7c1 62 raw_input(" Press <Enter> to exit and disable grbl.")
Sergunb 0:f1834a63f7c1 63
Sergunb 0:f1834a63f7c1 64 # Close file and serial port
Sergunb 0:f1834a63f7c1 65 f.close()
Sergunb 0:f1834a63f7c1 66 s.close()