public void UpdateChannelsInfo(string devID, int moduleIndex) { lstTbTrigIDs.Clear(); pnTrigs.Controls.Clear(); JFDevCellNameManeger mgr = JFHubCenter.Instance.MDCellNameMgr; IJFModule_CmprTrigger md = null; IJFDevice_MotionDaq dev = JFHubCenter.Instance.InitorManager.GetInitor(devID) as IJFDevice_MotionDaq; if (dev != null && dev.CompareTriggerCount > moduleIndex) { md = dev.GetCompareTrigger(moduleIndex); } int trigChannCount = mgr.GetCmpTrigCount(devID, moduleIndex); for (int i = 0; i < trigChannCount; i++) { Label lb = new Label(); lb.Location = new Point(2, 2 + 5 + 33 * i); lb.Text = "序号:" + i.ToString("D2") + "名称:"; pnTrigs.Controls.Add(lb); TextBox tbID = new TextBox(); tbID.Location = new Point(lb.Right, 2 + 33 * i); tbID.Text = mgr.GetCmpTrigName(devID, moduleIndex, i); tbID.BackColor = SystemColors.Control; tbID.ReadOnly = true; tbID.Width = 200; pnTrigs.Controls.Add(tbID); lstTbTrigIDs.Add(tbID); UcCmprTrgChn ucTrig = new UcCmprTrgChn(); ucTrig.Location = new Point(tbID.Right, 2 + 33 * i); ucTrig.SetModuleChn(md, i, "", null); pnTrigs.Controls.Add(ucTrig); } }
/// <summary> /// 更新模块的通道信息 /// </summary> /// <param name="nodeChannel"></param> void _UpdateChannelNode(TreeNode nodeChannel) { DevNodeInfo nodeInfo = nodeChannel.Tag as DevNodeInfo; JFDevCellNameManeger mgr = JFHubCenter.Instance.MDCellNameMgr; if (nodeInfo.Categoty == DevNodeCategory.DioModule) { nodeChannel.Text = "序号_" + nodeInfo.ModuleIndex + ",DI数:" + mgr.GetDiChannelCount(nodeInfo.DevID, nodeInfo.ModuleIndex) + ",DO数:" + mgr.GetDoChannelCount(nodeInfo.DevID, nodeInfo.ModuleIndex); ucDioNames.UpdateChannelsInfo(nodeInfo.DevID, nodeInfo.ModuleIndex); } else if (nodeInfo.Categoty == DevNodeCategory.MotionModule) { nodeChannel.Text = "序号_" + nodeInfo.ModuleIndex + ",轴数:" + mgr.GetAxisCount(nodeInfo.DevID, nodeInfo.ModuleIndex); ucAxisNames.UpdateChannelsInfo(nodeInfo.DevID, nodeInfo.ModuleIndex); } else if (nodeInfo.Categoty == DevNodeCategory.CmpTrigModule) { nodeChannel.Text = "序号_" + nodeInfo.ModuleIndex + ",通道数:" + mgr.GetCmpTrigCount(nodeInfo.DevID, nodeInfo.ModuleIndex); ucCmpTrigNames.UpdateChannelsInfo(nodeInfo.DevID, nodeInfo.ModuleIndex); } else if (nodeInfo.Categoty == DevNodeCategory.AioModule) { nodeChannel.Text = "序号_" + nodeInfo.ModuleIndex + ",AI数:" + mgr.GetAiChannelCount(nodeInfo.DevID, nodeInfo.ModuleIndex) + ",AO数:" + mgr.GetAoChannelCount(nodeInfo.DevID, nodeInfo.ModuleIndex); ucAioNames.UpdateChannelsInfo(nodeInfo.DevID, nodeInfo.ModuleIndex); } }
/// <summary>初始化HubCenter</summary> void Initialize() { dataPool = new JFDataPool(); string chkError = ""; string sysCfgFile = SystemCfgFilePath; while (string.IsNullOrEmpty(sysCfgFile) || //系统配置文件未设置 !File.Exists(sysCfgFile) || //系统配置文件已设置,但是文件不存在 !_CheckSysCfg(sysCfgFile, false, out chkError)) //系统文件已存在,但是格式不正确 { FormSelCfg fm = new FormSelCfg(); if (string.IsNullOrEmpty(sysCfgFile)) { fm.Tips = "系统配置文件未设置!"; } else if (!File.Exists(sysCfgFile)) { fm.Tips = "系统配置文件:" + "\"" + sysCfgFile + "\"不存在!\n请检查路径或选择/创建新的配置文件"; } else//(!_CheckSysCfg(SystemCfgFilePath,false)) //文件已存在,但格式不正确(缺少必要的数据项) { fm.Tips = "系统配置文件:" + "\"" + sysCfgFile + "\"格式错误!\nError:" + chkError + "\n请检查文件或选择/创建新的配置文件"; } fm.ShowDialog();//////////FormInitHub.ShowDialog()中有退出程序的出口,如果运行到下一步,肯定是已经选择了配置文件 sysCfgFile = fm.SysCfgFilePath; if (_CheckSysCfg(sysCfgFile, true, out chkError)) { SetSystemCfgFilePath(sysCfgFile);//退出程序,重新启动 break; } }//end while , 系统配置文件检查OK SystemCfg = new JFXCfg(); SystemCfg.Load(sysCfgFile, false); InitorHelp = new JFinitializerHelper(); //加载JFDll库文件 List <string> dllFiles = SystemCfg.GetItemValue(CK_ExpandDllFiles) as List <string>; foreach (string dllFile in dllFiles) { try { InitorHelp.AppendDll(dllFile); } catch (Exception ex) { MessageBox.Show("Hub-Center 加载dll = \"" + dllFile + "\"异常:\n" + ex); } } _mdCellNameMgr = new JFDevCellNameManeger(sysCfgFile);//运动控制卡单元名称管理 return; }
/// <summary> /// 向树形控件添加一个运动控制设备节点 /// </summary> /// <param name="devID"></param> void _AddDevNode(string devID, DevNodeCategory category) { TreeNode devNode = new TreeNode(devID); devNode.Tag = new DevNodeInfo(devID, /*DevNodeCategory.MotionDaqDev*/ category, 0); devNode.ContextMenuStrip = contextMenuDev; JFDevCellNameManeger mgr = JFHubCenter.Instance.MDCellNameMgr; tvDevs.Nodes[0].Nodes.Add(devNode); _UpdateModuleNode(devNode); }
/// <summary> /// 修改Module所属的通道数量 轴/Dio/Aio/Trig等等 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ToolStripMenuItemResetChannelCount_Click(object sender, EventArgs e) { TreeNode currNode = tvDevs.SelectedNode; DevNodeInfo nodeInfo = currNode.Tag as DevNodeInfo; JFDevCellNameManeger mgr = JFHubCenter.Instance.MDCellNameMgr; FormSetModuleChnCount fm = new FormSetModuleChnCount(); if (nodeInfo.Categoty == DevNodeCategory.MotionModule) { fm.Category = FormSetModuleChnCount.ModuleCategory.Motion; fm.ChannelCount1 = mgr.GetAxisCount(nodeInfo.DevID, nodeInfo.ModuleIndex); if (fm.ShowDialog() == DialogResult.OK) { mgr.SetAxisCount(nodeInfo.DevID, nodeInfo.ModuleIndex, fm.ChannelCount1); _UpdateChannelNode(currNode);//_UpdateCfg2UI(); } } else if (nodeInfo.Categoty == DevNodeCategory.CmpTrigModule) { fm.Category = FormSetModuleChnCount.ModuleCategory.Trig; fm.ChannelCount1 = mgr.GetCmpTrigCount(nodeInfo.DevID, nodeInfo.ModuleIndex); if (fm.ShowDialog() == DialogResult.OK) { mgr.SetCmpTrigCount(nodeInfo.DevID, nodeInfo.ModuleIndex, fm.ChannelCount1); _UpdateChannelNode(currNode);//_UpdateCfg2UI(); } } else if (nodeInfo.Categoty == DevNodeCategory.DioModule) { fm.Category = FormSetModuleChnCount.ModuleCategory.Dio; fm.ChannelCount1 = mgr.GetDiChannelCount(nodeInfo.DevID, nodeInfo.ModuleIndex); fm.ChannelCount2 = mgr.GetDoChannelCount(nodeInfo.DevID, nodeInfo.ModuleIndex); if (fm.ShowDialog() == DialogResult.OK) { mgr.SetDiChannelCount(nodeInfo.DevID, nodeInfo.ModuleIndex, fm.ChannelCount1); mgr.SetDoChannelCount(nodeInfo.DevID, nodeInfo.ModuleIndex, fm.ChannelCount2); _UpdateChannelNode(currNode);////_UpdateCfg2UI(); } } else if (nodeInfo.Categoty == DevNodeCategory.AioModule) { fm.Category = FormSetModuleChnCount.ModuleCategory.Aio; fm.ChannelCount1 = mgr.GetAiChannelCount(nodeInfo.DevID, nodeInfo.ModuleIndex); fm.ChannelCount2 = mgr.GetAoChannelCount(nodeInfo.DevID, nodeInfo.ModuleIndex); if (fm.ShowDialog() == DialogResult.OK) { mgr.SetAiChannelCount(nodeInfo.DevID, nodeInfo.ModuleIndex, fm.ChannelCount1); mgr.SetAoChannelCount(nodeInfo.DevID, nodeInfo.ModuleIndex, fm.ChannelCount2); _UpdateChannelNode(currNode);// _UpdateCfg2UI(); } } }
public void UpdateChannelsInfo(string devID, int moduleIndex) { //int nBottom = 0; pnAi.Controls.Clear(); pnAo.Controls.Clear(); JFDevCellNameManeger mgr = JFHubCenter.Instance.MDCellNameMgr; IJFModule_AIO md = null; IJFDevice_MotionDaq dev = JFHubCenter.Instance.InitorManager.GetInitor(devID) as IJFDevice_MotionDaq; if (dev != null && dev.DioCount > moduleIndex) { md = dev.GetAio(moduleIndex); } int AiCount = mgr.GetAiChannelCount(devID, moduleIndex); for (int i = 0; i < AiCount; i++) { Label lbIndex = new Label(); lbIndex.Text = i.ToString("D2"); lbIndex.Location = new Point(2, 10 + i * 33 + 2); lbIndex.Width = 30; pnAi.Controls.Add(lbIndex); UcAIOChn ucAi = new UcAIOChn(); pnAi.Controls.Add(ucAi); ucAi.Location = new Point(32, 2 + i * 33); ucAi.Width = pnAi.Width - 34; ucAi.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; ucAi.SetIOInfo(md, i, false, mgr.GetAiName(devID, moduleIndex, i)); //nBottom = ucAi.Bottom; } int aoCount = mgr.GetAoChannelCount(devID, moduleIndex); for (int i = 0; i < aoCount; i++) { Label lbIndex = new Label(); lbIndex.Text = i.ToString("D2"); lbIndex.Location = new Point(2, 10 + i * 33 + 2); lbIndex.Width = 30; pnAo.Controls.Add(lbIndex); UcAIOChn ucAo = new UcAIOChn(); pnAo.Controls.Add(ucAo); ucAo.Location = new Point(32, 2 + i * 33); ucAo.Width = pnAi.Width - 34; ucAo.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; ucAo.SetIOInfo(md, i, true, mgr.GetAoName(devID, moduleIndex, i)); //if (nBottom < ucAo.Bottom) // nBottom = ucAo.Bottom; } //rtTips.Top = nBottom + 10; }
void _UpdateCmpTrig() { JFDevCellNameManeger nameMgr = JFHubCenter.Instance.MDCellNameMgr; if (null == nameMgr.AllCmpTrigNames() || 0 == nameMgr.AllCmpTrigNames().Length) //系统中不存在已命名的AI通道 { ShowTips("系统配置中不存在已命名的CmpTrig通道!"); btAdd.Enabled = false; } else { btAdd.Enabled = true; } string[] cmpTrigNames = _station.CmpTrigNames; if (null == cmpTrigNames || 0 == cmpTrigNames.Length) { btDel.Enabled = false; return; } else//if(null != chnNames) { btDel.Enabled = true; foreach (string cmpTrigName in cmpTrigNames) { DataGridViewRow row = new DataGridViewRow(); DataGridViewTextBoxCell cellName = new DataGridViewTextBoxCell(); cellName.Value = cmpTrigName; DataGridViewTextBoxCell cellInfo = new DataGridViewTextBoxCell(); JFDevCellInfo devInfo = nameMgr.GetCmpTrigCellInfo(cmpTrigName); if (null == devInfo) { cellName.Style.ForeColor = Color.Red; cellInfo.Value = "无效的通道名称,在配置中不存在!"; cellInfo.Style.ForeColor = Color.Red; } else { 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); } } }
/// <summary> /// 向UI更新工站的AI命名通道 /// </summary> void _UpdateAI() { JFDevCellNameManeger nameMgr = JFHubCenter.Instance.MDCellNameMgr; string[] allAIs = nameMgr.AllAiNames(); //系统中所有可用的AI命名通道 string[] aiNames = _station.AINames; //工站中已配置的AI通道 if (null == allAIs || 0 == allAIs.Length) { ShowTips("系统配置中不存在已命名的AI通道!"); btAdd.Enabled = false; } else { btAdd.Enabled = true; } if (null == aiNames || 0 == aiNames.Length) { btDel.Enabled = false; return; } else//if(null != chnNames) { btDel.Enabled = true; foreach (string aiName in aiNames) { DataGridViewRow row = new DataGridViewRow(); DataGridViewTextBoxCell cellName = new DataGridViewTextBoxCell(); cellName.Value = aiName; DataGridViewTextBoxCell cellInfo = new DataGridViewTextBoxCell(); JFDevCellInfo devInfo = nameMgr.GetAiCellInfo(aiName); if (null == devInfo) { cellName.Style.ForeColor = Color.Red; cellInfo.Value = "无效的通道名称,在配置中不存在!"; cellInfo.Style.ForeColor = Color.Red; } else { 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 UpdateChannelsInfo(string devID, int moduleIndex) { lstTbAxisIDs.Clear(); pnAxes.Controls.Clear(); JFDevCellNameManeger mgr = JFHubCenter.Instance.MDCellNameMgr; IJFModule_Motion md = null; IJFDevice_MotionDaq dev = JFHubCenter.Instance.InitorManager.GetInitor(devID) as IJFDevice_MotionDaq; if (dev != null && dev.DioCount > moduleIndex) { md = dev.GetMc(moduleIndex); } int axisCount = mgr.GetAxisCount(devID, moduleIndex); for (int i = 0; i < axisCount; i++) { Label lbIndex = new Label(); lbIndex.Text = "轴序号:" + i.ToString("D2") + " 轴ID:"; lbIndex.Location = new Point(2, 5 + i * 70 + 2); pnAxes.Controls.Add(lbIndex); TextBox tbAxisID = new TextBox(); tbAxisID.Location = new Point(lbIndex.Right, i * 70 + 2); string axisID = mgr.GetAxisName(devID, moduleIndex, i); tbAxisID.Text = axisID; tbAxisID.Enabled = false; tbAxisID.BackColor = SystemColors.Control; pnAxes.Controls.Add(tbAxisID); lstTbAxisIDs.Add(tbAxisID); UcAxisStatus ucas = new UcAxisStatus(); tbAxisID.Width = ucas.Width - 5 - lbIndex.Width; pnAxes.Controls.Add(ucas); ucas.Location = new Point(2, lbIndex.Bottom - 3); //ucas.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; ucas.DisplayMode = UcAxisStatus.JFDisplayMode.simple; //ucDi.SetDioInfo(md, moduleIndex, false, mgr.GetDiName(devID, moduleIndex, i)); ucas.SetAxis(md, i); UcAxisTest ucat = new UcAxisTest(); ucat.DisplayMode = UcAxisTest.JFDisplayMode.simplest_vel; ucat.Location = new Point(ucas.Right, tbAxisID.Top); pnAxes.Controls.Add(ucat); ucat.SetAxis(md, i); } }
public void UpdateChannelsInfo(string devID, int moduleIndex) { pnDi.Controls.Clear(); pnDo.Controls.Clear(); JFDevCellNameManeger mgr = JFHubCenter.Instance.MDCellNameMgr; IJFModule_DIO md = null; IJFDevice_MotionDaq dev = JFHubCenter.Instance.InitorManager.GetInitor(devID) as IJFDevice_MotionDaq; if (dev != null && dev.DioCount > moduleIndex) { md = dev.GetDio(moduleIndex); } int diCount = mgr.GetDiChannelCount(devID, moduleIndex); for (int i = 0; i < diCount; i++) { Label lbIndex = new Label(); lbIndex.Text = i.ToString("D2"); lbIndex.Location = new Point(2, 10 + i * 33 + 2); lbIndex.Width = 30; pnDi.Controls.Add(lbIndex); UcDioChn ucDi = new UcDioChn(); pnDi.Controls.Add(ucDi); ucDi.Location = new Point(32, 2 + i * 33); ucDi.Width = pnDi.Width - 34; ucDi.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; ucDi.SetDioInfo(md, i, false, mgr.GetDiName(devID, moduleIndex, i)); } int doCount = mgr.GetDoChannelCount(devID, moduleIndex); for (int i = 0; i < doCount; i++) { Label lbIndex = new Label(); lbIndex.Text = i.ToString("D2"); lbIndex.Location = new Point(2, 10 + i * 33 + 2); lbIndex.Width = 30; pnDo.Controls.Add(lbIndex); UcDioChn ucDo = new UcDioChn(); pnDo.Controls.Add(ucDo); ucDo.Location = new Point(32, 2 + i * 33); ucDo.Width = pnDi.Width - 34; ucDo.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; ucDo.SetDioInfo(md, i, true, mgr.GetDoName(devID, moduleIndex, i)); } }
void _UpdateCfg2UI() { tvDevs.Nodes[0].Nodes.Clear(); JFDevCellNameManeger mgr = JFHubCenter.Instance.MDCellNameMgr; string[] devIDs = mgr.AllMotionDaqDevices(); if (null != devIDs) { foreach (string devID in devIDs) { _AddDevNode(devID, DevNodeCategory.MotionDaqDev); } } string[] lightDevIDs = mgr.AllLightCtrlDevs(); if (null != lightDevIDs) { foreach (string lightDevID in lightDevIDs) { _AddDevNode(lightDevID, DevNodeCategory.LightCtrlTDev); } } string[] trigDevIDs = mgr.AllTrigCtrlDevs(); //触发控制器 if (null != trigDevIDs) { foreach (string trigDevID in trigDevIDs) { if (!typeof(IJFDevice_LightController).IsAssignableFrom(JFHubCenter.Instance.InitorManager.GetInitor(trigDevID).GetType())) //去除光源控制器设备 { _AddDevNode(trigDevID, DevNodeCategory.TrigCtrlDev); } } } }
/// <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); }
void _AddDINames() { string[] allChnNames = null; //系统中所有已命名的通道 string[] existChnNames = null; //已存在的通道名称 JFDevCellNameManeger nameMgr = JFHubCenter.Instance.MDCellNameMgr; allChnNames = nameMgr.AllDiNames(); //系统名称表中所有可用的DI通道名称 existChnNames = _station.DINames; //工站中已有的DI通道名称 if (null == allChnNames || 0 == allChnNames.Length) { MessageBox.Show("不存在" + _chnType.ToString() + "命名通道"); return; } List <string> lstAddNames = new List <string>(); //可供添加的DI通道名称 if (null == existChnNames || 0 == existChnNames.Length) { lstAddNames.AddRange(allChnNames); } else { foreach (string chnName in allChnNames) { if (!existChnNames.Contains(chnName)) { lstAddNames.Add(chnName); } } } if (lstAddNames.Count == 0) { MessageBox.Show("没有可供添加的" + _chnType.ToString() + "命名通道"); return; } List <string> lstAddInfos = new List <string>(); foreach (string addName in lstAddNames) { JFDevCellInfo chnInfo = nameMgr.GetDiCellInfo(addName); lstAddInfos.Add(string.Format("控制器:{0} - 模块:{1} - 通道:{2}", chnInfo.DeviceID, chnInfo.ModuleIndex, chnInfo.ChannelIndex)); } FormAddNames frm = new FormAddNames(); frm.Text = "为工站:" + _station.Name + " 添加Di命名通道"; frm.SetAvailedNames(lstAddNames.ToArray(), lstAddInfos.ToArray()); if (DialogResult.OK == frm.ShowDialog()) { string[] chnNamesWillAdd = null; string[] chnInfosWillAdd = null; frm.GetSelectNameInfos(out chnNamesWillAdd, out chnInfosWillAdd); for (int i = 0; i < chnNamesWillAdd.Length; i++) { string chnName = chnNamesWillAdd[i]; _station.AddDI(chnName); } _station.SaveCfg(); UpdateStation2UI(); } }
/// <summary> /// 开始编辑/保存通道名称 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ToolStripMenuItemEditSave_Click(object sender, EventArgs e) { DevNodeInfo nodeInfo = tvDevs.SelectedNode.Tag as DevNodeInfo; if (!isChannelNameEditting) //开始编辑 { isChannelNameEditting = true; if (nodeInfo.Categoty == DevNodeCategory.DioModule) { ucDioNames.BeginEdit(); } else if (nodeInfo.Categoty == DevNodeCategory.MotionModule) { ucAxisNames.BeginEdit(); } else if (nodeInfo.Categoty == DevNodeCategory.CmpTrigModule) { ucCmpTrigNames.BeginEdit(); } else if (nodeInfo.Categoty == DevNodeCategory.AioModule) { ucAioNames.BeginEdit(); } else if (nodeInfo.Categoty == DevNodeCategory.TrigCtrlDev) //编辑触发控制器通道名称 { ucTrigCtrlNames.BeginEdit(); } else if (nodeInfo.Categoty == DevNodeCategory.LightCtrlTDev) { ucLightCtrlNames.BeginEdit(); } ToolStripMenuItemEditSave.Text = "保存名称"; ToolStripMenuItemEditCancel.Enabled = true; tvDevs.Enabled = false; } else //尝试保存并结束编辑状态 { JFDevCellNameManeger mgr = JFHubCenter.Instance.MDCellNameMgr; string errInfo = ""; if (nodeInfo.Categoty == DevNodeCategory.DioModule) { string[] diNames = ucDioNames.DiNames; string[] doNames = ucDioNames.DoNames; if (!mgr.SetDiNames(nodeInfo.DevID, nodeInfo.ModuleIndex, ucDioNames.DiNames, out errInfo)) { MessageBox.Show("设置DI通道名称失败,错误信息:\n" + errInfo); return; } if (!mgr.SetDoNames(nodeInfo.DevID, nodeInfo.ModuleIndex, ucDioNames.DoNames, out errInfo)) { MessageBox.Show("设置DO通道名称失败,错误信息:\n" + errInfo); return; } ucDioNames.EndEdit(); MessageBox.Show("设置DIO通道名称OK"); } else if (nodeInfo.Categoty == DevNodeCategory.MotionModule) { if (!mgr.SetAxisNames(nodeInfo.DevID, nodeInfo.ModuleIndex, ucAxisNames.AxisNames, out errInfo)) { MessageBox.Show("设置轴通道名称失败,错误信息:\n" + errInfo); return; } ucAxisNames.EndEdit(); MessageBox.Show("设置轴通道名称OK"); } else if (nodeInfo.Categoty == DevNodeCategory.CmpTrigModule) { if (!mgr.SetCmpTrigNames(nodeInfo.DevID, nodeInfo.ModuleIndex, ucCmpTrigNames.TrigNames, out errInfo)) { MessageBox.Show("设置比较触发通道名称失败,错误信息:\n" + errInfo); return; } ucCmpTrigNames.EndEdit(); MessageBox.Show("设置比较触发通道名称OK"); } else if (nodeInfo.Categoty == DevNodeCategory.AioModule) { if (!mgr.SetAiNames(nodeInfo.DevID, nodeInfo.ModuleIndex, ucAioNames.AiNames, out errInfo)) { MessageBox.Show("设置AI通道名称失败,错误信息:\n" + errInfo); return; } if (!mgr.SetAoNames(nodeInfo.DevID, nodeInfo.ModuleIndex, ucAioNames.AoNames, out errInfo)) { MessageBox.Show("设置AO通道名称失败,错误信息:\n" + errInfo); return; } ucAioNames.EndEdit(); MessageBox.Show("设置AIO通道名称OK"); } else if (nodeInfo.Categoty == DevNodeCategory.TrigCtrlDev) { //ucTrigCtrlNames. if (!mgr.SetTrigCtrlChannelNames(nodeInfo.DevID, ucTrigCtrlNames.ChannelNames(), out errInfo)) { MessageBox.Show("设置触发控制器通道名称失败,错误信息:\n" + errInfo); ucTrigCtrlNames.UpdateChannelsInfo(nodeInfo.DevID); return; } ucTrigCtrlNames.EndEdit(); } else if (nodeInfo.Categoty == DevNodeCategory.LightCtrlTDev) { if (!mgr.SetLightCtrlChannelNames(nodeInfo.DevID, ucLightCtrlNames.LightChannelNames(), out errInfo)) { MessageBox.Show("设置触发控制器通道名称失败,错误信息:\n" + errInfo); ucLightCtrlNames.UpdateChannelsInfo(nodeInfo.DevID); return; } string[] trigChannelNames = ucLightCtrlNames.TrigChannelNames(); if (null == trigChannelNames || 0 == trigChannelNames.Length) { mgr.RemoveLightCtrlDev(nodeInfo.DevID); } else { if (!mgr.SetTrigCtrlChannelNames(nodeInfo.DevID, ucLightCtrlNames.TrigChannelNames(), out errInfo)) { MessageBox.Show("设置触发控制器通道名称失败,错误信息:\n" + errInfo); ucLightCtrlNames.UpdateChannelsInfo(nodeInfo.DevID); return; } } ucLightCtrlNames.EndEdit(); //if (!mgr.SetLightCtrlChannelNames(nodeInfo.DevID, ucTrigCtrlNames.ChannelNames(), out errInfo)) //{ // MessageBox.Show("设置触发控制器通道名称失败,错误信息:\n" + errInfo); // ucTrigCtrlNames.UpdateChannelsInfo(nodeInfo.DevID); // return; //} } ToolStripMenuItemEditSave.Text = "编辑名称"; ToolStripMenuItemEditCancel.Enabled = true; isChannelNameEditting = false; tvDevs.Enabled = true; } }
/// <summary> /// 修改设备所属的模块数量 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ToolStripMenuItemResetDevsModuleCount_Click(object sender, EventArgs e) { TreeNode currNode = tvDevs.SelectedNode; DevNodeInfo nodeInfo = currNode.Tag as DevNodeInfo; JFDevCellNameManeger mgr = JFHubCenter.Instance.MDCellNameMgr; if (nodeInfo.Categoty == DevNodeCategory.MotionDaqDev) //更改运动控制器模块数量 { FormDevModuleInfo fm = new FormDevModuleInfo(); fm.DevID = nodeInfo.DevID; fm.MotionCount = mgr.GetAxisModuleCount(nodeInfo.DevID); fm.DioCount = mgr.GetDioModuleCount(nodeInfo.DevID); fm.AioCount = mgr.GetAioModuleCount(nodeInfo.DevID); fm.TrigCount = mgr.GetCmpTrigModuleCount(nodeInfo.DevID); fm.SettingMode = DevModuleSettingMode.Set; if (DialogResult.OK == fm.ShowDialog()) { mgr.SetAxisModuleCount(nodeInfo.DevID, fm.MotionCount); mgr.SetDioModuleCount(nodeInfo.DevID, fm.DioCount); mgr.SetAioModuleCount(nodeInfo.DevID, fm.AioCount); mgr.SetCmpTrigModuleCount(nodeInfo.DevID, fm.TrigCount); _UpdateModuleNode(currNode);//_UpdateCfg2UI(); } } else if (nodeInfo.Categoty == DevNodeCategory.TrigCtrlDev)//更改触发控制器通道数量 { FormAddMChnDev fm = new FormAddMChnDev(); fm.Text = "修改触发器通道数量"; string[] devIDs = JFHubCenter.Instance.InitorManager.GetIDs(typeof(IJFDevice_TrigController)); //所有触发控制设备ID,过滤掉其中的光源控制器 List <string> trigDevIDs = new List <string>(); fm.SetDeviceID(nodeInfo.DevID); fm.SettingMode = DevModuleSettingMode.Set; fm.SetChannelTypes(new string[] { "触发通道数量:" }); int nCurrChns = JFHubCenter.Instance.MDCellNameMgr.GetTrigCtrlChannelCount(nodeInfo.DevID); fm.ChannelCount = new int[] { nCurrChns }; if (DialogResult.OK != fm.ShowDialog()) { return; } JFHubCenter.Instance.MDCellNameMgr.SetTrigCtrlChannelCount(fm.DeviceID, fm.ChannelCount[0]); _UpdateModuleNode(currNode); } else if (nodeInfo.Categoty == DevNodeCategory.LightCtrlTDev) //更改光源控制器通道数量 { FormAddMChnDev fm = new FormAddMChnDev(); fm.Text = "修改光源通道数量"; // string[] devIDs = JFHubCenter.Instance.InitorManager.GetIDs(typeof(IJFDevice_TrigController)); //所有触发控制设备ID,过滤掉其中的光源控制器 //List<string> trigDevIDs = new List<string>(); fm.SetDeviceID(nodeInfo.DevID); fm.SettingMode = DevModuleSettingMode.Set; fm.SetChannelTypes(new string[] { "开关通道数量", "触发通道数量:" }); int lightChnCount = JFHubCenter.Instance.MDCellNameMgr.GetLightCtrlChannelCount(nodeInfo.DevID); int trigChnCount = JFHubCenter.Instance.MDCellNameMgr.GetTrigCtrlChannelCount(nodeInfo.DevID); fm.ChannelCount = new int[] { lightChnCount, trigChnCount }; if (DialogResult.OK != fm.ShowDialog()) { return; } JFHubCenter.Instance.MDCellNameMgr.SetLightCtrlChannelCount(fm.DeviceID, fm.ChannelCount[0]); JFHubCenter.Instance.MDCellNameMgr.SetTrigCtrlChannelCount(fm.DeviceID, fm.ChannelCount[1]); _UpdateModuleNode(currNode); } }
/// <summary> /// 更新控制卡的模块数量信息 /// </summary> /// <param name="nodeModule"></param> void _UpdateModuleNode(TreeNode nodeModule) { JFDevCellNameManeger mgr = JFHubCenter.Instance.MDCellNameMgr; DevNodeInfo nodeInfo = nodeModule.Tag as DevNodeInfo; if (nodeInfo.Categoty == DevNodeCategory.MotionDaqDev) //更新运动控制设备节点 { nodeModule.Nodes.Clear(); int motionModuleCount = mgr.GetAxisModuleCount(nodeInfo.DevID);//轴模块 if (motionModuleCount > 0) { TreeNode motionsNode = new TreeNode("轴模块"); motionsNode.Tag = new DevNodeInfo(nodeInfo.DevID, DevNodeCategory.Module, 0); nodeModule.Nodes.Add(motionsNode); for (int i = 0; i < motionModuleCount; i++) { TreeNode motionNode = new TreeNode("序号_" + i + ",轴数:" + mgr.GetAxisCount(nodeInfo.DevID, i)); motionNode.Tag = new DevNodeInfo(nodeInfo.DevID, DevNodeCategory.MotionModule, i); motionsNode.Nodes.Add(motionNode); motionNode.ContextMenuStrip = contextMenuModule; } } int dioModuleCount = mgr.GetDioModuleCount(nodeInfo.DevID);//数字IO模块 if (dioModuleCount > 0) { TreeNode diosNode = new TreeNode("Dio模块"); diosNode.Tag = new DevNodeInfo(nodeInfo.DevID, DevNodeCategory.Module, 0); nodeModule.Nodes.Add(diosNode); for (int i = 0; i < dioModuleCount; i++) { TreeNode dioNode = new TreeNode("序号_" + i + ",DI数:" + mgr.GetDiChannelCount(nodeInfo.DevID, i) + ",DO数:" + mgr.GetDoChannelCount(nodeInfo.DevID, i)); dioNode.Tag = new DevNodeInfo(nodeInfo.DevID, DevNodeCategory.DioModule, i); diosNode.Nodes.Add(dioNode); dioNode.ContextMenuStrip = contextMenuModule; } } int trigModuleCount = mgr.GetCmpTrigModuleCount(nodeInfo.DevID);//位置比较触发 if (trigModuleCount > 0) { TreeNode trigsNode = new TreeNode("位置比较触发模块"); trigsNode.Tag = new DevNodeInfo(nodeInfo.DevID, DevNodeCategory.Module, 0); nodeModule.Nodes.Add(trigsNode); for (int i = 0; i < trigModuleCount; i++) { TreeNode trigNode = new TreeNode("序号_" + i + ",通道数:" + mgr.GetCmpTrigCount(nodeInfo.DevID, i)); trigNode.Tag = new DevNodeInfo(nodeInfo.DevID, DevNodeCategory.CmpTrigModule, i); trigsNode.Nodes.Add(trigNode); trigNode.ContextMenuStrip = contextMenuModule; } } int aioModuleCount = mgr.GetAioModuleCount(nodeInfo.DevID); if (aioModuleCount > 0) { TreeNode aiosNode = new TreeNode("Aio模块"); aiosNode.Tag = new DevNodeInfo(nodeInfo.DevID, DevNodeCategory.Module, 0); nodeModule.Nodes.Add(aiosNode); for (int i = 0; i < aioModuleCount; i++) { TreeNode aioNode = new TreeNode("序号_" + i + ",AI数:" + mgr.GetAiChannelCount(nodeInfo.DevID, i) + ",AO数:" + mgr.GetAoChannelCount(nodeInfo.DevID, i)); aioNode.Tag = new DevNodeInfo(nodeInfo.DevID, DevNodeCategory.AioModule, i); aiosNode.Nodes.Add(aioNode); aioNode.ContextMenuStrip = contextMenuModule; } } } else if (nodeInfo.Categoty == DevNodeCategory.LightCtrlTDev) //光源控制器设备节点 { ucLightCtrlNames.UpdateChannelsInfo(nodeInfo.DevID); } else if (nodeInfo.Categoty == DevNodeCategory.TrigCtrlDev) //触发控制器设备节点 { ucTrigCtrlNames.UpdateChannelsInfo(nodeInfo.DevID); } }