int interpret_from_keyboard( /* ARGUMENTS */ int block_delete, /* switch which is ON or OFF */ int print_stack) /* option which is ON or OFF */ { char line[RS274NGC_TEXT_SIZE]; int status; for(; ;) { printf("READ => "); fgets(line, sizeof(line), stdin); if (strcmp (line, "quit") IS 0) return 0; status SET_TO rs274ngc_read(line); if ((status IS RS274NGC_EXECUTE_FINISH) AND (block_delete IS ON)); else if (status IS RS274NGC_ENDFILE); else if ((status ISNT RS274NGC_EXECUTE_FINISH) AND (status ISNT RS274NGC_OK)) report_error(status, print_stack); else { status SET_TO rs274ngc_execute(); if ((status IS RS274NGC_EXIT) OR (status IS RS274NGC_EXECUTE_FINISH)); else if (status ISNT RS274NGC_OK) report_error(status, print_stack); } } }
int CGCodeInterpreter::ChangeFixtureNumber(int fixture) { switch (fixture) { case 1: return rs274ngc_execute("G54"); case 2: return rs274ngc_execute("G55"); case 3: return rs274ngc_execute("G56"); case 4: return rs274ngc_execute("G57"); case 5: return rs274ngc_execute("G58"); case 6: return rs274ngc_execute("G59"); case 7: return rs274ngc_execute("G59.1"); case 8: return rs274ngc_execute("G59.2"); case 9: return rs274ngc_execute("G59.3"); } return 0; }
int CGCodeInterpreter::DoExecute() { int status; char trash[INTERP_TEXT_SIZE]; char * read_ok; int program_status; ErrorOutput[0]='\0'; program_status = RS274NGC_OK; // This doesn't work yet and results in a memory leak // so leave this static for now // int * device = new int; // *device=(int)this; // SET_CANON_DEVICE(device); if (DoResumeSafe()) return 1; // check for re-position motions // initialize everything if we are starting at the beginning if (m_restart || m_InitializeOnExecute) { status = InitializeInterp(); if (status) return status; } CoordMotion->m_Stopping = STOPPED_NONE; // always read the tool file now (some users set it externally) // if (m_restart || m_ReadToolFile) { if (ToolFile[0]!=0) { status = read_tool_file(ToolFile, &_setup); if (status != RS274NGC_OK) return rs274ErrorExit(status); } m_ReadToolFile = false; } if (!CoordMotion->m_Simulate) { int result; // find out which axis is which // force refresh and save results CoordMotion->m_DefineCS_valid = false; if (CoordMotion->m_PreviouslyStopped) result = CoordMotion->ReadCurAbsPosition(&CoordMotion->current_x,&CoordMotion->current_y,&CoordMotion->current_z, &CoordMotion->current_a,&CoordMotion->current_b,&CoordMotion->current_c,true); else result = ReadAndSyncCurPositions(&_setup.current_x,&_setup.current_y,&_setup.current_z,&_setup.AA_current,&_setup.BB_current,&_setup.CC_current); if (result == 1) { if (CoordMotion->m_AxisDisabled) strcpy(ErrorOutput,"Unable to read defined coordinate system axis positions - Axis Disabled "); else strcpy(ErrorOutput,"Unable to read defined coordinate system axis positions "); } if (result != 0) return 1005; } status = rs274ngc_open(m_InFile); if (status != RS274NGC_OK) return rs274ErrorExit(status); if (_setup.percent_flag == ON) m_GCodeReads = 1; else m_GCodeReads = 0; for( ; m_GCodeReads<m_CurrentLine ; m_GCodeReads++) { read_ok = fgets(trash, INTERP_TEXT_SIZE,_setup.file_pointer); if (!read_ok) { strcpy(ErrorOutput,"Error while reading GCode file "); return NCE_A_FILE_IS_ALREADY_OPEN; } } CoordMotion->m_realtime_Sequence_number_valid=false; ExecutionInProgress=true; SetupTracker.ClearHistory(); _setup.current_line=m_GCodeReads; for( ; ; m_GCodeReads++) { // record what line we are doing in the GCode _setup.current_line = m_CurrentLine = m_GCodeReads; SetupTracker.InsertState(&_setup); // save the interpreter state // give output to caller #ifndef _KMOTIONX //not needed on linux CString tmpStr = Output; tmpStr.Replace("\n","\r\n"); strcpy(Output, tmpStr); #endif m_StatusFn(m_CurrentLine,Output); Output[0]='\0'; // clear it if (((m_end!=-1)&&(m_CurrentLine>m_end)) || (CoordMotion->m_Simulate && m_Halt) || CoordMotion->GetAbort() || m_HaltNextLine) { rs274ngc_close(); return 0; } status = rs274ngc_read(); if (status == RS274NGC_ENDFILE) { rs274ngc_close(); return RS274NGC_ENDFILE; } if (status != RS274NGC_OK) return rs274ErrorExit(status); status = rs274ngc_execute(NULL); SaveStateOnceOnly(); // if it wasn't saved before first motion then save it now if (m_CurrentLine != _setup.current_line) { // line number changed if (m_end!=-1) m_end += _setup.current_line - m_CurrentLine; m_GCodeReads = m_CurrentLine = _setup.current_line; // get back line no (in case we called a subroutine) } if (CoordMotion->GetAbort()) return rs274ErrorExit(status); if (status == RS274NGC_EXIT) { rs274ngc_close(); _setup.current_line = m_CurrentLine = 0; // reset back to the beginning return program_status; } if (status != RS274NGC_OK) return rs274ErrorExit(status); // successfully executed one line clear stopped status if (!CoordMotion->GetAbort()) CoordMotion->m_PreviouslyStopped = STOPPED_NONE; } return 0; }
int interpret_from_file( /* ARGUMENTS */ int do_next, /* what to do if error */ int block_delete, /* switch which is ON or OFF */ int print_stack) /* option which is ON or OFF */ { int status; char line[RS274NGC_TEXT_SIZE]; for(; ;) { status SET_TO rs274ngc_read(NULL); if ((status IS RS274NGC_EXECUTE_FINISH) AND (block_delete IS ON)) continue; else if (status IS RS274NGC_ENDFILE) break; if ((status ISNT RS274NGC_OK) AND // should not be EXIT (status ISNT RS274NGC_EXECUTE_FINISH)) { report_error(status, print_stack); if ((status IS NCE_FILE_ENDED_WITH_NO_PERCENT_SIGN) OR (do_next IS 2)) /* 2 means stop */ { status SET_TO 1; break; } else if (do_next IS 1) /* 1 means MDI */ { fprintf(stderr, "starting MDI\n"); interpret_from_keyboard(block_delete, print_stack); fprintf(stderr, "continue program? y/n =>"); fgets(line, sizeof(line), stdin); if (line[0] ISNT 'y') { status SET_TO 1; break; } else continue; } else /* if do_next IS 0 -- 0 means continue */ continue; } status SET_TO rs274ngc_execute(); if ((status ISNT RS274NGC_OK) AND (status ISNT RS274NGC_EXIT) AND (status ISNT RS274NGC_EXECUTE_FINISH)) { report_error(status, print_stack); status SET_TO 1; if (do_next IS 1) /* 1 means MDI */ { fprintf(stderr, "starting MDI\n"); interpret_from_keyboard(block_delete, print_stack); fprintf(stderr, "continue program? y/n =>"); fgets(line,sizeof(line), stdin); if (line[0] ISNT 'y') break; } else if (do_next IS 2) /* 2 means stop */ break; } else if (status IS RS274NGC_EXIT) break; } return ((status IS 1) ? 1 : 0); }