📄 driver.cc
字号:
_tools[slot].zoffset = zoffset; _tools[slot].diameter = diameter; _tools[slot].xoffset = xoffset; _tools[slot].frontangle = frontangle; _tools[slot].backangle = backangle; _tools[slot].orientation = orientation; } else if (sscanf(buffer, "%d %d %lf %lf", &slot, &tool_id, &zoffset, &diameter) == 4 && slot >= 0 && slot < _tool_max) { _tools[slot].id = tool_id; _tools[slot].zoffset = zoffset; _tools[slot].diameter = diameter; _tools[slot].orientation = 0; //mill tool } else { if (slot < 0 || slot >= _tool_max) fprintf(stderr, "Out of range tool slot number %d\n", slot); else fprintf(stderr, "Bad input line \"%s\" in tool file\n", buffer); return 1; } } fclose(tool_file_port); return 0;}/************************************************************************//* designate_parameter_fileReturned Value: int If any of the following errors occur, this returns 1. Otherwise, it returns 0. 1. The file named by the user cannot be opened.Side Effects: The name of a parameter file given by the user is put in the parameter_file_name string.Called By: main*/int designate_parameter_file(char * parameter_file_name){ FILE * test_port; fprintf(stderr, "name of parameter file => "); fgets(parameter_file_name, PARAMETER_FILE_NAME_LENGTH, stdin); parameter_file_name[strlen(parameter_file_name) - 1] = 0; test_port = fopen(parameter_file_name, "r"); if (test_port == NULL) { fprintf(stderr, "Cannot open %s\n", parameter_file_name); return 1; } fclose(test_port); return 0;}/************************************************************************//* adjust_error_handlingReturned Value: int (0)Side Effects: The values of print_stack and do_next are set.Called By: mainThis function allows the user to set one or two aspects of error handling.By default the driver does not print the function stack in case of error.This function always allows the user to turn stack printing on if it is offor to turn stack printing off if it is on.When interpreting from the keyboard, the driver always goes ahead if thereis an error.When interpreting from a file, the default behavior is to stop in case ofan error. If the user is interpreting from a file (indicated by args being2 or 3), this lets the user change what it does on an error.If the user has not asked for output to a file (indicated by args being 2),the user can choose any of three behaviors in case of an error (1) continue,(2) stop, (3) go into MDI mode. This function allows the user to cycle amongthe three.If the user has asked for output to a file (indicated by args being 3),the user can choose any of two behaviors in case of an error (1) continue,(2) stop. This function allows the user to toggle between the two.*/int adjust_error_handling( int args, int * print_stack, int * do_next){ char buffer[80]; int choice; for(;;) { fprintf(stderr, "enter a number:\n"); fprintf(stderr, "1 = done with error handling\n"); fprintf(stderr, "2 = %sprint stack on error\n", ((*print_stack == ON) ? "do not " : "")); if (args == 3) { if (*do_next == 0) /* 0 means continue */ fprintf(stderr, "3 = stop on error (do not continue)\n"); else /* if do_next == 2 -- 2 means stopping on error */ fprintf(stderr, "3 = continue on error (do not stop)\n"); } else if (args == 2) { if (*do_next == 0) /* 0 means continue */ fprintf(stderr, "3 = mdi on error (do not continue or stop)\n"); else if (*do_next == 1) /* 1 means MDI */ fprintf(stderr, "3 = stop on error (do not mdi or continue)\n"); else /* if do_next == 2 -- 2 means stopping on error */ fprintf(stderr, "3 = continue on error (do not stop or mdi)\n"); } fprintf(stderr, "enter choice => "); fgets(buffer, 80, stdin); if (sscanf(buffer, "%d", &choice) != 1) continue; if (choice == 1) break; else if (choice == 2) *print_stack = ((*print_stack == OFF) ? ON : OFF); else if ((choice == 3) && (args == 3)) *do_next = ((*do_next == 0) ? 2 : 0); else if ((choice == 3) && (args == 2)) *do_next = ((*do_next == 2) ? 0 : (*do_next + 1)); } return 0;}/************************************************************************//* mainThe executable exits with either 0 (under all conditions not listedbelow) or 1 (under the following conditions):1. A fatal error occurs while interpreting from a file.2. Read_tool_file fails.3. An error occurs in interp_init.***********************************************************************Here are three ways in which the rs274 executable may be called.Any other sort of call to the executable will cause an error messageto be printed and the interpreter will not run. Other executablesmay be called similarly.1. If the rs274 stand-alone executable is called with no arguments,input is taken from the keyboard, and an error in the input does notcause the rs274 executable to exit.EXAMPLE:1A. To interpret from the keyboard, enter:rs274***********************************************************************2. If the executable is called with one argument, the argument istaken to be the name of an NC file and the file is interpreted asdescribed in the documentation of interpret_from_file.EXAMPLES:2A. To interpret the file "cds.abc" and read the results on thescreen, enter:rs274 cds.abc2B. To interpret the file "cds.abc" and print the results in the file"cds.prim", enter:rs274 cds.abc > cds.prim***********************************************************************Whichever way the executable is called, this gives the user severalchoices before interpretation starts1 = start interpreting2 = choose parameter file3 = read tool file ...4 = turn block delete switch ON5 = adjust error handling...Interpretation starts when option 1 is chosen. Until that happens, theuser is repeatedly given the five choices listed above. Item 4toggles between "turn block delete switch ON" and "turn block deleteswitch OFF". See documentation of adjust_error_handling regardingwhat option 5 does.User instructions are printed to stderr (with fprintf) so that outputcan be redirected to a file. When output is redirected and userinstructions are printed to stdout (with printf), the instructions getredirected and the user does not see them.*/int main (int argc, char ** argv){ int status; int choice; int do_next; /* 0=continue, 1=mdi, 2=stop */ int block_delete; char buffer[80]; int tool_flag; int gees[ACTIVE_G_CODES]; int ems[ACTIVE_M_CODES]; double sets[ACTIVE_SETTINGS]; char default_name[] = EMC2_HOME "/configs/sim/sim.var"; int print_stack; int go_flag; do_next = 2; /* 2=stop */ block_delete = OFF; print_stack = OFF; tool_flag = 0; strcpy(_parameter_file_name, default_name); _outfile = stdout; /* may be reset below */ go_flag = 0; while(1) { int c = getopt(argc, argv, "t:v:bsn:g"); if(c == -1) break; switch(c) { case 't': read_tool_file(optarg); tool_flag=1; break; case 'v': strcpy(_parameter_file_name, optarg); break; case 'b': block_delete = (block_delete == OFF) ? ON : OFF; break; case 's': print_stack = (print_stack == OFF) ? ON : OFF; break; case 'n': do_next = atoi(optarg); break; case 'g': go_flag = !go_flag; break; case '?': default: goto usage; } } if (argc - optind > 3) {usage: fprintf(stderr, "Usage: %s [-t tool.tbl] [-v var-file.var] [-n 0|1|2]\n" " [-b] [-s] [-g] [input file [output file]]\n" "\n" " -t: Specify the .tbl (tool table) file to use\n" " -v: Specify the .var (parameter) file to use\n" " -n: Specify the continue mode:\n" " 0: continue\n" " 1: enter MDI mode\n" " 2: stop (default)\n" " -b: Toggle the 'block delete' flag (default: ON)\n" " -s: Toggle the 'print stack' flag (default: ON)\n" " -g: Toggle the 'go (batch mode)' flag (default: OFF)\n" , argv[0]); exit(1); } for(; !go_flag ;) { fprintf(stderr, "enter a number:\n"); fprintf(stderr, "1 = start interpreting\n"); fprintf(stderr, "2 = choose parameter file ...\n"); fprintf(stderr, "3 = read tool file ...\n"); fprintf(stderr, "4 = turn block delete switch %s\n", ((block_delete == OFF) ? "ON" : "OFF")); fprintf(stderr, "5 = adjust error handling...\n"); fprintf(stderr, "enter choice => "); fgets(buffer, 80, stdin); if (sscanf(buffer, "%d", &choice) != 1) continue; if (choice == 1) break; else if (choice == 2) { if (designate_parameter_file(_parameter_file_name) != 0) exit(1); } else if (choice == 3) { if (read_tool_file("") != 0) exit(1); tool_flag = 1; } else if (choice == 4) block_delete = ((block_delete == OFF) ? ON : OFF); else if (choice == 5) adjust_error_handling(argc, &print_stack, &do_next); } fprintf(stderr, "executing\n"); if (tool_flag == 0) { if (read_tool_file(EMC2_HOME "/configs/sim/sim.tbl") != 0) exit(1); } // Skip past arguments used up by getopt() */ argc = argc - optind + 1; argv = argv + optind - 1; if (argc == 3) { _outfile = fopen(argv[2], "w"); if (_outfile == NULL) { fprintf(stderr, "could not open output file %s\n", argv[2]); exit(1); } } if ((status = interp_init()) != INTERP_OK) { report_error(status, print_stack); exit(1); } if (argc == 1) status = interpret_from_keyboard(block_delete, print_stack); else /* if (argc == 2 or argc == 3) */ { status = interp_open(argv[1]); if (status != INTERP_OK) /* do not need to close since not open */ { report_error(status, print_stack); exit(1); } status = interpret_from_file(do_next, block_delete, print_stack); file_name(buffer, 5); /* called to exercise the function */ file_name(buffer, 79); /* called to exercise the function */ interp_close(); } line_length(); /* called to exercise the function */ sequence_number(); /* called to exercise the function */ active_g_codes(gees); /* called to exercise the function */ active_m_codes(ems); /* called to exercise the function */ active_settings(sets); /* called to exercise the function */ interp_exit(); /* saves parameters */ exit(status);}/***********************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -