📄 iosh.cc
字号:
Tcl_Obj * CONST objv[]){ int toolInSpindle; if (objc != 2) { Tcl_SetResult(interp, "emc_io_status_tool_in_spindle: need tool", TCL_VOLATILE); return TCL_ERROR; } if (TCL_OK == Tcl_GetIntFromObj(0, objv[1], &toolInSpindle)) { emcioStatus.tool.toolInSpindle = toolInSpindle; return TCL_OK; } Tcl_SetResult(interp, "emc_io_status_tool_in_spindle: need tool", TCL_VOLATILE); return TCL_ERROR;}/*Load the tool table file*/static int emc_io_load_tool_table(ClientData clientdata, Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[]){ if (objc != 1) { Tcl_SetResult(interp, "emc_io_load_tool_table: need no args", TCL_VOLATILE); return TCL_ERROR; } if (0 == loadToolTable(TOOL_TABLE_FILE, emcioStatus.tool.toolTable)) { return TCL_OK; } Tcl_SetResult(interp, "Error reading tool table", TCL_VOLATILE); return TCL_ERROR;}/*#####################################################################################*//* IO commands*//*#####################################################################################*/static int unpriv = 0; // non-zero means can't read IO// note the leading f_ so we don't conflict with real inbstatic int f_inb(ClientData clientdata, Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[]){ long address; if (objc == 2) { if (TCL_OK == Tcl_GetLongFromObj(0, objv[1], &address)) { if (unpriv) { Tcl_SetObjResult(interp, Tcl_NewIntObj(0xFF)); return TCL_OK; } Tcl_SetObjResult(interp, Tcl_NewIntObj((int) inb(address))); return TCL_OK; } } Tcl_SetResult(interp, "syntax: inb <address>", TCL_VOLATILE); return TCL_ERROR;}// note the leading f_ so we don't conflict with real outbstatic int f_outb(ClientData clientdata, Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[]){ long address; int value; if (objc == 3) { if (TCL_OK == Tcl_GetLongFromObj(0, objv[1], &address) && TCL_OK == Tcl_GetIntFromObj(0, objv[2], &value)) { if (unpriv) { return TCL_OK; } outb((char) value, address); return TCL_OK; } } Tcl_SetResult(interp, "syntax: outb <address> <value>", TCL_VOLATILE); return TCL_ERROR;}// note the leading f_ so we don't conflict with real inwstatic int f_inw(ClientData clientdata, Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[]){ long address; if (objc == 2) { if (TCL_OK == Tcl_GetLongFromObj(0, objv[1], &address)) { if (unpriv) { Tcl_SetObjResult(interp, Tcl_NewIntObj(0xFFFF)); return TCL_OK; } Tcl_SetObjResult(interp, Tcl_NewIntObj((int) inw(address))); return TCL_OK; } } Tcl_SetResult(interp, "syntax: inw <address>", TCL_VOLATILE); return TCL_ERROR;}// note the leading f_ so we don't conflict with real outwstatic int f_outw(ClientData clientdata, Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[]){ long address; int value; if (objc == 3) { if (TCL_OK == Tcl_GetLongFromObj(0, objv[1], &address) && TCL_OK == Tcl_GetIntFromObj(0, objv[2], &value)) { if (unpriv) { return TCL_OK; } outw((short) value, address); return TCL_OK; } } Tcl_SetResult(interp, "syntax: outw <address> <value>", TCL_VOLATILE); return TCL_ERROR;}// note the leading f_ so we don't conflict with real inlstatic int f_inl(ClientData clientdata, Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[]){ long address; if (objc == 2) { if (TCL_OK == Tcl_GetLongFromObj(0, objv[1], &address)) { if (unpriv) { Tcl_SetObjResult(interp, Tcl_NewLongObj(0xFFFFFFFF)); return TCL_OK; } Tcl_SetObjResult(interp, Tcl_NewLongObj(inl(address))); return TCL_OK; } } Tcl_SetResult(interp, "syntax: inl <address>", TCL_VOLATILE); return TCL_ERROR;}// note the leading f_ so we don't conflict with real outlstatic int f_outl(ClientData clientdata, Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[]){ long address; long value; if (objc == 3) { if (TCL_OK == Tcl_GetLongFromObj(0, objv[1], &address) && TCL_OK == Tcl_GetLongFromObj(0, objv[2], &value)) { if (unpriv) { return TCL_OK; } outl(value, address); return TCL_OK; } } Tcl_SetResult(interp, "syntax: outl <address> <value>", TCL_VOLATILE); return TCL_ERROR;}static int emc_mot_shmem(ClientData clientdata, Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[]){ if (objc == 1) { if (unpriv) { Tcl_SetObjResult(interp, Tcl_NewLongObj(0xFFFFFFFF)); return TCL_OK; } Tcl_SetObjResult(interp, Tcl_NewLongObj(shmem)); return TCL_OK; } Tcl_SetResult(interp, "emc_mot_shmem: need no args", TCL_VOLATILE); return TCL_ERROR;}/* raw input no longer exists *//*! \todo Another #if 0 */#if 0static int emc_mot_rawinput(ClientData clientdata, Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[]){ int axis; if (objc == 2) { if (TCL_OK == Tcl_GetIntFromObj(0, objv[1], &axis)) { if (shmem > 0) { Tcl_SetObjResult(interp, Tcl_NewDoubleObj(emcmotshmem->debug. rawInput[axis])); return TCL_OK; } else { Tcl_SetObjResult(interp, Tcl_NewDoubleObj(0)); return TCL_OK; } } } Tcl_SetResult(interp, "syntax: emc_mot_rawinput <axis>", TCL_VOLATILE); return TCL_ERROR;}#endifstatic int emc_mot_move(ClientData clientdata, Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[]){ int axis; double move; double vel; if (objc == 4) { if (TCL_OK != Tcl_GetIntFromObj(0, objv[1], &axis)) { return TCL_ERROR; } if (TCL_OK != Tcl_GetDoubleFromObj(0, objv[2], &move)) { return TCL_ERROR; } if (TCL_OK != Tcl_GetDoubleFromObj(0, objv[3], &vel)) { return TCL_ERROR; }// Set the velocity emcmotCommand.vel = vel; emcmotCommand.command = EMCMOT_SET_VEL; usrmotWriteEmcmotCommand(&emcmotCommand);// Get the current position emcmotCommand.pos.tran.x = emcmotshmem->status.carte_pos_fb.tran.x; emcmotCommand.pos.tran.y = emcmotshmem->status.carte_pos_fb.tran.y; emcmotCommand.pos.tran.z = emcmotshmem->status.carte_pos_fb.tran.z;// Program the move switch (axis) { case 0: emcmotCommand.pos.tran.x = move; break; case 1: emcmotCommand.pos.tran.y = move; break; case 2: emcmotCommand.pos.tran.z = move; break; } emcmotCommand.id = emcmotshmem->status.id++; emcmotCommand.command = EMCMOT_SET_LINE; usrmotWriteEmcmotCommand(&emcmotCommand); return TCL_OK; } Tcl_SetResult(interp, "syntax: emc_mot_move <axis> <position> <velocity>", TCL_VOLATILE); return TCL_ERROR;}int Tcl_AppInit(Tcl_Interp * interp){ /* * Call the init procedures for included packages. Each call should * look like this: * * if (Mod_Init(interp) == TCL_ERROR) { * return TCL_ERROR; * } * * where "Mod" is the name of the module. */ if (Tcl_Init(interp) == TCL_ERROR) { return TCL_ERROR; } if (Tk_Init(interp) == TCL_ERROR) { return TCL_ERROR; } /* * Call Tcl_CreateCommand for application-specific commands, if * they weren't already created by the init procedures called above. */ Tcl_CreateObjCommand(interp, "emc_ini", emc_ini, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); Tcl_CreateObjCommand(interp, "emc_io_connect", emc_io_connect, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); Tcl_CreateObjCommand(interp, "emc_io_disconnect", emc_io_disconnect, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); Tcl_CreateObjCommand(interp, "emc_io_read_command", emc_io_read_command, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); Tcl_CreateObjCommand(interp, "emc_io_get_command", emc_io_get_command, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); Tcl_CreateObjCommand(interp, "emc_io_get_command_type", emc_io_get_command_type, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); Tcl_CreateObjCommand(interp, "emc_io_get_serial_number", emc_io_get_serial_number, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); Tcl_CreateObjCommand(interp, "emc_io_write_status", emc_io_write_status, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); Tcl_CreateObjCommand(interp, "emc_io_write_error", emc_io_write_error, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); Tcl_CreateObjCommand(interp, "emc_io_status_heartbeat", emc_io_status_heartbeat, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); Tcl_CreateObjCommand(interp, "emc_io_status_command_type", emc_io_status_command_type, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); Tcl_CreateObjCommand(interp, "emc_io_status_echo_serial_number", emc_io_status_echo_serial_number, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); Tcl_CreateObjCommand(interp, "emc_io_status_status", emc_io_status_status, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); Tcl_CreateObjCommand(interp, "emc_io_status_estop", emc_io_status_estop, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); Tcl_CreateObjCommand(interp, "emc_io_status_mist", emc_io_status_mist, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); Tcl_CreateObjCommand(interp, "emc_io_status_flood", emc_io_status_flood, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); Tcl_CreateObjCommand(interp, "emc_io_status_lube", emc_io_status_lube, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); Tcl_CreateObjCommand(interp, "emc_io_status_lube_level", emc_io_status_lube_level, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); Tcl_CreateObjCommand(interp, "emc_io_status_spindle_speed", emc_io_status_spindle_speed, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); Tcl_CreateObjCommand(interp, "emc_io_status_spindle_enabled", emc_io_status_spindle_enabled, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); Tcl_CreateObjCommand(interp, "emc_io_status_spindle_direction", emc_io_status_spindle_direction, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); Tcl_CreateObjCommand(interp, "emc_io_status_spindle_increasing", emc_io_status_spindle_increasing, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); Tcl_CreateObjCommand(interp, "emc_io_status_spindle_brake", emc_io_status_spindle_brake, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); Tcl_CreateObjCommand(interp, "emc_io_status_tool_prepped", emc_io_status_tool_prepped, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); Tcl_CreateObjCommand(interp, "emc_io_status_tool_in_spindle", emc_io_status_tool_in_spindle, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); Tcl_CreateObjCommand(interp, "emc_io_load_tool_table", emc_io_load_tool_table, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); Tcl_CreateObjCommand(interp, "inb", f_inb, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); Tcl_CreateObjCommand(interp, "outb", f_outb, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); Tcl_CreateObjCommand(interp, "inw", f_inw, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); Tcl_CreateObjCommand(interp, "outw", f_outw, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); Tcl_CreateObjCommand(interp, "inl", f_inl, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); Tcl_CreateObjCommand(interp, "outl", f_outl, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); Tcl_CreateObjCommand(interp, "emc_mot_shmem", emc_mot_shmem, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);/*! \todo Another #if 0 raw input no longer exists */#if 0 Tcl_CreateObjCommand(interp, "emc_mot_rawinput", emc_mot_rawinput, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);#endif Tcl_CreateObjCommand(interp, "emc_mot_move", emc_mot_move, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); /* * Specify a user-specific startup file to invoke if the application * is run interactively. Typically the startup file is "~/.apprc" * where "app" is the name of the application. If this line is deleted * then no user-specific startup file will be run under any conditions. */ Tcl_SetVar(interp, "tcl_rcFileName", "~/.tclmainrc", TCL_GLOBAL_ONLY); // set app-specific global variables Tcl_SetVar(interp, "EMC_INIFILE", EMC_INIFILE, TCL_GLOBAL_ONLY); return TCL_OK;}static void thisQuit(ClientData clientData){ // clean up NML channels if (emcErrorBuffer != 0) { delete emcErrorBuffer; emcErrorBuffer = 0; } if (emcioStatusBuffer != 0) { delete emcioStatusBuffer; emcioStatusBuffer = 0; } if (emcioCommandBuffer != 0) { delete emcioCommandBuffer; emcioCommandBuffer = 0; emcioCommand = 0; } // turn off port access iopl(0); // Clean up shared memory// usrmotExit(); Tcl_Exit(0); exit(0);}/* iniLoad() loads basic parameters from the ini file that are needed to define functions here: [EMC] DEBUG [EMC] VERSION [EMC] MACHINE [EMC] NML_FILE The rest of the ini file parameters for the IO subsystems, e.g., [EMCIO] CYCLE_TIME [EMCIO] or [EMC] IO_BASE_ADDRESS [EMCIO] TOOL_TABLE [EMCIO] SPINDLE_OFF_WAIT [EMCIO] ESTOP_SENSE_INDEX etc. are read in by the Tcl/Tk script via emc_ini and used in the script.*/static int iniLoad(const char *filename){ Inifile inifile; const char *inistring; char version[LINELEN]; // open it if (inifile.open(filename) == false) { return -1; } if (NULL != (inistring = inifile.find("DEBUG", "EMC"))) { // copy to global if (1 != sscanf(inistring, "%i", &EMC_DEBUG)) { EMC_DEBUG = 0; } } else { // not found, use default EMC_DEBUG = 0; } if (EMC_DEBUG & EMC_DEBUG_VERSIONS) { if (NULL != (inistring = inifile.find("VERSION", "EMC"))) { // print version if(sscanf(inistring, "$Revision: %s", version) == 1) rcs_print("Version: %s\n", version); } else { // not found, not fatal rcs_print("Version: (not found)\n"); } if (NULL != (inistring = inifile.find("MACHINE", "EMC"))) { // print machine rcs_print("Machine: %s\n", inistring); } else { // not found, not fatal rcs_print("Machine: (not found)\n"); } } if (NULL != (inistring = inifile.find("NML_FILE", "EMC"))) { // copy to global strcpy(EMC_NMLFILE, inistring); } else { // not found, use default } if (NULL != (inistring = inifile.find("TOOL_TABLE", "EMCIO"))) { // copy to global strcpy(TOOL_TABLE_FILE, inistring); } else { strcpy(TOOL_TABLE_FILE, "emc.tbl"); // not found, use default } // close it inifile.close(); return 0;}static void sigQuit(int sig){ thisQuit((ClientData) 0);}int main(int argc, char *argv[]){ // process command line args if (0 != emcGetArgs(argc, argv)) { rcs_print_error("error in argument list\n"); exit(1); } // get configuration information iniLoad(EMC_INIFILE); // Enable shared memory comms. usrmotIniLoad(EMC_INIFILE); if (-1 != (shmem = usrmotInit("iosh"))) { shmem = (long) emcmotshmem; } // turn on port access unpriv = 0; if (0 != iopl(3)) { fprintf(stderr, "not privileged to access IO-- disabling IO\n"); unpriv = 1; } // attach our quit function to exit Tcl_CreateExitHandler(thisQuit, (ClientData) 0); // attach our quit function to SIGINT signal(SIGINT, sigQuit); // run Tk main loop Tk_Main(argc, argv, Tcl_AppInit);/* Tk_Main bombs straight out, so anything after this does NOT get executed. So any cleanup operations need to be done in thisQuit(). */ exit(0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -