iosh.cc

来自「CNC 的开放码,EMC2 V2.2.8版」· CC 代码 · 共 1,639 行 · 第 1/3 页

CC
1,639
字号
{    const char *objstr;    if (objc != 2) {	Tcl_SetResult(interp,		      "emc_io_status_spindle_enabled: need on | off",		      TCL_VOLATILE);	return TCL_ERROR;    }    objstr = Tcl_GetStringFromObj(objv[1], 0);    if (!strcmp(objstr, "on")) {	emcmotionStatus.spindle.enabled = 1;	return TCL_OK;    } else if (!strcmp(objstr, "off")) {	emcmotionStatus.spindle.enabled = 0;	return TCL_OK;    }    Tcl_SetResult(interp, "emc_io_status_spindle_enabled: need on | off",		  TCL_VOLATILE);    return TCL_ERROR;}static int emc_io_status_spindle_direction(ClientData clientdata,					   Tcl_Interp * interp, int objc,					   Tcl_Obj * CONST objv[]){    int direction;    if (objc != 2) {	Tcl_SetResult(interp,		      "emc_io_status_spindle_direction: need direction",		      TCL_VOLATILE);	return TCL_ERROR;    }    if (TCL_OK == Tcl_GetIntFromObj(0, objv[1], &direction)) {	emcmotionStatus.spindle.direction = direction;	return TCL_OK;    }    Tcl_SetResult(interp,		  "emc_io_status_spindle_direction: need direction",		  TCL_VOLATILE);    return TCL_ERROR;}static int emc_io_status_spindle_increasing(ClientData clientdata,					    Tcl_Interp * interp, int objc,					    Tcl_Obj * CONST objv[]){    int increasing;    if (objc != 2) {	Tcl_SetResult(interp,		      "emc_io_status_spindle_increasing: need increasing",		      TCL_VOLATILE);	return TCL_ERROR;    }    if (TCL_OK == Tcl_GetIntFromObj(0, objv[1], &increasing)) {	emcmotionStatus.spindle.increasing = increasing;	return TCL_OK;    }    Tcl_SetResult(interp,		  "emc_io_status_spindle_increasing: need increasing",		  TCL_VOLATILE);    return TCL_ERROR;}static int emc_io_status_spindle_brake(ClientData clientdata,				       Tcl_Interp * interp, int objc,				       Tcl_Obj * CONST objv[]){    const char *objstr;    if (objc != 2) {	Tcl_SetResult(interp, "emc_io_status_spindle_brake: need on | off",		      TCL_VOLATILE);	return TCL_ERROR;    }    objstr = Tcl_GetStringFromObj(objv[1], 0);    if (!strcmp(objstr, "on")) {	emcmotionStatus.spindle.brake = 1;	return TCL_OK;    } else if (!strcmp(objstr, "off")) {	emcmotionStatus.spindle.brake = 0;	return TCL_OK;    }    Tcl_SetResult(interp, "emc_io_status_spindle_brake: need on | off",		  TCL_VOLATILE);    return TCL_ERROR;}*/static int emc_io_status_tool_prepped(ClientData clientdata,				      Tcl_Interp * interp, int objc,				      Tcl_Obj * CONST objv[]){    int toolPrepped;    if (objc != 2) {	Tcl_SetResult(interp, "emc_io_status_tool_prepped: need tool",		      TCL_VOLATILE);	return TCL_ERROR;    }    if (TCL_OK == Tcl_GetIntFromObj(0, objv[1], &toolPrepped)) {	emcioStatus.tool.toolPrepped = toolPrepped;	return TCL_OK;    }    Tcl_SetResult(interp, "emc_io_status_tool_prepped: need tool",		  TCL_VOLATILE);    return TCL_ERROR;}static int emc_io_status_tool_in_spindle(ClientData clientdata,					 Tcl_Interp * interp, int objc,					 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;}static int emc_mot_shmem(ClientData clientdata,			 Tcl_Interp * interp, int objc,			 Tcl_Obj * CONST objv[]){    if (objc == 1) {        Tcl_SetObjResult(interp, Tcl_NewLongObj(0xFFFFFFFF));        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);/* FIXME: uncomment for now, bring back later    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, "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;    }    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;    }    // 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 + =
减小字号Ctrl + -
显示快捷键?