Basically it replies all ok and suddenly prints the error 24 as a reply.
On start, and while the machine is moving/hovering the Y and Y axis above the surface, and on its way to the first working height point, the buffer is filled up very fast and the serial activity stays stalled until the first movement is completed, when the sending recovers activity and usually outputs the error after a few seconds.
This behavior leads to believe that the buffer is overflowed, It may be a way to read the available buffer space and throttle the data accordingly, but I have no idea how.
Edit: I see that a Python script from GRBL repo can keep track of the characters sent and ok's received and will control the output in such a way to never let the buffer get full.
I will give a try in implementing this part in C..
# 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
# rather than wait for the call-response serial protocol to finish. This is done by careful
# counting of the number of characters sent by the streamer to Grbl and tracking Grbl's
# responses, such that we never overflow Grbl's serial read buffer.
g_count = 0
c_line = []
# periodic() # Start status report periodic timer
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)+1) # 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.find('ok') < 0 and out_temp.find('error') < 0 :
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] # Delete the block character count corresponding to the last 'ok'
if verbose: print "SND: " + str(l_count) + " : " + l_block,
s.write(l_block + '\n') # Send g-code block to grbl
if verbose : print "BUF:",str(sum(c_line)),"REC:",grbl_out