Clean up and new streaming script check-mode feature.
[new] The stream.py streaming script now has a check-mode option, where it will place Grbl in $C check mode automatically and then stream the g-code program. It's a very fast way to check if the g-code program has any errors. [fix] The debug variable was not initialized if the debug option was enabled in config.h [fix] Updated error_codes CSV file to the same format as the others.
This commit is contained in:
parent
790c666ecb
commit
921e5a9799
5 changed files with 113 additions and 52 deletions
|
|
@ -18,7 +18,7 @@ CHANGELOG:
|
|||
write mode via simple streaming method. MIT-licensed.
|
||||
|
||||
TODO:
|
||||
- Add runtime command capabilities
|
||||
- Add realtime control commands during streaming.
|
||||
|
||||
---------------------
|
||||
The MIT License (MIT)
|
||||
|
|
@ -69,6 +69,8 @@ parser.add_argument('-q','--quiet',action='store_true', default=False,
|
|||
help='suppress output text')
|
||||
parser.add_argument('-s','--settings',action='store_true', default=False,
|
||||
help='settings write mode')
|
||||
parser.add_argument('-c','--check',action='store_true', default=False,
|
||||
help='stream in check mode')
|
||||
args = parser.parse_args()
|
||||
|
||||
# Periodic timer to query for status reports
|
||||
|
|
@ -89,14 +91,30 @@ verbose = True
|
|||
if args.quiet : verbose = False
|
||||
settings_mode = False
|
||||
if args.settings : settings_mode = True
|
||||
check_mode = False
|
||||
if args.check : check_mode = True
|
||||
|
||||
# Wake up grbl
|
||||
print "Initializing 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()
|
||||
|
||||
if check_mode :
|
||||
print "Enabling Grbl Check-Mode: SND: [$C]",
|
||||
s.write("$C\n")
|
||||
while 1:
|
||||
grbl_out = s.readline().strip() # Wait for grbl response with carriage return
|
||||
if grbl_out.find('error') >= 0 :
|
||||
print "REC:",grbl_out
|
||||
print " Failed to set Grbl check-mode. Aborting..."
|
||||
quit()
|
||||
elif grbl_out.find('ok') >= 0 :
|
||||
if verbose: print 'REC:',grbl_out
|
||||
break
|
||||
|
||||
start_time = time.time();
|
||||
|
||||
# Start status report periodic timer
|
||||
|
|
@ -107,6 +125,7 @@ if ENABLE_STATUS_REPORTS :
|
|||
|
||||
# Stream g-code to grbl
|
||||
l_count = 0
|
||||
error_count = 0
|
||||
if settings_mode:
|
||||
# Send settings file via simple call-response streaming method. Settings must be streamed
|
||||
# in this manner since the EEPROM accessing cycles shut-off the serial interrupt.
|
||||
|
|
@ -115,15 +134,19 @@ if settings_mode:
|
|||
l_count += 1 # Iterate line counter
|
||||
# l_block = re.sub('\s|\(.*?\)','',line).upper() # Strip comments/spaces/new line and capitalize
|
||||
l_block = line.strip() # Strip all EOL characters for consistency
|
||||
if verbose: print 'SND: ' + str(l_count) + ':' + l_block,
|
||||
if verbose: print "SND>"+str(l_count)+": \"" + l_block + "\""
|
||||
s.write(l_block + '\n') # Send g-code block to grbl
|
||||
while 1:
|
||||
grbl_out = s.readline().strip() # Wait for grbl response with carriage return
|
||||
if grbl_out.find('ok') < 0 and grbl_out.find('error') < 0 :
|
||||
print "\n Debug: ",grbl_out,
|
||||
else :
|
||||
if verbose: print 'REC:',grbl_out
|
||||
if grbl_out.find('ok') >= 0 :
|
||||
if verbose: print " REC<"+str(l_count)+": \""+grbl_out+"\""
|
||||
break
|
||||
elif grbl_out.find('error') >= 0 :
|
||||
if verbose: print " REC<"+str(l_count)+": \""+grbl_out+"\""
|
||||
error_count += 1
|
||||
break
|
||||
else:
|
||||
print " MSG: \""+grbl_out+"\""
|
||||
else:
|
||||
# Send g-code program via a more agressive streaming protocol that forces characters into
|
||||
# Grbl's serial read buffer to ensure Grbl has immediate access to the next g-code command
|
||||
|
|
@ -141,22 +164,38 @@ else:
|
|||
while sum(c_line) >= RX_BUFFER_SIZE-1 | s.inWaiting() :
|
||||
out_temp = s.readline().strip() # Wait for grbl response
|
||||
if out_temp.find('ok') < 0 and out_temp.find('error') < 0 :
|
||||
print " Debug: ",out_temp # Debug response
|
||||
print " MSG: \""+out_temp+"\"" # Debug response
|
||||
else :
|
||||
grbl_out += out_temp;
|
||||
if out_temp.find('error') >= 0 : error_count += 1
|
||||
g_count += 1 # Iterate g-code counter
|
||||
grbl_out += str(g_count); # Add line finished indicator
|
||||
if verbose: print " REC<"+str(g_count)+": \""+out_temp+"\""
|
||||
del c_line[0] # Delete the block character count corresponding to the last 'ok'
|
||||
s.write(l_block + '\n') # Send g-code block to grbl
|
||||
if verbose: print "BUF: " + str(sum(c_line)) + " SND: " + str(l_count) + " [" + l_block + "] REC: " + grbl_out
|
||||
if verbose: print "SND>"+str(l_count)+": \"" + l_block + "\""
|
||||
# Wait until all responses have been received.
|
||||
while l_count > g_count :
|
||||
out_temp = s.readline().strip() # Wait for grbl response
|
||||
if out_temp.find('ok') < 0 and out_temp.find('error') < 0 :
|
||||
print " MSG: \""+out_temp+"\"" # Debug response
|
||||
else :
|
||||
if out_temp.find('error') >= 0 : error_count += 1
|
||||
g_count += 1 # Iterate g-code counter
|
||||
del c_line[0] # Delete the block character count corresponding to the last 'ok'
|
||||
if verbose: print " REC<"+str(g_count)+": \""+out_temp + "\""
|
||||
|
||||
# Wait for user input after streaming is completed
|
||||
print "G-code streaming finished!"
|
||||
print "\nG-code streaming finished!"
|
||||
end_time = time.time();
|
||||
is_run = False;
|
||||
print " Time elapsed: ",end_time-start_time,"\n"
|
||||
print "WARNING: Wait until grbl completes buffered g-code blocks before exiting."
|
||||
raw_input(" Press <Enter> to exit and disable grbl.")
|
||||
if check_mode :
|
||||
if error_count > 0 :
|
||||
print "CHECK FAILED:",error_count,"errors found! See output for details.\n"
|
||||
else :
|
||||
print "CHECK PASSED: No errors found in g-code program.\n"
|
||||
else :
|
||||
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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue