void _UpdateTrig() { string[] allTrigDevs = JFHubCenter.Instance.InitorManager.GetIDs(typeof(IJFDevice_TrigController)); if (null == allTrigDevs || 0 == allTrigDevs.Length) //系统中不存在已命名的AI通道 { ShowTips("设备列表中不存在触发设备!"); btAdd.Enabled = false; } else { btAdd.Enabled = true; } string[] chnNames = _station.TrigChannelNames; if (null == chnNames || 0 == chnNames.Length) { btDel.Enabled = false; return; } else//if(null != chnNames) { btDel.Enabled = true; foreach (string chnName in chnNames) { DataGridViewRow row = new DataGridViewRow(); DataGridViewTextBoxCell cellName = new DataGridViewTextBoxCell(); cellName.Value = chnName; DataGridViewTextBoxCell cellInfo = new DataGridViewTextBoxCell(); JFDevCellInfo chnCellInfo = JFHubCenter.Instance.MDCellNameMgr.GetTrigCtrlChannelInfo(chnName); if (null == chnCellInfo) { cellName.Style.ForeColor = Color.Red; cellInfo.Value = "无效的通道名称,在名称配置表中不存在!"; cellInfo.Style.ForeColor = Color.Red; } else { IJFDevice_TrigController trigDev = JFHubCenter.Instance.InitorManager.GetInitor(chnCellInfo.DeviceID) as IJFDevice_TrigController; if (null == trigDev) { cellName.Style.ForeColor = Color.Red; cellInfo.Value = "控制器在设备列表中不存在!"; cellInfo.Style.ForeColor = Color.Red; } else { cellInfo.Value = string.Format("控制器:{0} - 通道:{1}", chnCellInfo.DeviceID, chnCellInfo.ChannelIndex); } //cellInfo.Value = string.Format("控制器:{0} - 模块:{1} - 通道:{2}", devInfo.DeviceID, devInfo.ModuleIndex, devInfo.ChannelIndex); } row.Cells.Add(cellName); row.Cells.Add(cellInfo); dgvNameInfos.Rows.Add(row); } } }
public void SetChannelInfo(IJFDevice_TrigController module, int chn, string chnID) { _module = module; _chn = chn; _chnID = string.IsNullOrEmpty(chnID) ? "通道_" + chn : chnID; if (isFormLoaded) { AdjustChannelView();//UpdateChannelStatus(); } }
/// <summary> /// 设置模块和通道序号 /// </summary> /// <param name="module"></param> /// <param name="chns">当此值为null时,表示显示所有通道</param> public void SetModuleInfo(IJFDevice_TrigController module, int[] chns = null, string[] chnIDs = null) { _module = module; List <int> lstChn = new List <int>(); List <string> lstIDs = new List <string>(); if (null != _module) { if (null == chns) //添加所有通道 { for (int i = 0; i < _module.TrigChannelCount; i++) { lstChn.Add(i); if (null == chnIDs || chnIDs.Length > i) { lstIDs.Add("通道_" + i.ToString()); } else { lstIDs.Add(chnIDs[i]); } } } else { lstChn.AddRange(chns); for (int i = 0; i < chns.Length; i++) { if (null == chnIDs || chnIDs.Length > i) { lstIDs.Add("通道_" + i.ToString()); } else { lstIDs.Add(chnIDs[i]); } } } } _chns = lstChn.ToArray(); _chnIDs = lstIDs.ToArray(); if (_isFormLoaded) { AdjustUI(); } }
public void UpdateChannelsInfo(string devID) { _devID = devID; panel1.Controls.Clear(); if (string.IsNullOrEmpty(_devID)) { ShowTips("设备名称为空!"); return; } if (!JFHubCenter.Instance.MDCellNameMgr.ContainTrigCtrlDev(devID)) { ShowTips("设备名称列表中未包含触发控制器设备:" + _devID); return; } string[] trigChnNames = JFHubCenter.Instance.MDCellNameMgr.AllChannelNamesInTrigCtrlDev(devID); if (trigChnNames == null || 0 == trigChnNames.Length) { ShowTips("命名通道数量为0"); return; } IJFDevice_TrigController dev = JFHubCenter.Instance.InitorManager.GetInitor(_devID) as IJFDevice_TrigController; if (dev == null) { ShowTips("设备列表中不存在设备Name = " + _devID); } if (!dev.IsDeviceOpen) { ShowTips("设备当前处于关闭状态"); } int top = 3; for (int i = 0; i < trigChnNames.Count(); i++) { UcTrigCtrlChn ucChn = new UcTrigCtrlChn(); ucChn.Location = new Point(3, top); panel1.Controls.Add(ucChn); ucChn.SetChannelInfo(dev, i, trigChnNames[i]); top = ucChn.Bottom + 5; } }
/// <summary> /// 检查设备通道是否存在并且可用 /// </summary> /// <param name="category"></param> /// <param name="cellName"></param> /// <param name="initor"></param> /// <param name="cellInfo"></param> /// <param name="errorInfo"></param> /// <returns></returns> public static bool CheckDevCellName(string category, string cellName, out IJFInitializable initor, out JFDevCellInfo ci, out string errorInfo) { initor = null; ci = null; errorInfo = null; if (string.IsNullOrEmpty(cellName)) { errorInfo = "参数项\"cellName\"为空"; return(false); } JFDevCellNameManeger nameMgr = JFHubCenter.Instance.MDCellNameMgr; JFInitorManager initorMgr = JFHubCenter.Instance.InitorManager; JFDevCellInfo cellInfo = null; if (category == DO) //获取数字量输出通道信息 { cellInfo = nameMgr.GetDoCellInfo(cellName); if (null == cellInfo) { errorInfo = "设备命名表中不存在DO:" + cellName; return(false); } IJFInitializable dev = initorMgr.GetInitor(cellInfo.DeviceID); if (null == dev) { errorInfo = "DO:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"在设备列表中不存在"; return(false); } if (!typeof(IJFDevice_MotionDaq).IsAssignableFrom(dev.GetType())) { errorInfo = "DO:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"类型不是Device_MotionDaq "; return(false); } IJFDevice_MotionDaq md = dev as IJFDevice_MotionDaq; if (!md.IsInitOK) { errorInfo = "DO:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"未完成初始化动作 "; return(false); } if (!md.IsDeviceOpen) { errorInfo = "DO:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"未打开 "; return(false); } if (cellInfo.ModuleIndex >= md.DioCount) { errorInfo = "DO:\"" + cellName + "\" ModuleIndex = :" + cellInfo.ModuleIndex + "超出设备DIO模块数量: " + md.DioCount; return(false); } if (cellInfo.ChannelIndex >= md.GetDio(cellInfo.ModuleIndex).DOCount) { errorInfo = "DO:\"" + cellName + "\" Channel = :" + cellInfo.ChannelIndex + "超出模块DO通道数量: " + md.GetDio(cellInfo.ModuleIndex).DOCount; return(false); } initor = dev; ci = cellInfo; errorInfo = "Success"; return(true); } else if (category == DI) //获取数字量输入 { cellInfo = nameMgr.GetDiCellInfo(cellName); if (null == cellInfo) { errorInfo = "设备命名表中不存在DI:" + cellName; return(false); } IJFInitializable dev = initorMgr.GetInitor(cellInfo.DeviceID); if (null == dev) { errorInfo = "DI:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"在设备列表中不存在"; return(false); } if (!typeof(IJFDevice_MotionDaq).IsAssignableFrom(dev.GetType())) { errorInfo = "DI:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"类型不是Device_MotionDaq "; return(false); } IJFDevice_MotionDaq md = dev as IJFDevice_MotionDaq; if (!md.IsInitOK) { errorInfo = "DI:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"未完成初始化动作 "; return(false); } if (!md.IsDeviceOpen) { errorInfo = "DI:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"未打开 "; return(false); } if (cellInfo.ModuleIndex >= md.DioCount) { errorInfo = "DI:\"" + cellName + "\" ModuleIndex = :" + cellInfo.ModuleIndex + "超出设备DIO模块数量: " + md.DioCount; return(false); } if (cellInfo.ChannelIndex >= md.GetDio(cellInfo.ModuleIndex).DICount) { errorInfo = "DI:\"" + cellName + "\" Channel = :" + cellInfo.ChannelIndex + "超出模块DI通道数量: " + md.GetDio(cellInfo.ModuleIndex).DOCount; return(false); } initor = dev; ci = cellInfo; errorInfo = "Success"; return(true); } else if (category == AI) { } else if (category == AO) { } else if (category == Axis) { cellInfo = nameMgr.GetAxisCellInfo(cellName); if (null == cellInfo) { errorInfo = "设备命名表中不存在Axis:" + cellName; return(false); } IJFInitializable dev = initorMgr.GetInitor(cellInfo.DeviceID); if (null == dev) { errorInfo = "Axis:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"在设备列表中不存在"; return(false); } if (!typeof(IJFDevice_MotionDaq).IsAssignableFrom(dev.GetType())) { errorInfo = "Axis:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"类型不是Device_MotionDaq "; return(false); } IJFDevice_MotionDaq md = dev as IJFDevice_MotionDaq; if (!md.IsInitOK) { errorInfo = "Axis:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"未完成初始化动作 "; return(false); } if (!md.IsDeviceOpen) { errorInfo = "Axis:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"未打开 "; return(false); } if (cellInfo.ModuleIndex >= md.McCount) { errorInfo = "Axis:\"" + cellName + "\" ModuleIndex = :" + cellInfo.ModuleIndex + "超出设备轴模块数量: " + md.McCount; return(false); } if (cellInfo.ChannelIndex >= md.GetMc(cellInfo.ModuleIndex).AxisCount) { errorInfo = "Axis:\"" + cellName + "\" Channel = :" + cellInfo.ModuleIndex + "超出模块轴通道数量: " + md.GetMc(cellInfo.ModuleIndex).AxisCount; return(false); } initor = dev; ci = cellInfo; errorInfo = "Success"; return(true); } else if (category == CmpTrig) { cellInfo = nameMgr.GetCmpTrigCellInfo(cellName); if (null == cellInfo) { errorInfo = "设备命名表中不存在CmpTrig:" + cellName; return(false); } IJFInitializable dev = initorMgr.GetInitor(cellInfo.DeviceID); if (null == dev) { errorInfo = "CmpTrig:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"在设备列表中不存在"; return(false); } if (!typeof(IJFDevice_MotionDaq).IsAssignableFrom(dev.GetType())) { errorInfo = "CmpTrig:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"类型不是Device_MotionDaq "; return(false); } IJFDevice_MotionDaq md = dev as IJFDevice_MotionDaq; if (!md.IsInitOK) { errorInfo = "CmpTrig:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"未完成初始化动作 "; return(false); } if (!md.IsDeviceOpen) { errorInfo = "CmpTrig:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"未打开 "; return(false); } if (cellInfo.ModuleIndex >= md.CompareTriggerCount) { errorInfo = "CmpTrig:\"" + cellName + "\" ModuleIndex = :" + cellInfo.ModuleIndex + "超出设备比较触发模块数量: " + md.CompareTriggerCount; return(false); } if (cellInfo.ChannelIndex >= md.GetCompareTrigger(cellInfo.ModuleIndex).EncoderChannels) { errorInfo = "CmpTrig:\"" + cellName + "\" Channel = :" + cellInfo.ModuleIndex + "超出模块比较触发通道数量: " + md.GetCompareTrigger(cellInfo.ModuleIndex).EncoderChannels; return(false); } initor = dev; ci = cellInfo; errorInfo = "Success"; return(true); } else if (category == LightCtrl) { cellInfo = nameMgr.GetLightCtrlChannelInfo(cellName); if (null == cellInfo) { errorInfo = "设备命名表中不存在LightCtrl:" + cellName; return(false); } IJFInitializable dev = initorMgr.GetInitor(cellInfo.DeviceID); if (null == dev) { errorInfo = "LightCtrl:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"在设备列表中不存在"; return(false); } if (!typeof(IJFDevice_LightController).IsAssignableFrom(dev.GetType())) { errorInfo = "LightCtrl:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"类型不是IJFDevice_LightController "; return(false); } IJFDevice_LightController md = dev as IJFDevice_LightController; if (!md.IsInitOK) { errorInfo = "LightCtrl:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"未完成初始化动作 "; return(false); } if (!md.IsDeviceOpen) { errorInfo = "LightCtrl:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"未打开 "; return(false); } if (cellInfo.ChannelIndex >= md.LightChannelCount) { errorInfo = "LightCtrl:\"" + cellName + "\" Channel = :" + cellInfo.ChannelIndex + "超出设备光源通道数量: " + md.LightChannelCount; return(false); } initor = dev; ci = cellInfo; errorInfo = "Success"; return(true); } else if (category == LightTrig) { cellInfo = nameMgr.GetTrigCtrlChannelInfo(cellName); if (null == cellInfo) { errorInfo = "设备命名表中不存在LightTrig:" + cellName; return(false); } IJFInitializable dev = initorMgr.GetInitor(cellInfo.DeviceID); if (null == dev) { errorInfo = "LightTrig:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"在设备列表中不存在"; return(false); } if (!typeof(IJFDevice_TrigController).IsAssignableFrom(dev.GetType())) { errorInfo = "LightTrig:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"类型不是IJFDevice_TrigController "; return(false); } IJFDevice_TrigController md = dev as IJFDevice_TrigController; if (!md.IsInitOK) { errorInfo = "LightTrig:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"未完成初始化动作 "; return(false); } if (!md.IsDeviceOpen) { errorInfo = "LightTrig:\"" + cellName + "\" 所属设备:\"" + cellInfo.DeviceID + "\"未打开 "; return(false); } if (cellInfo.ChannelIndex >= md.TrigChannelCount) { errorInfo = "LightTrig:\"" + cellName + "\" Channel = :" + cellInfo.ChannelIndex + "超出设备触发通道数量: " + md.TrigChannelCount; return(false); } initor = dev; ci = cellInfo; errorInfo = "Success"; return(true); } else if (category == Cmr) { IJFInitializable dev = initorMgr.GetInitor(cellName); if (null == dev) { errorInfo = "Camera:\"" + cellName + "\" 在设备列表中不存在"; return(false); } if (!typeof(IJFDevice_Camera).IsAssignableFrom(dev.GetType())) { errorInfo = "Camera:\"" + cellName + "\" 设备类型不是IJFDevice_Camera "; return(false); } initor = dev; errorInfo = "Success"; return(true); } else { errorInfo = "不支持的参数项\"category\" = " + category; } return(false); }
///// <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); }
protected override bool ActionGenuine(out string errorInfo) { string chnID = GetInitParamValue("触发通道ID") as string; bool isAutoSwitchWorkMode = (bool)GetInitParamValue("自动切换到触发模式"); bool isAutoEnable = (bool)GetInitParamValue("自动使能"); int intensity = (int)GetInitParamValue("触发强度"); bool ignoreIntensity = (bool)GetInitParamValue("忽略不支持强度设置"); int duration = (int)GetInitParamValue("触发时长"); bool ignoreDuration = (bool)GetInitParamValue("忽略不支持时长设置"); int[] srcChannels = GetInitParamValue("输入源通道") as int[]; bool ignoreSrcChannels = (bool)GetInitParamValue("忽略不支持源通道设置"); IJFInitializable initor = null; JFDevCellInfo ci = null; if (!JFCMFunction.CheckDevCellName(JFCMFunction.LightTrig, chnID, out initor, out ci, out errorInfo)) { return(false); } int errCode = 0; IJFDevice_TrigController dev = initor as IJFDevice_TrigController; if (typeof(IJFDevice_LightControllerWithTrig).IsAssignableFrom(dev.GetType())) //当前设备同时也是开关式光源控制器 { IJFDevice_LightControllerWithTrig lightCtrlWithT = dev as IJFDevice_LightControllerWithTrig; JFLightWithTrigWorkMode wm; errCode = lightCtrlWithT.GetWorkMode(out wm); if (errCode != 0) { errorInfo = "获取工作模式失败:" + lightCtrlWithT.GetErrorInfo(errCode); return(false); } if (wm == JFLightWithTrigWorkMode.TurnOnOff) //当前处于开关模式 { if (!isAutoSwitchWorkMode) { errorInfo = "当前工作模式为开关光源模式"; return(false); } errCode = lightCtrlWithT.SetWorkMode(JFLightWithTrigWorkMode.Trigger); if (errCode != 0) { errorInfo = "未能将光源控制器切换为触发模式:" + lightCtrlWithT.GetErrorInfo(errCode); return(false); } } } bool isChnEnabled = false; errCode = dev.GetTrigChannelEnable(ci.ChannelIndex, out isChnEnabled); if (0 != errCode) { errorInfo = "获取通道使能状态失败:" + dev.GetErrorInfo(errCode); return(false); } if (!isChnEnabled) { if (!isAutoEnable) { errorInfo = "触发通道当前未使能"; return(false); } errCode = dev.SetTrigChannelEnable(ci.ChannelIndex, true); if (errCode != 0) { errorInfo = "使能触发通道失败:" + dev.GetErrorInfo(errCode); return(false); } } if (null != srcChannels && srcChannels.Length != 0) //需要绑定输入源通道 { int mask = 0; //输入通道掩码 foreach (int srcChn in srcChannels) { mask += 1 << mask; } errCode = dev.SetTrigChannelSrc(ci.ChannelIndex, mask); if (errCode != 0 && !ignoreSrcChannels) { errorInfo = "绑定触发源通道失败:" + dev.GetErrorInfo(errCode); return(false); } } errCode = dev.SetTrigChannelIntensity(ci.ChannelIndex, intensity); if (errCode != 0 && !ignoreIntensity) { errorInfo = "设置触发强度:" + intensity + " 失败:" + dev.GetErrorInfo(errCode); return(false); } errCode = dev.SetTrigChannelDuration(ci.ChannelIndex, duration); if (errCode != 0 && !ignoreDuration) { errorInfo = "设置触发时长:" + duration + " 失败:" + dev.GetErrorInfo(errCode); return(false); } errorInfo = "Success"; return(true); }
DevNodeCategory _currNodeCategory = DevNodeCategory.MotionDaqDev; //当前点击的节点类型 private void tvDevs_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right)//判断右键 { Point ClickPoint = new Point(e.X, e.Y); TreeNode nodeClicked = tvDevs.GetNodeAt(ClickPoint); if (null == nodeClicked) { return; } tvDevs.SelectedNode = nodeClicked; DevNodeInfo nodeInfo = nodeClicked.Tag as DevNodeInfo; if (null == nodeInfo) { return; } if (nodeInfo.Categoty == DevNodeCategory.MotionDaqDev) { contextMenuDev.Items["ToolStripMenuItemResetDevsModuleCount"].Text = "修改模块数量"; if (JFHubCenter.Instance.InitorManager.GetIDs(typeof(IJFDevice_MotionDaq)).Contains(nodeInfo.DevID)) { contextMenuDev.Items["ToolStripMenuItemOpenCloseDev"].Enabled = true; IJFDevice_MotionDaq dev = JFHubCenter.Instance.InitorManager.GetInitor(nodeInfo.DevID) as IJFDevice_MotionDaq; if (dev.IsDeviceOpen) { contextMenuDev.Items["ToolStripMenuItemOpenCloseDev"].Text = "关闭设备"; } else { contextMenuDev.Items["ToolStripMenuItemOpenCloseDev"].Text = "打开设备"; } } else { contextMenuDev.Items["ToolStripMenuItemOpenCloseDev"].Enabled = false; contextMenuDev.Items["ToolStripMenuItemOpenCloseDev"].Text = "无效设备"; } } else if (nodeInfo.Categoty == DevNodeCategory.LightCtrlTDev || nodeInfo.Categoty == DevNodeCategory.TrigCtrlDev) { contextMenuDev.Items["ToolStripMenuItemResetDevsModuleCount"].Text = "修改通道数量"; if (JFHubCenter.Instance.InitorManager.GetIDs(typeof(IJFDevice_TrigController)).Contains(nodeInfo.DevID)) { contextMenuDev.Items["ToolStripMenuItemOpenCloseDev"].Enabled = true; IJFDevice_TrigController dev = JFHubCenter.Instance.InitorManager.GetInitor(nodeInfo.DevID) as IJFDevice_TrigController; if (dev.IsDeviceOpen) { contextMenuDev.Items["ToolStripMenuItemOpenCloseDev"].Text = "关闭设备"; } else { contextMenuDev.Items["ToolStripMenuItemOpenCloseDev"].Text = "打开设备"; } } else { contextMenuDev.Items["ToolStripMenuItemOpenCloseDev"].Enabled = false; contextMenuDev.Items["ToolStripMenuItemOpenCloseDev"].Text = "无效设备"; } } else if (nodeInfo.Categoty == DevNodeCategory.LightCtrlTDev) { contextMenuDev.Items["ToolStripMenuItemResetDevsModuleCount"].Text = "修改通道数量"; if (JFHubCenter.Instance.InitorManager.GetIDs(typeof(IJFDevice_LightControllerWithTrig)).Contains(nodeInfo.DevID)) { contextMenuDev.Items["ToolStripMenuItemOpenCloseDev"].Enabled = true; IJFDevice_LightControllerWithTrig dev = JFHubCenter.Instance.InitorManager.GetInitor(nodeInfo.DevID) as IJFDevice_LightControllerWithTrig; if (dev.IsDeviceOpen) { contextMenuDev.Items["ToolStripMenuItemOpenCloseDev"].Text = "关闭设备"; } else { contextMenuDev.Items["ToolStripMenuItemOpenCloseDev"].Text = "打开设备"; } } else { contextMenuDev.Items["ToolStripMenuItemOpenCloseDev"].Enabled = false; contextMenuDev.Items["ToolStripMenuItemOpenCloseDev"].Text = "无效设备"; } } } else if (e.Button == MouseButtons.Left) //左键 { Point ClickPoint = new Point(e.X, e.Y); TreeNode nodeClicked = tvDevs.GetNodeAt(ClickPoint); if (null == nodeClicked) { return; } DevNodeInfo nodeInfo = nodeClicked.Tag as DevNodeInfo; if (null == nodeInfo) { return; } panel1.Controls.Clear(); _currNodeCategory = nodeInfo.Categoty; switch (nodeInfo.Categoty) { case DevNodeCategory.MotionDaqDev: timer1.Enabled = false; break; case DevNodeCategory.DioModule: ucDioNames.UpdateChannelsInfo(nodeInfo.DevID, nodeInfo.ModuleIndex); panel1.Controls.Add(ucDioNames); ucDioNames.Dock = DockStyle.Fill; timer1.Enabled = true; break; case DevNodeCategory.MotionModule: timer1.Enabled = true; ucAxisNames.UpdateChannelsInfo(nodeInfo.DevID, nodeInfo.ModuleIndex); panel1.Controls.Add(ucAxisNames); ucAxisNames.Dock = DockStyle.Fill; timer1.Enabled = true; break; case DevNodeCategory.AioModule: ucAioNames.UpdateChannelsInfo(nodeInfo.DevID, nodeInfo.ModuleIndex); panel1.Controls.Add(ucAioNames); ucAioNames.Dock = DockStyle.Fill; timer1.Enabled = true; break; case DevNodeCategory.CmpTrigModule: ucCmpTrigNames.UpdateChannelsInfo(nodeInfo.DevID, nodeInfo.ModuleIndex); panel1.Controls.Add(ucCmpTrigNames); ucCmpTrigNames.Dock = DockStyle.Fill; timer1.Enabled = true; break; case DevNodeCategory.TrigCtrlDev: ucTrigCtrlNames.UpdateChannelsInfo(nodeInfo.DevID); panel1.Controls.Add(ucTrigCtrlNames); ucTrigCtrlNames.Dock = DockStyle.Fill; timer1.Enabled = true; break; case DevNodeCategory.LightCtrlTDev: ucLightCtrlNames.UpdateChannelsInfo(nodeInfo.DevID); panel1.Controls.Add(ucLightCtrlNames); ucLightCtrlNames.Dock = DockStyle.Fill; timer1.Enabled = true; break; } } }