/// <summary> /// 将轴状态更新到界面 /// </summary> public void UpdateStationUI() { int i = 0; if (null != _axisNames) { for (i = 0; i < _axisNames.Length; i++) { JFDevCellInfo dcInfo = JFHubCenter.Instance.MDCellNameMgr.GetAxisCellInfo(_axisNames[i]); if (dcInfo == null) { tbCurrPoses[i].Text = "无效值"; continue; } IJFDevice_MotionDaq dev = JFHubCenter.Instance.InitorManager.GetInitor(dcInfo.DeviceID) as IJFDevice_MotionDaq; if (null == dev) { tbCurrPoses[i].Text = "无效值"; continue; } if (dcInfo.ModuleIndex >= dev.McCount) { tbCurrPoses[i].Text = "无效值"; continue; } IJFModule_Motion md = dev.GetMc(dcInfo.ModuleIndex); if (dcInfo.ChannelIndex >= md.AxisCount) { tbCurrPoses[i].Text = "无效值"; continue; } double pos = 0; int errCode = md.GetFbkPos(dcInfo.ChannelIndex, out pos); if (0 != errCode) { tbCurrPoses[i].Text = "获取错误!代码:" + errCode; } else { tbCurrPoses[i].Text = pos.ToString(); } bool isServon = md.IsSVO(i); btServons[i].LampColor = isServon ? LampButton.LColor.Green : LampButton.LColor.Gray; } } for (; i < 4; i++) { tbCurrPoses[i].Text = "无效值"; btServons[i].LampColor = LampButton.LColor.Gray; } }
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?"去使能":"使能") + "成功"); }