public List <String> GetLeaf(string path)
        {
            List <string> list     = new List <string>();
            Array         branches = path.Substring(path.IndexOf("/") + 1, path.Length - path.IndexOf("/") - 1).Split('/');

            opcBrowser.MoveTo(branches);
            opcBrowser.ShowLeafs(false);
            foreach (var branch in opcBrowser)
            {
                list.Add(branch.ToString());
            }
            opcBrowser.MoveToRoot();
            return(list);
        }
예제 #2
0
        /// <summary>
        /// OPCBrowser遍历组下一层节点,并构建Tree节点
        /// </summary>
        /// <param name="nodeId"></param>
        public List <OpcNode> ShowBranches(string nodeId = "")
        {
            if (nodeId.IsNullOrEmpty())
            {
                //返回根节点,需要顺序执行下列3个函数。
                oPCBrowser.MoveTo(oPCBrowser.CurrentPosition.Split('.'));
                oPCBrowser.ShowLeafs(true);
                oPCBrowser.MoveToRoot();
            }
            else
            {
                oPCBrowser.MoveTo(nodeId.Split('.'));
            }

            oPCBrowser.ShowBranches();
            List <OpcNode> listNode = Task.Run(() =>
            {
                List <OpcNode> list = new List <OpcNode>();
                foreach (object branch in oPCBrowser)
                {
                    string key          = "ClassIcon";
                    bool isExpand       = false;
                    string branchNodeId = "";
                    //拼接nodeId
                    if (nodeId.IsNullOrEmpty())
                    {
                        branchNodeId = branch.ToString();
                    }
                    else
                    {
                        branchNodeId = nodeId + "." + branch.ToString();
                    }
                    oPCBrowser.MoveDown(branch.ToString());
                    oPCBrowser.ShowBranches();
                    if (oPCBrowser.Count > 0)
                    {
                        isExpand = true;
                    }
                    var child = new OpcNode(branch.ToString(), branchNodeId, key, isExpand);
                    list.Add(child);
                    oPCBrowser.MoveUp();
                }
                return(list);
            }
                                               ).Result;

            oPCBrowser.MoveToRoot();
            return(listNode);
        }
예제 #3
0
        /// <summary>
        /// 列出OPC服务器中所有节点
        /// </summary>
        /// <param name="oPCBrowser"></param>
        private void RecurBrowse(OPCBrowser oPCBrowser)
        {
            ItemTreeNode.Nodes.Clear();
            //建树
            oPCBrowser.MoveToRoot();
            TreeNode root = ItemTreeNode.Nodes.Add("Root");

            BuildBranchTree(ref root, oPCBrowser);
        }
예제 #4
0
        public List <string> GetBranch(string position)
        {
            List <string> branchs = new List <string>();

            string[] desName = position.ToString().Split('.');
            Browser.MoveTo(desName);
            Browser.ShowBranches();
            IEnumerator enumerator = Browser.GetEnumerator();

            //树
            while (enumerator.MoveNext())
            {
                if (enumerator.Current != null)
                {
                    branchs.Add(enumerator.Current.ToString());
                }
            }

            Browser.MoveToRoot();
            return(branchs);
        }
예제 #5
0
 /// <summary>
 /// 遍历该分支节点下所有的叶节点
 /// </summary>
 /// <param name="node"></param>
 /// <param name="oPCBrowser"></param>
 private void ListLeaf(ref TreeNode node, OPCBrowser oPCBrowser)
 {
     if (null == node)
     {
         oPCBrowser.MoveToRoot();
         node = ItemTreeNode.Nodes.Add("Root");
     }
     else
     {//剔除无意义的Root根节点
         List <string> BranchesList = new List <string>();
         BranchesList.AddRange(node.FullPath.Split('\\'));
         BranchesList.RemoveAt(0);
         Array Branches = BranchesList.ToArray();
         oPCBrowser.MoveTo(ref Branches);
     }
     oPCBrowser.ShowLeafs(false);//false不展开子集叶,true展开所有子集叶
     foreach (object item in oPCBrowser)
     {
         node.Nodes.Add(item.ToString());
     }
     oPCBrowser.ShowBranches();
 }