Exemplo n.º 1
0
        public bool DoBrowse()
        {
            try
            {
                OPCNAMESPACETYPE opcorgi = theSrv.QueryOrganization();

                // fill TreeView with all
                treeOpcItems.Nodes.Clear();
                TreeNode tnRoot = new TreeNode(rootname, 0, 1);
                if (opcorgi == OPCNAMESPACETYPE.OPC_NS_HIERARCHIAL)
                {
                    theSrv.ChangeBrowsePosition(OPCBROWSEDIRECTION.OPC_BROWSE_TO, "");                  // to root
                    RecurBrowse(tnRoot, 1);
                }
                treeOpcItems.Nodes.Add(tnRoot);

                tnRoot.ExpandAll();                     // expand all nodes ([+] -> [-])
                tnRoot.EnsureVisible();                 // make the root visible

                // preselect root (dummy)
                treeOpcItems.SelectedNode = tnRoot;                     // force treeOpcItems_AfterSelect
            }
            catch (COMException /* eX */)
            {
                MessageBox.Show(this, "browse error!", "DoBrowse", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(false);
            }
            return(true);
        }
Exemplo n.º 2
0
        private void DoBrowse()
        {
            OPCNAMESPACETYPE opcorgi = this.QueryOrganization();


            if (opcorgi == OPCNAMESPACETYPE.OPC_NS_HIERARCHIAL)
            {
                this.MoveToRoot();
                this._Nodes = new List <OPCNode>();
                RecurBrowse(_Nodes, null, null);
            }
        }
Exemplo n.º 3
0
        public void TestQueryOrganization01()
        {
            //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
            OPCNAMESPACETYPE spaceType = opcServer.QueryOrganization();
            //Post Condition Check
        }
Exemplo n.º 4
0
 public void QueryOrganization(out OPCNAMESPACETYPE pNameSpaceType)
 {
     lock (this)
     {
         try
         {
             pNameSpaceType = OPCNAMESPACETYPE.OPC_NS_HIERARCHIAL;
         }
         catch (Exception e)
         {
             throw CreateException(e);
         }
     }
 }
Exemplo n.º 5
0
            public void QueryOrganization(out OPCNAMESPACETYPE pNameSpaceType)
            {
                var methodName = nameof(IOPCBrowseServerAddressSpace) + "." + nameof(IOPCBrowseServerAddressSpace.QueryOrganization);

                try
                {
                    var server = BeginComCall <IOPCBrowseServerAddressSpace>(methodName, true);
                    server.QueryOrganization(out pNameSpaceType);
                }
                finally
                {
                    EndComCall(methodName);
                }
            }
Exemplo n.º 6
0
 public void QueryOrganization(out OPCNAMESPACETYPE pNameSpaceType)
 {
     OpcCom.Da.Wrapper.Server server;
     Monitor.Enter(server = this);
     try
     {
         pNameSpaceType = OPCNAMESPACETYPE.OPC_NS_HIERARCHIAL;
     }
     catch (Exception exception)
     {
         throw CreateException(exception);
     }
     finally
     {
         Monitor.Exit(server);
     }
 }
Exemplo n.º 7
0
        public OPCNAMESPACETYPE QueryOrganization()
        {
            if (QueryOrganizationType != OPCNAMESPACETYPE.none)
            {
                return(QueryOrganizationType);
            }

            OPCNAMESPACETYPE ns;

            ifBrowse.QueryOrganization(out ns);
            if (ns != OPCNAMESPACETYPE.OPC_NS_HIERARCHIAL)
            {
                throw (new OnlyItemsException("此服务器只有Items,没有任何group节点"));
            }
            QueryOrganizationType = ns;
            return(ns);
        }
Exemplo n.º 8
0
        private void setPosition(string f_name)
        {
            int m_Res;
            OPCNAMESPACETYPE cOpcNameSpace = OPCNAMESPACETYPE.OPC_NS_FLAT;

            m_Res = m_pIBrowse.QueryOrganization(out cOpcNameSpace);
            if (m_Res >= 0)
            {
                m_Res = m_pIBrowse.ChangeBrowsePosition(OPCBROWSEDIRECTION.OPC_BROWSE_TO, f_name);
                if (m_Res < 0)
                {
                    throw new Exception("Browser: Item " + f_name + " is not found.");
                }
            }
            else
            {
                throw new Exception("Browser: QueryOrganization error.");
            }
        }
Exemplo n.º 9
0
 private bool DoBrowse()
 {
     try
     {
         OPCNAMESPACETYPE opcorgi = _theSrv.QueryOrganization();
         // fill Tree with all
         OpcNamespacesTree.Clear();
         if (opcorgi == OPCNAMESPACETYPE.OPC_NS_HIERARCHIAL)
         {
             _theSrv.ChangeBrowsePosition(OPCBROWSEDIRECTION.OPC_BROWSE_TO, ""); // to root
             RecurBrowse(OpcNamespacesTree, 1);
         }
     }
     catch (COMException ex)
     {
         throw ex;
     }
     return(true);
 }
Exemplo n.º 10
0
 void IOPCBrowseServerAddressSpace.QueryOrganization([MarshalAs(UnmanagedType.U4)] out OPCNAMESPACETYPE pNameSpaceType)
 {
     pNameSpaceType = OPCNAMESPACETYPE.OPC_NS_HIERARCHIAL;
 }
Exemplo n.º 11
0
        private BrowseElement[] GetElements(int elementsFound, ItemIdentifier itemID, BrowseFilters filters, bool branches, ref BrowsePosition position)
        {
            EnumString enumString = null;

            if (position == null)
            {
                IOPCBrowseServerAddressSpace iOPCBrowseServerAddressSpace = (IOPCBrowseServerAddressSpace)m_server;
                OPCNAMESPACETYPE             pNameSpaceType = OPCNAMESPACETYPE.OPC_NS_HIERARCHIAL;
                try
                {
                    iOPCBrowseServerAddressSpace.QueryOrganization(out pNameSpaceType);
                }
                catch (Exception e)
                {
                    throw Interop.CreateException("IOPCBrowseServerAddressSpace.QueryOrganization", e);
                }

                if (pNameSpaceType == OPCNAMESPACETYPE.OPC_NS_FLAT)
                {
                    if (branches)
                    {
                        return(new BrowseElement[0]);
                    }

                    if (itemID != null && itemID.ItemName != null && itemID.ItemName.Length > 0)
                    {
                        throw new ResultIDException(ResultID.Da.E_UNKNOWN_ITEM_NAME);
                    }
                }

                enumString = GetEnumerator(itemID?.ItemName, filters, branches, pNameSpaceType == OPCNAMESPACETYPE.OPC_NS_FLAT);
            }
            else
            {
                enumString = position.Enumerator;
            }

            ArrayList     arrayList     = new ArrayList();
            BrowseElement browseElement = null;
            int           num           = 0;

            string[] array = null;
            if (position != null)
            {
                num      = position.Index;
                array    = position.Names;
                position = null;
            }

            do
            {
                if (array != null)
                {
                    for (int i = num; i < array.Length; i++)
                    {
                        if (filters.MaxElementsReturned != 0 && filters.MaxElementsReturned == arrayList.Count + elementsFound)
                        {
                            position       = new BrowsePosition(itemID, filters, enumString, branches);
                            position.Names = array;
                            position.Index = i;
                            break;
                        }

                        browseElement = GetElement(itemID, array[i], filters, branches);
                        if (browseElement == null)
                        {
                            break;
                        }

                        arrayList.Add(browseElement);
                    }
                }

                if (position != null)
                {
                    break;
                }

                array = enumString.Next(10);
                num   = 0;
            }while (array != null && array.Length > 0);
            if (position == null)
            {
                enumString.Dispose();
            }

            return((BrowseElement[])arrayList.ToArray(typeof(BrowseElement)));
        }
Exemplo n.º 12
0
 public void QueryOrganization(out OPCNAMESPACETYPE pNameSpaceType)
 {
     var methodName = nameof(IOPCBrowseServerAddressSpace) + "." + nameof(IOPCBrowseServerAddressSpace.QueryOrganization);
     try
     {
         var server = BeginComCall<IOPCBrowseServerAddressSpace>(methodName, true);
         server.QueryOrganization(out pNameSpaceType);
     }
     finally
     {
         EndComCall(methodName);
     }
 }
Exemplo n.º 13
0
        private BrowseElement[] GetElements(int elementsFound, ItemIdentifier itemID, BrowseFilters filters, bool branches, ref OpcCom.Da20.BrowsePosition position)
        {
            EnumString enumerator = null;

            if (position == null)
            {
                IOPCBrowseServerAddressSpace server         = (IOPCBrowseServerAddressSpace)base.m_server;
                OPCNAMESPACETYPE             pNameSpaceType = OPCNAMESPACETYPE.OPC_NS_HIERARCHIAL;
                try
                {
                    server.QueryOrganization(out pNameSpaceType);
                }
                catch (Exception exception)
                {
                    throw OpcCom.Interop.CreateException("IOPCBrowseServerAddressSpace.QueryOrganization", exception);
                }
                if ((pNameSpaceType == OPCNAMESPACETYPE.OPC_NS_FLAT) && branches)
                {
                    return(new BrowseElement[0]);
                }
                enumerator = this.GetEnumerator((itemID != null) ? itemID.ItemName : null, filters, branches);
            }
            else
            {
                enumerator = position.Enumerator;
            }
            ArrayList     list    = new ArrayList();
            BrowseElement element = null;
            int           index   = 0;

            string[] names = null;
            if (position != null)
            {
                index    = position.Index;
                names    = position.Names;
                position = null;
            }
Label_0089:
            if (names != null)
            {
                for (int i = index; i < names.Length; i++)
                {
                    if ((filters.MaxElementsReturned != 0) && (filters.MaxElementsReturned == (list.Count + elementsFound)))
                    {
                        position       = new OpcCom.Da20.BrowsePosition(itemID, filters, enumerator, branches);
                        position.Names = names;
                        position.Index = i;
                        break;
                    }
                    element = this.GetElement(names[i], filters, branches);
                    if (element == null)
                    {
                        break;
                    }
                    list.Add(element);
                }
            }
            if (position == null)
            {
                names = enumerator.Next(10);
                index = 0;
                if ((names != null) && (names.Length > 0))
                {
                    goto Label_0089;
                }
            }
            if (position == null)
            {
                enumerator.Dispose();
            }
            return((BrowseElement[])list.ToArray(typeof(BrowseElement)));
        }