Position reporting, refactored system variables, serial print fixes, updated streaming scripts.
- Added machine position reporting to status queries. This will be further developed with part positioning/offsets and maintaining location upon reset. - System variables refactored into a global struct for better readability. - Removed old obsolete Ruby streaming scripts. These were no longer compatible. Updated Python streaming scripts. - Fixed printFloat() and other printing functions. - Decreased planner buffer back to 18 blocks and increased TX serial buffer to 64 bytes. Need the memory space for future developments. - Begun adding run-time modes to grbl, where block delete toggle, mm/in reporting modes, jog modes, etc can be set during runtime. Will be fleshed out and placed into EEPROM when everything is added.
This commit is contained in:
@ -1,6 +1,15 @@
|
||||
#!/usr/bin/env python
|
||||
"""\
|
||||
Simple g-code streaming script for grbl
|
||||
|
||||
Provided as an illustration of the basic communication interface
|
||||
for grbl. When grbl has finished parsing the g-code block, it will
|
||||
return an 'ok' or 'error' response. When the planner buffer is full,
|
||||
grbl will not send a response until the planner buffer clears space.
|
||||
|
||||
G02/03 arcs are special exceptions, where they inject short line
|
||||
segments directly into the planner. So there may not be a response
|
||||
from grbl for the duration of the arc.
|
||||
"""
|
||||
|
||||
import serial
|
||||
|
80
script/stream.py
Executable file
80
script/stream.py
Executable file
@ -0,0 +1,80 @@
|
||||
#!/usr/bin/env python
|
||||
"""\
|
||||
Stream g-code to grbl controller
|
||||
|
||||
This script differs from the simple_stream.py script by
|
||||
tracking the number of characters in grbl's serial read
|
||||
buffer. This allows grbl to fetch the next line directly
|
||||
from the serial buffer and does not have to wait for a
|
||||
response from the computer. This effectively adds another
|
||||
buffer layer to prevent buffer starvation.
|
||||
|
||||
TODO: - Add runtime command capabilities
|
||||
|
||||
Version: SKJ.20120104
|
||||
"""
|
||||
|
||||
import serial
|
||||
import re
|
||||
import time
|
||||
import sys
|
||||
import argparse
|
||||
|
||||
RX_BUFFER_SIZE = 128
|
||||
|
||||
# Define command line argument interface
|
||||
parser = argparse.ArgumentParser(description='Stream g-code file to grbl. (pySerial library required)')
|
||||
parser.add_argument('gcode', type=argparse.FileType('r'),
|
||||
help='g-code filename to be streamed')
|
||||
parser.add_argument('device',
|
||||
help='serial device path')
|
||||
parser.add_argument('-q','--quiet',action='store_true', default=False,
|
||||
help='suppress output text')
|
||||
args = parser.parse_args()
|
||||
|
||||
# Initialize
|
||||
s = serial.Serial(args.device_file,9600)
|
||||
f = args.gcode_file
|
||||
verbose = True
|
||||
if args.quiet : verbose = False
|
||||
|
||||
# Wake up grbl
|
||||
print "Initializing grbl..."
|
||||
s.write("\r\n\r\n")
|
||||
|
||||
# Wait for grbl to initialize and flush startup text in serial input
|
||||
time.sleep(2)
|
||||
s.flushInput()
|
||||
|
||||
# Stream g-code to grbl
|
||||
print "Streaming ", args.gcode_file.name, " to ", args.device_file
|
||||
l_count = 0
|
||||
g_count = 0
|
||||
c_line = []
|
||||
for line in f:
|
||||
l_count += 1 # Iterate line counter
|
||||
# l_block = re.sub('\s|\(.*?\)','',line).upper() # Strip comments/spaces/new line and capitalize
|
||||
l_block = line.strip()
|
||||
c_line.append(len(l_block)) # Track number of characters in grbl serial read buffer
|
||||
grbl_out = ''
|
||||
while sum(c_line) >= RX_BUFFER_SIZE-1 | s.inWaiting() :
|
||||
out_temp = s.readline().strip() # Wait for grbl response
|
||||
if out_temp not in ['ok','error'] :
|
||||
print " Debug: ",out_temp # Debug response
|
||||
else :
|
||||
grbl_out += out_temp;
|
||||
g_count += 1 # Iterate g-code counter
|
||||
grbl_out += str(g_count); # Add line finished indicator
|
||||
del c_line[0]
|
||||
if verbose: print "SND: " + str(l_count) + " : " + l_block,
|
||||
s.write(l_block + '\n') # Send block to grbl
|
||||
if verbose : print "BUF:",str(sum(c_line)),"REC:",grbl_out
|
||||
|
||||
# Wait for user input after streaming is completed
|
||||
print "G-code streaming finished!\n"
|
||||
print "WARNING: Wait until grbl completes buffered g-code blocks before exiting."
|
||||
raw_input(" Press <Enter> to exit and disable grbl.")
|
||||
|
||||
# Close file and serial port
|
||||
f.close()
|
||||
s.close()
|
Reference in New Issue
Block a user