diff --git a/ecmc_plugin_grbl/ecmcGrbl.cpp b/ecmc_plugin_grbl/ecmcGrbl.cpp index f397cbf..c1bc11e 100644 --- a/ecmc_plugin_grbl/ecmcGrbl.cpp +++ b/ecmc_plugin_grbl/ecmcGrbl.cpp @@ -391,6 +391,7 @@ bool ecmcGrbl::WriteGCodeSuccess() { setReset(0); setReset(1); setReset(0); + printf("SOMETHING BAD HAPPEND!!!!\n"); grblCommandBufferIndex_ = 0; return false; // for loop } @@ -398,6 +399,7 @@ bool ecmcGrbl::WriteGCodeSuccess() { grblCommandBufferIndex_++; } else { + printf("NO MORE COMMANDS in buffer!!!\n"); if( ( (grblCommandBufferIndex_ >= grblCommandBuffer_.size()) || !executeCmd_) && grblInitDone_) { writerBusy_ = 0; return true; // code executed once @@ -411,18 +413,17 @@ bool ecmcGrbl::WriteGCodeSuccess() { } void ecmcGrbl::grblWriteCommand(std::string command) { - // wait for grbl - while(serial_get_rx_buffer_available() <= strlen(command.c_str())+1) { - delay_ms(1); + while(serial_get_rx_buffer_available() <= strlen(command.c_str()+1)) { + printf("WAITING for freee in buffer %d %d\n",serial_get_rx_buffer_available(),strlen(command.c_str()+1)); + delay_ms(1000); } + ecmc_write_command_serial(strdup(command.c_str())); if(cfgDbgMode_){ printf("GRBL: INFO: Write command (command[%d] = %s)\n", grblCommandBufferIndex_, command.c_str()); } - - ecmc_write_command_serial(strdup(command.c_str())); } grblReplyType ecmcGrbl::grblReadReply() { @@ -438,7 +439,7 @@ void ecmcGrbl::grblWriteCommand(std::string command) { if(c == '\n'&& reply.length() > 1) { if(reply.find(ECMC_PLUGIN_GRBL_GRBL_OK_STRING) != std::string::npos) { if(cfgDbgMode_){ - printf("GRBL: INFO: Reply OK\n"); + printf("GRBL: INFO: Reply OK (%s)\n",reply.c_str()); } return ECMC_GRBL_REPLY_OK; } else if(reply.find(ECMC_PLUGIN_GRBL_GRBL_ERR_STRING) != std::string::npos) { @@ -986,8 +987,11 @@ void ecmcGrbl::addConfig(std::string command) { __FILE__,__FUNCTION__,__LINE__,ECMC_PLUGIN_CONFIG_ERROR_CODE); return; } + + commandStrip+='\n'; epicsMutexLock(grblConfigBufferMutex_); + grblConfigBuffer_.push_back(commandStrip.c_str()); epicsMutexUnlock(grblConfigBufferMutex_); if(cfgDbgMode_){ diff --git a/grbl/grbl_gcode.c b/grbl/grbl_gcode.c index 6770817..637cde6 100644 --- a/grbl/grbl_gcode.c +++ b/grbl/grbl_gcode.c @@ -69,6 +69,10 @@ void gc_sync_position() uint8_t gc_execute_line(char *line) { PRINTF_DEBUG(""); + printf("gc_execute_line: %s\n",line); + if(strlen(line)<2) { + return(STATUS_OK); + } /* ------------------------------------------------------------------------------------- STEP 1: Initialize parser block struct and copy current g-code state modes. The parser diff --git a/grbl/grbl_protocol.c b/grbl/grbl_protocol.c index d81714d..c894d9f 100644 --- a/grbl/grbl_protocol.c +++ b/grbl/grbl_protocol.c @@ -80,7 +80,7 @@ void protocol_main_loop() delay_us(100); // added for ecmc while((c = serial_read()) != SERIAL_NO_DATA) { if ((c == '\n') || (c == '\r')) { // End of line reached - + protocol_execute_realtime(); // Runtime command check point. if (sys.abort) { return; } // Bail to calling function upon system abort @@ -93,7 +93,7 @@ void protocol_main_loop() if (line_flags & LINE_FLAG_OVERFLOW) { // Report line overflow error. report_status_message(STATUS_OVERFLOW); - } else if (line[0] == 0) { + } else if (line[0] == 0 || line[0]== '0') { // Empty or comment line. For syncing purposes. report_status_message(STATUS_OK); } else if (line[0] == '$') { @@ -104,7 +104,11 @@ void protocol_main_loop() report_status_message(STATUS_SYSTEM_GC_LOCK); } else { // Parse and execute g-code block. - report_status_message(gc_execute_line(line)); + printf("protocol: Line to gc_execute %s\n",line); + if(strlen(line)>1) { + + report_status_message(gc_execute_line(line)); + } } // Reset tracking data for next line. diff --git a/grbl/grbl_serial.c b/grbl/grbl_serial.c index d49daff..6cdf7b8 100644 --- a/grbl/grbl_serial.c +++ b/grbl/grbl_serial.c @@ -106,6 +106,7 @@ uint16_t serial_get_tx_buffer_count() void serial_init() { printf("%s:%s:%d:\n",__FILE__,__FUNCTION__,__LINE__); + memset(&serial_rx_buffer[0],0,RX_RING_BUFFER); // Create some mutexes to ensure safe communication if(!(serialRxBufferMutex = epicsMutexCreate())) { printf("%s:%s:%d: Failed create serialRxBufferMutex\n",__FILE__,__FUNCTION__,__LINE__); @@ -203,15 +204,17 @@ uint8_t serial_read() uint16_t tail = serial_rx_buffer_tail; // Temporary serial_rx_buffer_tail (to optimize for volatile) if (serial_rx_buffer_head == tail) { MUTEX_UNLOCK(serialRxBufferMutex); + //printf("tail %u, head %u, available %u\n",serial_rx_buffer_tail,serial_rx_buffer_head,serial_get_rx_buffer_available()); return SERIAL_NO_DATA; } else { uint8_t data = serial_rx_buffer[tail]; + serial_rx_buffer[tail]=0; tail++; if (tail == RX_RING_BUFFER) { tail = 0; } - + //printf("tail %u, head %u, available %u\n",serial_rx_buffer_tail,serial_rx_buffer_head,serial_get_rx_buffer_available()); serial_rx_buffer_tail = tail; MUTEX_UNLOCK(serialRxBufferMutex); return data; @@ -270,10 +273,10 @@ void ecmc_add_char_to_buffer(char data) if (next_head == RX_RING_BUFFER) { next_head = 0; } // Write data to buffer unless it is full. - if (next_head != serial_rx_buffer_tail) { + //if (next_head != serial_rx_buffer_tail) { serial_rx_buffer[serial_rx_buffer_head] = data; serial_rx_buffer_head = next_head; - } + //} } } } @@ -285,11 +288,24 @@ void ecmc_write_command_serial(char* line) { for(i=0; i