rs274ngc_pre.cc
来自「CNC 的开放码,EMC2 V2.2.8版」· CC 代码 · 共 1,399 行 · 第 1/3 页
CC
1,399 行
//_setup.parameter_values does not need initialization//_setup.percent_flag does not need initialization//_setup.plane set in Interp::synch _setup.probe_flag = OFF; _setup.toolchange_flag = OFF; _setup.input_flag = OFF; _setup.input_index = -1; _setup.input_digital = OFF; _setup.program_x = 0.; /* for cutter comp */ _setup.program_y = 0.; /* for cutter comp */ _setup.program_z = 0.; /* for cutter comp */ _setup.cutter_comp_firstmove = ON;//_setup.retract_mode does not need initialization//_setup.selected_tool_slot set in Interp::synch _setup.sequence_number = 0; /*DOES THIS NEED TO BE AT TOP? *///_setup.speed set in Interp::synch _setup.speed_feed_mode = CANON_INDEPENDENT;//_setup.speed_override set in Interp::synch//_setup.spindle_turning set in Interp::synch//_setup.stack does not need initialization//_setup.stack_index does not need initialization _setup.tool_xoffset = 0.0; _setup.tool_zoffset = 0.0;//_setup.tool_max set in Interp::synch//_setup.tool_table set in Interp::synch//_setup.traverse_rate set in Interp::synch//_setup.adaptive_feed set in Interp::synch//_setup.feed_hold set in Interp::synch // initialization stuff for subroutines and control structures _setup.call_level = 0; _setup.defining_sub = 0; _setup.skipping_o = 0; _setup.oword_labels = 0; memcpy(_readers, default_readers, sizeof(default_readers)); long axis_mask = GET_EXTERNAL_AXIS_MASK(); if(!(axis_mask & AXIS_MASK_X)) _readers[(int)'x'] = 0; if(!(axis_mask & AXIS_MASK_Y)) _readers[(int)'y'] = 0; if(!(axis_mask & AXIS_MASK_Z)) _readers[(int)'z'] = 0; if(!(axis_mask & AXIS_MASK_A)) _readers[(int)'a'] = 0; if(!(axis_mask & AXIS_MASK_B)) _readers[(int)'b'] = 0; if(!(axis_mask & AXIS_MASK_C)) _readers[(int)'c'] = 0; if(!(axis_mask & AXIS_MASK_U)) _readers[(int)'u'] = 0; if(!(axis_mask & AXIS_MASK_V)) _readers[(int)'v'] = 0; if(!(axis_mask & AXIS_MASK_W)) _readers[(int)'w'] = 0; synch(); //synch first, then update the interface write_g_codes((block_pointer) NULL, &_setup); write_m_codes((block_pointer) NULL, &_setup); write_settings(&_setup); // Synch rest of settings to external world return INTERP_OK;}/***********************************************************************//*! Interp::load_tool_tableReturned Value: int If any of the following errors occur, this returns the error code shown. Otherwise, this returns INTERP_OK. 1. _setup.tool_max is larger than CANON_TOOL_MAX: NCE_TOOL_MAX_TOO_LARGESide Effects: _setup.tool_table[] is modified.Called By: Interp::synch external programsThis function calls the canonical interface function GET_EXTERNAL_TOOL_TABLEto load the whole tool table into the _setup.The CANON_TOOL_MAX is an upper limit for this software. The_setup.tool_max is intended to be set for a particular machine.*/int Interp::load_tool_table(){ static char name[] = "Interp::load_tool_table"; int n; CHK((_setup.tool_max > CANON_TOOL_MAX), NCE_TOOL_MAX_TOO_LARGE); for (n = 0; n <= _setup.tool_max; n++) { _setup.tool_table[n] = GET_EXTERNAL_TOOL_TABLE(n); } for (; n <= CANON_TOOL_MAX; n++) { _setup.tool_table[n].id = 0; _setup.tool_table[n].xoffset = 0; _setup.tool_table[n].zoffset = 0; _setup.tool_table[n].diameter = 0; _setup.tool_table[n].orientation = 0; _setup.tool_table[n].frontangle = 0; _setup.tool_table[n].backangle = 0; } return INTERP_OK;}/***********************************************************************//*! Interp::openReturned Value: int If any of the following errors occur, this returns the error code shown. Otherwise it returns INTERP_OK. 1. A file is already open: NCE_A_FILE_IS_ALREADY_OPEN 2. The name of the file is too long: NCE_FILE_NAME_TOO_LONG 3. The file cannot be opened: NCE_UNABLE_TO_OPEN_FILESide Effects: See belowCalled By: external programsThe file is opened for reading and _setup.file_pointer is set.The file name is copied into _setup.filename.The _setup.sequence_number, is set to zero.Interp::reset() is called, changing several more _setup attributes.The manual [NCMS, page 3] discusses the use of the "%" character at thebeginning of a "tape". It is not clear whether it is intended thatevery NC-code file should begin with that character.In the following, "uses percents" means the first non-blank lineof the file must consist of nothing but the percent sign, with optionalleading and trailing white space, and there must be a second lineof the same sort later on in the file. If a file uses percents,execution stops at the second percent line. Any lines after thesecond percent line are ignored.In this interpreter (recalling that M2 and M30 always ends execution):1. If execution of a file is ended by M2 or M30 (not necessarily onthe last line of the file), then it is optional that the fileuses percents.2. If execution of a file is not ended by M2 or M30, then it isrequired that the file uses percents.If the file being opened uses percents, this function turns on the_setup.percent flag, reads any initial blank lines, and reads thefirst line with the "%". If not, after reading enough to determinethat, this function puts the file pointer back at the beginning of thefile.*/int Interp::open(const char *filename) //!< string: the name of the input NC-program file{ static char name[] = "Interp::open"; char *line; int index; int length; CHK((_setup.file_pointer != NULL), NCE_A_FILE_IS_ALREADY_OPEN); CHK((strlen(filename) > (LINELEN - 1)), NCE_FILE_NAME_TOO_LONG); _setup.file_pointer = fopen(filename, "r"); CHK((_setup.file_pointer == NULL), NCE_UNABLE_TO_OPEN_FILE); line = _setup.linetext; for (index = -1; index == -1;) { /* skip blank lines */ CHK((fgets(line, LINELEN, _setup.file_pointer) == NULL), NCE_FILE_ENDED_WITH_NO_PERCENT_SIGN); length = strlen(line); if (length == (LINELEN - 1)) { // line is too long. need to finish reading the line to recover for (; fgetc(_setup.file_pointer) != '\n';); // could look for EOF ERM(NCE_COMMAND_TOO_LONG); } for (index = (length - 1); // index set on last char (index >= 0) && (isspace(line[index])); index--); } if (line[index] == '%') { for (index--; (index >= 0) && (isspace(line[index])); index--); if (index == -1) { _setup.percent_flag = ON; _setup.sequence_number = 1; // We have already read the first line // and we are not going back to it. } else { fseek(_setup.file_pointer, 0, SEEK_SET); _setup.percent_flag = OFF; _setup.sequence_number = 0; // Going back to line 0 } } else { fseek(_setup.file_pointer, 0, SEEK_SET); _setup.percent_flag = OFF; _setup.sequence_number = 0; // Going back to line 0 } strcpy(_setup.filename, filename); reset(); return INTERP_OK;}/***********************************************************************//*! Interp::readReturned Value: int If any of the following errors occur, this returns the error code shown. Otherwise, this returns: a. INTERP_ENDFILE if the only non-white character on the line is %, b. INTERP_EXECUTE_FINISH if the first character of the close_and_downcased line is a slash, and c. INTERP_OK otherwise. 1. The command and_setup.file_pointer are both NULL: INTERP_FILE_NOT_OPEN 2. The probe_flag is ON but the HME command queue is not empty: NCE_QUEUE_IS_NOT_EMPTY_AFTER_PROBING 3. If read_text (which gets a line of NC code from file) or parse_line (which parses the line) returns an error code, this returns that code.Side Effects: _setup.sequence_number is incremented. The _setup.block1 is filled with data.Called By: external programsThis reads a line of NC-code from the command string or, (if thecommand string is NULL) from the currently open file. The_setup.line_length will be set by read_text. This will be zero if theline is blank or consists of nothing but a slash. If the length is notzero, this parses the line into the _setup.block1.*/int Interp::read(const char *command) //!< may be NULL or a string to read{ static char name[] = "Interp::read"; int status; int read_status; if (_setup.probe_flag == ON) { CHK((GET_EXTERNAL_QUEUE_EMPTY() == 0), NCE_QUEUE_IS_NOT_EMPTY_AFTER_PROBING); set_probe_data(&_setup); _setup.probe_flag = OFF; } if (_setup.toolchange_flag == ON) { CHKF((GET_EXTERNAL_QUEUE_EMPTY() == 0), (_("Queue is not empty after tool change"))); refresh_actual_position(&_setup); _setup.toolchange_flag = OFF; } if (_setup.input_flag == ON) { CHK((GET_EXTERNAL_QUEUE_EMPTY() == 0), NCE_QUEUE_IS_NOT_EMPTY_AFTER_INPUT); if (_setup.input_digital == ON) { // we are checking for a digital input _setup.parameters[5399] = GET_EXTERNAL_DIGITAL_INPUT(_setup.input_index); } else { // checking for analog input _setup.parameters[5399] = GET_EXTERNAL_ANALOG_INPUT(_setup.input_index); } _setup.input_flag = OFF; } CHK(((command == NULL) && (_setup.file_pointer == NULL)), INTERP_FILE_NOT_OPEN); if(_setup.file_pointer) { _setup.block1.offset = ftell(_setup.file_pointer); } read_status = read_text(command, _setup.file_pointer, _setup.linetext, _setup.blocktext, &_setup.line_length); if(command)logDebug("%s:[cmd]:|%s|", name, command); else logDebug("%s:|%s|", name, _setup.linetext); if ((read_status == INTERP_EXECUTE_FINISH) || (read_status == INTERP_OK)) { if (_setup.line_length != 0) { CHP(parse_line(_setup.blocktext, &(_setup.block1), &_setup)); } else // Blank line (zero length) { /* RUM - this case reached when the block delete '/' character is used, or READ_FULL_COMMENT is OFF and a comment is the only content of a line. If a block o-type is in effect, block->o_number needs to be incremented to allow o-extensions to work. Note that the the block is 'refreshed' by init_block(), not created new, so this is a legal operation on block1. */ if (_setup.block1.o_type != O_none) { // Clear o_type, this isn't line isn't a command... _setup.block1.o_type = 0; // increment o_number _setup.block1.o_number++; } } } else if (read_status == INTERP_ENDFILE); else ERP(read_status); return read_status;}/***********************************************************************//*! Interp::resetReturned Value: int (INTERP_OK)Side Effects: See belowCalled By: external programs Interp::close Interp::exit Interp::openThis function resets the parts of the _setup model having to do withreading and interpreting one line. It does not affect the parts of themodel dealing with a file being open; Interp::open and Interp::closedo that.There is a hierarchy of resetting the interpreter. Each of the followingcalls does everything the ones above it do.Interp::reset()Interp::close()Interp::init()In addition, Interp::synch and Interp::restore_parameters (both ofwhich are called by Interp::init) change the model.*/int Interp::reset(){ _setup.linetext[0] = 0; _setup.blocktext[0] = 0; _setup.line_length = 0; // initialization stuff for subroutines and control structures _setup.call_level = 0; _setup.defining_sub = 0; _setup.skipping_o = 0; _setup.oword_labels = 0; return INTERP_OK;}/***********************************************************************//*! Interp::restore_parametersReturned Value: If any of the following errors occur, this returns the error code shown. Otherwise it returns INTERP_OK. 1. The parameter file cannot be opened for reading: NCE_UNABLE_TO_OPEN_FILE 2. A parameter index is out of range: NCE_PARAMETER_NUMBER_OUT_OF_RANGE 3. The parameter file is not in increasing order: NCE_PARAMETER_FILE_OUT_OF_ORDERSide Effects: See belowCalled By: external programs Interp::initThis function restores the parameters from a file, modifying theparameters array. Usually parameters is _setup.parameters. The filecontains lines of the form:<variable number> <value>e.g.5161 10.456The variable numbers must be in increasing order, and certainparameters must be included, as given in the _required_parametersarray. These are the axis offsets, the origin index (5220), and ninesets of origin offsets. Any parameter not given a value in the filehas its value set to zero.*/int Interp::restore_parameters(const char *filename) //!< name of parameter file to read { static char name[] = "Interp::restore_parameters"; FILE *infile; char line[256]; int variable; double value; int required; // number of next required parameter int index; // index into _required_parameters double *pars; // short name for _setup.parameters int k; // open original for reading infile = fopen(filename, "r"); CHK((infile == NULL), NCE_UNABLE_TO_OPEN_FILE); pars = _setup.parameters; 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 in the file 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) { pars[k] = value; if (k == required) required = _required_parameters[index++]; k++; break; } else // if (k < variable) { if (k == required) required = _required_parameters[index++]; pars[k] = 0; } } } } fclose(infile); for (; k < RS274NGC_MAX_PARAMETERS; k++) { pars[k] = 0; } return INTERP_OK;}/***********************************************************************//*! Interp::save_parametersReturned Value: If any of the following errors occur, this returns the error code shown. Otherwise it returns INTERP_OK. 1. The existing file cannot be renamed: NCE_CANNOT_CREATE_BACKUP_FILE 2. The renamed file cannot be opened to read: NCE_CANNOT_OPEN_BACKUP_FILE 3. The new file cannot be opened to write: NCE_CANNOT_OPEN_VARIABLE_FILE 4. A parameter index is out of range: NCE_PARAMETER_NUMBER_OUT_OF_RANGE 5. The renamed file is out of order: NCE_PARAMETER_FILE_OUT_OF_ORDERSide Effects: See belowCalled By: external programs Interp::exitA file containing variable-value assignments is updated. The oldversion of the file is saved under a different name. For eachvariable-value pair in the old file, a line is written in the new filegiving the current value of the variable. File lines have the form:<variable number> <value>e.g.5161 10.456If a required parameter is missing from the input file, this does notcomplain, but does write it in the output file.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?