emcsh.cc
来自「CNC 的开放码,EMC2 V2.2.8版」· CC 代码 · 共 2,603 行 · 第 1/5 页
CC
2,603 行
} if (TCL_OK == Tcl_GetIntFromObj(0, objv[1], &joint)) { if (joint < 0 || joint >= EMC_AXIS_MAX) { Tcl_SetResult(interp, "emc_joint_limit: joint out of bounds", TCL_VOLATILE); return TCL_ERROR; } if (emcStatus->motion.axis[joint].minHardLimit) { Tcl_SetResult(interp, "minhard", TCL_VOLATILE); return TCL_OK; } else if (emcStatus->motion.axis[joint].minSoftLimit) { Tcl_SetResult(interp, "minsoft", TCL_VOLATILE); return TCL_OK; } else if (emcStatus->motion.axis[joint].maxSoftLimit) { Tcl_SetResult(interp, "maxsoft", TCL_VOLATILE); return TCL_OK; } else if (emcStatus->motion.axis[joint].maxHardLimit) { Tcl_SetResult(interp, "maxsoft", TCL_VOLATILE); return TCL_OK; } else { Tcl_SetResult(interp, "ok", TCL_VOLATILE); return TCL_OK; } } Tcl_SetResult(interp, "emc_joint_limit: joint out of bounds", TCL_VOLATILE); return TCL_ERROR;}static int emc_joint_fault(ClientData clientdata, Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[]){ int joint; if (objc != 2) { Tcl_SetResult(interp, "emc_joint_fault: need exactly 1 non-negative integer", TCL_VOLATILE); return TCL_ERROR; } if (emcUpdateType == EMC_UPDATE_AUTO) { updateStatus(); } if (TCL_OK == Tcl_GetIntFromObj(0, objv[1], &joint)) { if (joint < 0 || joint >= EMC_AXIS_MAX) { Tcl_SetResult(interp, "emc_joint_fault: joint out of bounds", TCL_VOLATILE); return TCL_ERROR; } if (emcStatus->motion.axis[joint].fault) { Tcl_SetResult(interp, "fault", TCL_VOLATILE); return TCL_OK; } else { Tcl_SetResult(interp, "ok", TCL_VOLATILE); return TCL_OK; } } Tcl_SetResult(interp, "emc_joint_fault: joint out of bounds", TCL_VOLATILE); return TCL_ERROR;}static int emc_override_limit(ClientData clientdata, Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[]){ Tcl_Obj *obj; int on; if (objc == 1) { // no arg-- return status if (emcUpdateType == EMC_UPDATE_AUTO) { updateStatus(); } // motion overrides all axes at same time, so just reference index 0 obj = Tcl_NewIntObj(emcStatus->motion.axis[0].overrideLimits); Tcl_SetObjResult(interp, obj); return TCL_OK; } if (objc == 2) { if (TCL_OK == Tcl_GetIntFromObj(0, objv[1], &on)) { if (on) { if (0 != sendOverrideLimits(0)) { Tcl_SetResult(interp, "emc_override_limit: can't send command", TCL_VOLATILE); return TCL_OK; } } else { if (0 != sendOverrideLimits(-1)) { Tcl_SetResult(interp, "emc_override_limit: can't send command", TCL_VOLATILE); return TCL_OK; } } return TCL_OK; } else { Tcl_SetResult(interp, "emc_override_limit: need 0 or 1", TCL_VOLATILE); return TCL_ERROR; } } Tcl_SetResult(interp, "emc_override_limit: need no args, 0 or 1", TCL_VOLATILE); return TCL_ERROR;}static int emc_joint_homed(ClientData clientdata, Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[]){ int joint; if (objc != 2) { Tcl_SetResult(interp, "emc_joint_homed: need exactly 1 non-negative integer", TCL_VOLATILE); return TCL_ERROR; } if (emcUpdateType == EMC_UPDATE_AUTO) { updateStatus(); } if (TCL_OK == Tcl_GetIntFromObj(0, objv[1], &joint)) { if (joint < 0 || joint >= EMC_AXIS_MAX) { Tcl_SetResult(interp, "emc_joint_homed: joint out of bounds", TCL_VOLATILE); return TCL_ERROR; } if (emcStatus->motion.axis[joint].homed) { Tcl_SetResult(interp, "homed", TCL_VOLATILE); return TCL_OK; } else { Tcl_SetResult(interp, "not", TCL_VOLATILE); return TCL_OK; } } Tcl_SetResult(interp, "emc_joint_homed: joint out of bounds", TCL_VOLATILE); return TCL_ERROR;}static int emc_mdi(ClientData clientdata, Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[]){ char string[256]; int t; if (objc < 2) { Tcl_SetResult(interp, "emc_mdi: need command", TCL_VOLATILE); return TCL_ERROR; } // bug-- check for string overflow strcpy(string, Tcl_GetStringFromObj(objv[1], 0)); for (t = 2; t < objc; t++) { strcat(string, " "); strcat(string, Tcl_GetStringFromObj(objv[t], 0)); } if (0 != sendMdiCmd(string)) { Tcl_SetResult(interp, "emc_mdi: error executing command", TCL_VOLATILE); return TCL_OK; } return TCL_OK;}static int emc_home(ClientData clientdata, Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[]){ int axis; if (objc != 2) { Tcl_SetResult(interp, "emc_home: need axis", TCL_VOLATILE); return TCL_ERROR; } if (TCL_OK == Tcl_GetIntFromObj(0, objv[1], &axis)) { sendHome(axis); return TCL_OK; } Tcl_SetResult(interp, "emc_home: need axis as integer, 0..", TCL_VOLATILE); return TCL_ERROR;}static int emc_jog_stop(ClientData clientdata, Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[]){ int axis; if (objc != 2) { Tcl_SetResult(interp, "emc_jog_stop: need axis", TCL_VOLATILE); return TCL_ERROR; } if (0 != Tcl_GetIntFromObj(0, objv[1], &axis)) { Tcl_SetResult(interp, "emc_jog_stop: need axis as integer, 0..", TCL_VOLATILE); return TCL_ERROR; } if (0 != sendJogStop(axis)) { Tcl_SetResult(interp, "emc_jog_stop: can't send jog stop msg", TCL_VOLATILE); return TCL_OK; } return TCL_OK;}static int emc_jog(ClientData clientdata, Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[]){ int axis; double speed; if (objc != 3) { Tcl_SetResult(interp, "emc_jog: need axis and speed", TCL_VOLATILE); return TCL_ERROR; } if (0 != Tcl_GetIntFromObj(0, objv[1], &axis)) { Tcl_SetResult(interp, "emc_jog: need axis as integer, 0..", TCL_VOLATILE); return TCL_ERROR; } if (0 != Tcl_GetDoubleFromObj(0, objv[2], &speed)) { Tcl_SetResult(interp, "emc_jog: need speed as real number", TCL_VOLATILE); return TCL_ERROR; } if (0 != sendJogCont(axis, speed)) { Tcl_SetResult(interp, "emc_jog: can't jog", TCL_VOLATILE); return TCL_OK; } return TCL_OK;}static int emc_jog_incr(ClientData clientdata, Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[]){ int axis; double speed; double incr; if (objc != 4) { Tcl_SetResult(interp, "emc_jog_incr: need axis, speed, and increment", TCL_VOLATILE); return TCL_ERROR; } if (0 != Tcl_GetIntFromObj(0, objv[1], &axis)) { Tcl_SetResult(interp, "emc_jog_incr: need axis as integer, 0..", TCL_VOLATILE); return TCL_ERROR; } if (0 != Tcl_GetDoubleFromObj(0, objv[2], &speed)) { Tcl_SetResult(interp, "emc_jog_incr: need speed as real number", TCL_VOLATILE); return TCL_ERROR; } if (0 != Tcl_GetDoubleFromObj(0, objv[3], &incr)) { Tcl_SetResult(interp, "emc_jog_incr: need increment as real number", TCL_VOLATILE); return TCL_ERROR; } if (0 != sendJogIncr(axis, speed, incr)) { Tcl_SetResult(interp, "emc_jog_incr: can't jog", TCL_VOLATILE); return TCL_OK; } return TCL_OK;}static int emc_feed_override(ClientData clientdata, Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[]){ Tcl_Obj *feedobj; int percent; if (objc == 1) { // no arg-- return status if (emcUpdateType == EMC_UPDATE_AUTO) { updateStatus(); } feedobj = Tcl_NewIntObj((int) (emcStatus->motion.traj.scale * 100.0 + 0.5)); Tcl_SetObjResult(interp, feedobj); return TCL_OK; } if (objc != 2) { Tcl_SetResult(interp, "emc_feed_override: need percent", TCL_VOLATILE); return TCL_ERROR; } if (TCL_OK == Tcl_GetIntFromObj(0, objv[1], &percent)) { sendFeedOverride(((double) percent) / 100.0); return TCL_OK; } Tcl_SetResult(interp, "emc_feed_override: need percent", TCL_VOLATILE); return TCL_ERROR;}static int emc_spindle_override(ClientData clientdata, Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[]){ Tcl_Obj *feedobj; int percent; if (objc == 1) { // no arg-- return status if (emcUpdateType == EMC_UPDATE_AUTO) { updateStatus(); } feedobj = Tcl_NewIntObj((int) (emcStatus->motion.traj.spindle_scale * 100.0 + 0.5)); Tcl_SetObjResult(interp, feedobj); return TCL_OK; } if (objc != 2) { Tcl_SetResult(interp, "emc_spindle_override: need percent", TCL_VOLATILE); return TCL_ERROR; } if (TCL_OK == Tcl_GetIntFromObj(0, objv[1], &percent)) { sendSpindleOverride(((double) percent) / 100.0); return TCL_OK; } Tcl_SetResult(interp, "emc_spindle_override: need percent", TCL_VOLATILE); return TCL_ERROR;}static int emc_task_plan_init(ClientData clientdata, Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[]){ if (0 != sendTaskPlanInit()) { Tcl_SetResult(interp, "emc_task_plan_init: can't init interpreter", TCL_VOLATILE); return TCL_OK; } return TCL_OK;}static int emc_open(ClientData clientdata, Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[]){ if (objc != 2) { Tcl_SetResult(interp, "emc_open: need file", TCL_VOLATILE); return TCL_ERROR; } if (0 != sendProgramOpen(Tcl_GetStringFromObj(objv[1], 0))) { Tcl_SetResult(interp, "emc_open: can't open file", TCL_VOLATILE); return TCL_OK; } return TCL_OK;}static int emc_run(ClientData clientdata, Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[]){ int line; if (objc == 1) { if (0 != sendProgramRun(0)) { Tcl_SetResult(interp, "emc_run: can't execute program", TCL_VOLATILE); return TCL_OK; } } if (objc == 2) { if (0 != Tcl_GetIntFromObj(0, objv[1], &line)) { Tcl_SetResult(interp, "emc_run: need integer start line", TCL_VOLATILE); return TCL_ERROR; } if (0 != sendProgramRun(line)) { Tcl_SetResult(interp, "emc_run: can't execute program", TCL_VOLATILE); return TCL_OK; } } return TCL_OK;}static int emc_pause(ClientData clientdata, Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[]){ if (0 != sendProgramPause()) { Tcl_SetResult(interp, "emc_pause: can't pause program", TCL_VOLATILE); return TCL_OK; } return TCL_OK;}static int emc_optional_stop(ClientData clientdata, Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[]){ Tcl_Obj *obj; int on; if (objc == 1) { // no arg-- return status if (emcUpdateType == EMC_UPDATE_AUTO) { updateStatus(); } // get the current state from the status obj = Tcl_NewIntObj(emcStatus->task.optional_stop_state); Tcl_SetObjResult(interp, obj); return TCL_OK; } if (objc == 2) { if (TCL_OK == Tcl_GetIntFromObj(0, objv[1], &on)) { if (0 != sendSetOptionalStop(on)) { Tcl_SetResult(interp, "emc_optional_stop: can't send command", TCL_VOLATILE); return TCL_OK; } return TCL_OK; } else { Tcl_SetResult(interp, "emc_optional_stop: need 0 or 1", TCL_VOLATILE); return TCL_ERROR; } } Tcl_SetResult(interp, "emc_optional_stop: need no args, 0 or 1", TCL_VOLATILE); return TCL_ERROR;}static int emc_resume(ClientData clientdata, Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[]){ if (0 != sendProgramResume()) { Tcl_SetResult(interp, "emc_resume: can't resume program", TCL_VOLATILE); return TCL_OK; } return TCL_OK;}static int emc_step(ClientData clientdata, Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[]){ if (0 != sendProgramStep()) { Tcl_SetResult(interp, "emc_step: can't step program", TCL_VOLATILE); return TCL_OK; } return TCL_OK;}static int emc_abort(ClientData clientdata, Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[]){ if (0 != sendAbort()) { Tcl_SetResult(interp, "emc_abort: can't execute program", TCL_VOLATILE); return TCL_OK; } return TCL_OK;}static int emc_program(ClientData clientdata, Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[]){ if (objc != 1) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?