예제 #1
0
        private void treeOpcItems_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
        {
            listOpcView.Items.Clear();
            RemoveItem();                               // remove item from group

            try
            {
                theSrv.ChangeBrowsePosition(OPCBROWSEDIRECTION.OPC_BROWSE_TO, ""); // to root

                if (e.Node.FullPath.Length > rootname.Length)                      // check if it's only the dummy root
                {
                    selectednode = e.Node.FullPath.Substring(rootname.Length + 1);
                    string[] splitpath = selectednode.Split(new char[] { '\t' });               // convert path-string to string-array (separator)

                    foreach (string n in splitpath)
                    {
                        theSrv.ChangeBrowsePosition(OPCBROWSEDIRECTION.OPC_BROWSE_DOWN, n);                     // browse to node in OPC namespace
                    }
                }
                else
                {
                    selectednode = "";
                }

                // get all items at this node level
                ArrayList lst;
                theSrv.Browse(OPCBROWSETYPE.OPC_LEAF, out lst);
                if (lst == null)
                {
                    return;
                }
                if (lst.Count < 1)
                {
                    return;
                }

                // enum+add all item names to ListView
                string[] itemstrings = new string[2];
                foreach (string item in lst)
                {
                    itemstrings[0] = item;
                    itemstrings[1] = theSrv.GetItemID(item);
                    listOpcView.Items.Add(new ListViewItem(itemstrings, 0));
                }

                // preselect top item in ListView
                listOpcView.Items[0].Selected = true;
            }
            catch (Exception ex)                // exceptions MUST be handled
            {
                MessageBox.Show(this, "browse error! " + ex.ToString(), "Exception browsing namespace", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
        }
        private void RecursiveServerHierarchialBrowse(ref List <string> p_ItemIds)
        {
            ArrayList l_ItemList;

            _server.Browse(OpcBrowseType.OPC_LEAF, out l_ItemList);
            foreach (string l_ItemName in l_ItemList)
            {
                p_ItemIds.Add(_server.GetItemID(l_ItemName));
            }

            ArrayList l_BranchList;

            _server.Browse(OpcBrowseType.OPC_BRANCH, out l_BranchList);
            foreach (string l_BranchName in l_BranchList)
            {
                _server.ChangeBrowsePosition(OpcBrowseDirection.OPC_BROWSE_DOWN, l_BranchName);
                RecursiveServerHierarchialBrowse(ref p_ItemIds);
                _server.ChangeBrowsePosition(OpcBrowseDirection.OPC_BROWSE_UP, "");
            }
        }
예제 #3
0
        public void TestGetItemID01()
        {
            //testing --
            OpcServer opcServer         = new OpcServer();
            Accessor  opcServerAccessor = ReflectionAccessor.Wrap(opcServer);

            opcServerAccessor.SetField("ifServer", new OPCServerComClass());
            opcServerAccessor.SetField("ifBrowse", ((IOPCBrowseServerAddressSpace)opcServerAccessor.GetField("ifServer")));
            //Test Procedure Call
            opcServer.GetItemID("Item1");
            //Post Condition Check
        }