/// <summary> /// 将直线插补运动的所有轴伺服上电 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btLineServOn_Click(object sender, EventArgs e) { if (_module == null) { ShowTips("无效操作,模块未设置"); return; } if (!_module.IsOpen) { ShowTips("无效操作,模块未打开"); return; } if (dgvLinePos.Rows.Count == 0) { MessageBox.Show("无效操作:没有设置插补轴"); return; } List <int> axisIDs = new List <int>(); foreach (DataGridViewRow row in dgvLinePos.Rows) { string axisIDTxt = row.Cells[0].Value as string; if (string.IsNullOrEmpty(axisIDTxt)) { MessageBox.Show("操作失败:存在未设置的轴序号"); return; } axisIDs.Add(Convert.ToInt32(axisIDTxt)); } bool isSuccess = true; StringBuilder sbErr = new StringBuilder(); foreach (int axisID in axisIDs) { int err = _module.ServoOn(axisID); if (err != 0) { sbErr.Append("轴" + axisID + " 伺服上电失败,ErrorInfo:" + _module.GetErrorInfo(err) + "\n"); isSuccess = false; } } if (isSuccess) { ShowTips("所有直线插补伺服上电完成"); } else { MessageBox.Show("操作失败:\n" + sbErr.ToString()); } }
protected override bool ActionGenuine(out string errorInfo) { IJFInitializable dev = null; JFDevCellInfo ci = null; string axisID = GetInitParamValue("轴ID") as string; if (!JFHubCenter.Instance.MDCellNameMgr.ContainAxisName(axisID)) { errorInfo = "参数:\"轴ID\" = " + axisID + " 在设备名称表中不存在"; SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError); return(false); } if (!JFCMFunction.CheckDevCellName(JFCMFunction.Axis, axisID, out dev, out ci, out errorInfo)) { SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError); return(false); } IJFModule_Motion md = (dev as IJFDevice_MotionDaq).GetMc(ci.ModuleIndex); int err = 0; bool IsServoOn = (bool)GetInitParamValue("轴是否励磁"); if (IsServoOn) { err = md.ServoOn(ci.ChannelIndex); } else { err = md.ServoOff(ci.ChannelIndex); } if (err != 0) { errorInfo = (IsServoOn ? "励磁使能ON" : "励磁使能OFF") + "失败:" + md.GetErrorInfo(err); SetOutputParamValue("执行结果", JFWorkCmdResult.ActionError); return(false); } errorInfo = "Success"; SetOutputParamValue("执行结果", JFWorkCmdResult.Success); return(true); }
void OnServonButtonClicked(object sender, EventArgs e) { int i = 0; for (i = 0; i < btServons.Length; i++) { if (sender == btServons[i]) { break; } } string axisName = _axisNames[i]; string errInfo; JFDevCellInfo ci = CheckAxisDevInfo(axisName, out errInfo); if (null == ci) { MessageBox.Show("轴" + _axisNames[i] + "伺服操作失败,ErrorInfo:" + errInfo); return; } IJFDevice_MotionDaq dev = JFHubCenter.Instance.InitorManager.GetInitor(ci.DeviceID) as IJFDevice_MotionDaq; IJFModule_Motion md = dev.GetMc(ci.ModuleIndex); bool isCurrSerOn = md.IsSVO(ci.ChannelIndex); int errCode = 0; if (isCurrSerOn) { errCode = md.ServoOff(ci.ChannelIndex); } else { errCode = md.ServoOn(ci.ChannelIndex); } if (errCode != 0) { MessageBox.Show("轴" + _axisNames[i] + "伺服操作失败,ErrorInfo:" + md.GetErrorInfo(errCode)); return; } ShowTips("轴" + _axisNames[i] + "伺服" + (isCurrSerOn?"去使能":"使能") + "成功"); }
///// <summary> ///// 使通道可用(如伺服上电,光源/触发可用) ///// 建议在 打开设备->检查通道可用性 之后调用 ///// </summary> ///// <param name="errorInfo"></param> ///// <returns></returns> public bool EnabledChannel(out string errorInfo) { errorInfo = "Unknown-Error"; bool isOK = false; if (!CheckAvalid(out errorInfo)) { return(false); } int errorCode = 0; IJFDevice dev = Device(); switch (CellType) { case JFDevCellType.DI: isOK = true; errorInfo = "Success"; break; case JFDevCellType.DO: errorInfo = "Success"; isOK = true; break; case JFDevCellType.Axis: { IJFDevice_MotionDaq devMD = Device() as IJFDevice_MotionDaq; JFDevCellInfo ci = CellInfo(); IJFModule_Motion mm = devMD.GetMc(ci.ModuleIndex); errorCode = mm.ServoOn(ci.ChannelIndex); if (errorCode != 0) { errorInfo = mm.GetErrorInfo(errorCode); } else { isOK = true; errorInfo = "Success"; } } break; case JFDevCellType.AI: errorInfo = "Success"; isOK = true; break; case JFDevCellType.AO: errorInfo = "Success"; isOK = true; break; case JFDevCellType.CmpTrig: errorInfo = "Success"; isOK = true; break; case JFDevCellType.Light: dev = Device(); if (dev is IJFDevice_LightControllerWithTrig) //光源控制器 { IJFDevice_LightControllerWithTrig devLT = dev as IJFDevice_LightControllerWithTrig; errorCode = devLT.SetWorkMode(JFLightWithTrigWorkMode.TurnOnOff); //切换为开关模式 if (errorCode != 0) { errorInfo = "切换为开关模式失败:" + devLT.GetErrorInfo(errorCode); break; } } IJFDevice_LightController devl = dev as IJFDevice_LightController; errorCode = devl.SetLightChannelEnable(CellInfo().ChannelIndex, true); if (errorCode != 0) { errorInfo = "通道使能失败:" + devl.GetErrorInfo(errorCode); break; } isOK = true; errorInfo = "Success"; break; case JFDevCellType.Trig: dev = Device(); if (dev is IJFDevice_LightControllerWithTrig) //光源控制器 { IJFDevice_LightControllerWithTrig devLT = dev as IJFDevice_LightControllerWithTrig; errorCode = devLT.SetWorkMode(JFLightWithTrigWorkMode.Trigger); //切换为触发模式 if (errorCode != 0) { errorInfo = "切换为触发模式失败:" + devLT.GetErrorInfo(errorCode); break; } } IJFDevice_TrigController devt = dev as IJFDevice_TrigController; errorCode = devt.SetTrigChannelEnable(CellInfo().ChannelIndex, true); if (errorCode != 0) { errorInfo = "通道使能失败:" + devt.GetErrorInfo(errorCode); break; } isOK = true; errorInfo = "Success"; break; default: errorInfo = "未定义的通道类型"; break; } return(isOK); }