예제 #1
0
        private void GetItemChildren(List <OPCItem> items, string szNameFilter, IOPCBrowseServerAddressSpace pParent, OPCItem parentItem = null)
        {
            opcprox.IEnumString pEnum;
            uint   cnt;
            string strName;
            string szItemID;

            try
            {
                pParent.BrowseOPCItemIDs(tagOPCBROWSETYPE.OPC_LEAF, szNameFilter, (ushort)VarEnum.VT_EMPTY, 0, out pEnum);
                pEnum.RemoteNext(1, out strName, out cnt);
                int nLeavesCount = 0;
                while (cnt != 0)
                {
                    pParent.GetItemID(strName, out szItemID); // получает полный идентификатор тега
                    GetItemProperties(szItemID);
                    items.Add(
                        new OPCItem()
                    {
                        Parent   = parentItem,
                        ItemName = strName,
                        Enabled  = true,
                        ItemType = OPCItemType.LEAF,
                        ItemID   = szItemID
                    }
                        );
                    pEnum.RemoteNext(1, out strName, out cnt);
                    nLeavesCount++;
                }
                pParent.BrowseOPCItemIDs(tagOPCBROWSETYPE.OPC_BRANCH, szNameFilter, (ushort)VarEnum.VT_EMPTY, 0, out pEnum);
                pEnum.RemoteNext(1, out strName, out cnt);
                int nBranchesCount = 0;
                while (cnt != 0)
                {
                    pParent.GetItemID(strName, out szItemID);
                    OPCItem item = new OPCItem()
                    {
                        Parent   = parentItem,
                        ItemName = strName,
                        Enabled  = true,
                        ItemType = OPCItemType.BRANCH,
                        ItemID   = szItemID
                    };
                    items.Add(item);
                    pParent.ChangeBrowsePosition(tagOPCBROWSEDIRECTION.OPC_BROWSE_TO, szItemID);
                    GetItemChildren(items, "", pParent, item);
                    pParent.ChangeBrowsePosition(tagOPCBROWSEDIRECTION.OPC_BROWSE_UP, szItemID);
                    pEnum.RemoteNext(1, out strName, out cnt);
                    nBranchesCount++;
                }
            }
            catch (System.Exception ex)
            {
                Console.Out.WriteLine(ex.Message);
            }
        }
예제 #2
0
        /// <summary>
        /// Looks up the item id for the node relative to the current browse position.
        /// </summary>
        /// <param name="browseName">Name of the element to lookup.</param>
        /// <returns>The item id. Null if an error occurs.</returns>
        private string GetItemId(string browseName)
        {
            string methodName = "IOPCBrowseServerAddressSpace.GetItemID";

            try
            {
                IOPCBrowseServerAddressSpace server = BeginComCall <IOPCBrowseServerAddressSpace>(methodName, true);
                string itemId = null;
                server.GetItemID(browseName, out itemId);
                return(itemId);
            }
            catch (Exception e)
            {
                if (ComUtils.IsUnknownError(e, ResultIds.E_FAIL))
                {
                    ComCallError(methodName, e);
                }

                return(null);
            }
            finally
            {
                EndComCall(methodName);
            }
        }
예제 #3
0
        public string GetItemID(string p_ItemDataID)
        {
            string l_ItemID;

            m_IfBrowse.GetItemID(p_ItemDataID, out l_ItemID);

            return(l_ItemID);
        }
예제 #4
0
        private void AddTreeNode(IOPCBrowseServerAddressSpace srv, TreeNodeCollection root, string tag)
        {
            TreeNode       item    = root.Add(tag);
            OPCChannelInfo channel = new OPCChannelInfo();

            channel.progId = serversComboBox.Text;
            channel.host   = localServerButton.Checked ? "localhost" : serverTextBox.Text;
            srv.GetItemID(tag, out channel.channel);
            item.Tag = channel;
        }
예제 #5
0
        private void AddTreeNode(IOPCBrowseServerAddressSpace srv, TreeNodeCollection root, string tag)
        {
            TreeNode       item    = root.Add(tag);
            OPCChannelInfo channel = new OPCChannelInfo
            {
                progId = txtOPCServer.Text,
                host   = txtOPCServerPath.Text
            };

            srv.GetItemID(tag, out channel.channel);
            item.Tag = channel;
        }
예제 #6
0
		/// <summary>
		/// Получает дерево тегов OPC DA сервера
		/// </summary>
		/// <param name="parentDirectory">При первом вызове передать null - 
		/// будеть создана корневая директория</param>
		/// <param name="server"></param>
		void BuildTreeTags(ref OpcDaDirectory parentDirectory, IOPCBrowseServerAddressSpace server)
		{
			opcproxy.IEnumString ptrEnum;
			uint cnt;
			string strName;
			string szItemID;

			if (parentDirectory == null)
			{
				parentDirectory = new OpcDaDirectory(); // Создаём корневую директорию
			}


			// Получаем все теги
			server.BrowseOPCItemIDs(tagOPCBROWSETYPE.OPC_LEAF, "", (ushort)VarEnum.VT_EMPTY, 0, out ptrEnum);
			ptrEnum.RemoteNext(1, out strName, out cnt);
			while (cnt != 0)
			{
			
				// получаем полный идентификатор тега
				server.GetItemID(strName, out szItemID);
				parentDirectory.Items.Add(new OpcDaTag(szItemID, strName, parentDirectory));
				ptrEnum.RemoteNext(1, out strName, out cnt);
			}

			// Получем директории 
			server.BrowseOPCItemIDs(tagOPCBROWSETYPE.OPC_BRANCH, "", 1, 0, out ptrEnum);
			ptrEnum.RemoteNext(1, out strName, out cnt);
			while (cnt != 0)
			{
				server.ChangeBrowsePosition(tagOPCBROWSEDIRECTION.OPC_BROWSE_DOWN, strName);
				var childDirectory = new OpcDaDirectory(strName, parentDirectory);
				parentDirectory.Items.Add(childDirectory);
				BuildTreeTags(ref childDirectory, server);
				server.ChangeBrowsePosition(tagOPCBROWSEDIRECTION.OPC_BROWSE_UP, strName);
				ptrEnum.RemoteNext(1, out strName, out cnt);
			}
		}