📄 rs274ngc_pre.cc
字号:
strcpy(line, filename); strcat(line, RS274NGC_PARAMETER_FILE_BACKUP_SUFFIX); CHK((rename(filename, line) != 0), NCE_CANNOT_CREATE_BACKUP_FILE); // open backup for reading infile = fopen(line, "r"); CHK((infile == NULL), NCE_CANNOT_OPEN_BACKUP_FILE); // open original for writing outfile = fopen(filename, "w"); CHK((outfile == NULL), NCE_CANNOT_OPEN_VARIABLE_FILE); k = 0; index = 0; required = _required_parameters[index++]; while (feof(infile) == 0) { if (fgets(line, 256, infile) == NULL) { break; } // try for a variable-value match if (sscanf(line, "%d %lf", &variable, &value) == 2) { CHK(((variable <= 0) || (variable >= RS274NGC_MAX_PARAMETERS)), NCE_PARAMETER_NUMBER_OUT_OF_RANGE); for (; k < RS274NGC_MAX_PARAMETERS; k++) { if (k > variable) ERM(NCE_PARAMETER_FILE_OUT_OF_ORDER); else if (k == variable) { sprintf(line, "%d\t%f\n", k, parameters[k]); fputs(line, outfile); if (k == required) required = _required_parameters[index++]; k++; break; } else if (k == required) // know (k < variable) { sprintf(line, "%d\t%f\n", k, parameters[k]); fputs(line, outfile); required = _required_parameters[index++]; } } } } fclose(infile); for (; k < RS274NGC_MAX_PARAMETERS; k++) { if (k == required) { sprintf(line, "%d\t%f\n", k, parameters[k]); fputs(line, outfile); required = _required_parameters[index++]; } } fclose(outfile); return INTERP_OK;}/***********************************************************************//*! Interp::synchReturned Value: int (INTERP_OK)Side Effects: sets the value of many attribute of _setup by calling various GET_EXTERNAL_xxx functions.Called By: Interp::init external programsThis function gets the _setup world model in synch with the rest ofthe controller.*/int Interp::synch(){ char file_name[LINELEN]; _setup.control_mode = GET_EXTERNAL_MOTION_CONTROL_MODE(); _setup.AA_current = GET_EXTERNAL_POSITION_A(); _setup.BB_current = GET_EXTERNAL_POSITION_B(); _setup.CC_current = GET_EXTERNAL_POSITION_C(); _setup.current_slot = GET_EXTERNAL_TOOL_SLOT(); _setup.current_x = GET_EXTERNAL_POSITION_X(); _setup.current_y = GET_EXTERNAL_POSITION_Y(); _setup.current_z = GET_EXTERNAL_POSITION_Z(); _setup.feed_rate = GET_EXTERNAL_FEED_RATE(); _setup.flood = (GET_EXTERNAL_FLOOD() != 0) ? ON : OFF; _setup.length_units = GET_EXTERNAL_LENGTH_UNIT_TYPE(); _setup.mist = (GET_EXTERNAL_MIST() != 0) ? ON : OFF; _setup.plane = GET_EXTERNAL_PLANE(); _setup.selected_tool_slot = GET_EXTERNAL_SELECTED_TOOL_SLOT(); _setup.speed = GET_EXTERNAL_SPEED(); _setup.spindle_turning = GET_EXTERNAL_SPINDLE(); _setup.tool_max = GET_EXTERNAL_TOOL_MAX(); _setup.traverse_rate = GET_EXTERNAL_TRAVERSE_RATE(); GET_EXTERNAL_PARAMETER_FILE_NAME(file_name, (LINELEN - 1)); save_parameters(((file_name[0] == 0) ? RS274NGC_PARAMETER_FILE_NAME_DEFAULT : file_name), _setup.parameters); load_tool_table(); /* must set _setup.tool_max first */ return INTERP_OK;}/***********************************************************************//***********************************************************************//*The functions in this section are to extract information from theinterpreter.*//***********************************************************************//*! Interp::active_g_codesReturned Value: noneSide Effects: copies active G codes into the codes arrayCalled By: external programsSee documentation of write_g_codes.*/void Interp::active_g_codes(int *codes) //!< array of codes to copy into{ int n; for (n = 0; n < ACTIVE_G_CODES; n++) { codes[n] = _setup.active_g_codes[n]; }}/***********************************************************************//*! Interp::active_m_codesReturned Value: noneSide Effects: copies active M codes into the codes arrayCalled By: external programsSee documentation of write_m_codes.*/void Interp::active_m_codes(int *codes) //!< array of codes to copy into{ int n; for (n = 0; n < ACTIVE_M_CODES; n++) { codes[n] = _setup.active_m_codes[n]; }}/***********************************************************************//*! Interp::active_settingsReturned Value: noneSide Effects: copies active F, S settings into arrayCalled By: external programsSee documentation of write_settings.*/void Interp::active_settings(double *settings) //!< array of settings to copy into{ int n; for (n = 0; n < ACTIVE_SETTINGS; n++) { settings[n] = _setup.active_settings[n]; }}/***********************************************************************//*! Interp::error_textReturned Value: noneSide Effects: see belowCalled By: external programsThis copies the error string whose index in the _rs274ngc_errors arrayis error_code into the error_text array -- unless the error_code isan out-of-bounds index or the length of the error string is not lessthan max_size, in which case an empty string is put into theerror_text. The length of the error_text array should be at leastmax_size.*/void Interp::error_text(int error_code, //!< code number of error char *error_text, //!< char array to copy error text into int max_size) //!< maximum number of characters to copy{ if (((error_code >= INTERP_MIN_ERROR) && (error_code <= RS274NGC_MAX_ERROR)) && (strlen(_rs274ngc_errors[error_code]) < ((size_t) max_size))) { strcpy(error_text, _rs274ngc_errors[error_code]); } else error_text[0] = 0;}/***********************************************************************//*! Interp::file_nameReturned Value: noneSide Effects: see belowCalled By: external programsThis copies the _setup.filename (the name of the currently openfile) into the file_name array -- unless the name is not shorter thanmax_size, in which case a null string is put in the file_name array.*/void Interp::file_name(char *file_name, //!< string: to copy file name into int max_size) //!< maximum number of characters to copy{ if (strlen(_setup.filename) < ((size_t) max_size)) strcpy(file_name, _setup.filename); else file_name[0] = 0;}/***********************************************************************//*! Interp::line_lengthReturned Value: the length of the most recently read lineSide Effects: noneCalled By: external programs*/int Interp::line_length(){ return _setup.line_length;}/***********************************************************************//*! Interp::line_textReturned Value: noneSide Effects: See belowCalled By: external programsThis copies at most (max_size - 1) non-null characters of the mostrecently read line into the line_text string and puts a NULL after thelast non-null character.*/void Interp::line_text(char *line_text, //!< string: to copy line into int max_size) //!< maximum number of characters to copy{ int n; char *the_text; the_text = _setup.linetext; for (n = 0; n < (max_size - 1); n++) { if (the_text[n] != 0) line_text[n] = the_text[n]; else break; } line_text[n] = 0;}/***********************************************************************//*! Interp::sequence_numberReturned Value: the current interpreter sequence number (how manylines read since the last time the sequence number was reset to zero,which happens only when Interp::init or Interp::open is called).Side Effects: noneCalled By: external programs*/int Interp::sequence_number(){ return _setup.sequence_number;}/***********************************************************************//*! Interp::stack_nameReturned Value: noneSide Effects: see belowCalled By: external programsThis copies at most (max_size - 1) non-null characters from thestring whose index in the _setup.stack array is stack_index into thefunction_name string and puts a NULL after the last non-null character --unless the stack_index is an out-of-bounds index, in which case anempty string is put into the function_name.This function is intended to be used several times in a row to get thestack of function calls that existed when the most recent erroroccurred. It should be called first with stack_index equal to 0,next with stack_index equal to 1, and so on, stopping when anempty string is returned for the name.*/void Interp::stack_name(int stack_index, //!< index into stack of function names char *function_name, //!< string: to copy function name into int max_size) //!< maximum number of characters to copy{ int n; char *the_name; if ((stack_index > -1) && (stack_index < 20)) { the_name = _setup.stack[stack_index]; for (n = 0; n < (max_size - 1); n++) { if (the_name[n] != 0) function_name[n] = the_name[n]; else break; } function_name[n] = 0; } else function_name[0] = 0;}/***********************************************************************//* Interp::ini_load()Returned Value: INTERP_OK, RS274NGC_ERRORSide Effects: An INI file containing values for global variables is used to update the globalsCalled By: Interp::init()The file looks like this:[RS274NGC]VARIABLE_FILE = rs274ngc.var*/int Interp::ini_load(const char *filename){ Inifile inifile; const char *inistring; // open it if (inifile.open(filename) == false) { return -1; } if (NULL != (inistring = inifile.find("PARAMETER_FILE", "RS274NGC"))) { // found it strncpy(_parameter_file_name, inistring, LINELEN); } else { // not found, leave RS274NGC_PARAMETER_FILE alone } // close it inifile.close(); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -