none
.NET and .NET API from OPC Foundation and list tags in OPCSERVER RRS feed

  • Question

  • Good afternoon, I communicated with an OPCDA / OPCHDA server as follows:

    OpcCom.ServerEnumerator se = new OpcCom.ServerEnumerator();
    Opc.Server[] servers = se.GetAvailableServers(Opc.Specification.COM_HDA_10);
     Opc.Hda.Server daServer = (Opc.Hda.Server)servers[0];
    //Opc.Da.Server daServer = (Opc.Da.Server)servers[0];
     daServer.Connect();

    However I need to list all groups and tags within that server. I have not found any documentation about it so I'm kind of lost.

    • Moved by CoolDadTx Friday, January 18, 2019 8:59 PM Third party product
    Friday, January 18, 2019 6:24 PM

All replies

  • Unfortunately OPC is a third party library. We only provide support for C#-specific questions here. Please post your question over in OPC's forums for .NET developers.

    Michael Taylor http://www.michaeltaylorp3.net

    Friday, January 18, 2019 8:59 PM
  • Like this:

    public void GetElements(ItemCollection ElementCollection, Opc.Da.Server server)
            {
                ElementCollection.Clear();
                Opc.Da.BrowsePosition Pos;
                Opc.Da.BrowseElement[] Elems = new Opc.Da.BrowseElement[0];
                try
                {             
                    Opc.Da.BrowseFilters filter = new Opc.Da.BrowseFilters();
                    filter.ReturnAllProperties = true;
                    Pos = new Opc.Da.BrowsePosition(new Opc.ItemIdentifier(), filter);
                    Elems = server.Browse(new Opc.ItemIdentifier(), filter, out Pos);
                }
                catch (Exception e)
                {
                    ElementCollection.Add(e.Message);
                }
                if ((Elems != null) && (Elems.Length >0))
                        foreach (Opc.Da.BrowseElement element in Elems)
                        {
                            TreeViewItem it = new TreeViewItem();
                            AddChildren(it, element, server);

                            ElementCollection.Add(it);
                        }
                
            }


     public void AddChildren(TreeViewItem item, Opc.Da.BrowseElement element, Opc.Da.Server server)
            {
                item.Header = element.ItemName;
                if (element.HasChildren) //element.HasChildren
                {
                    Opc.Da.BrowsePosition Pos;
                    Opc.Da.BrowseElement[] elemChilds = new Opc.Da.BrowseElement[0];
                    try
                    {
                        Opc.Da.BrowseFilters filter = new Opc.Da.BrowseFilters();
                        filter.ReturnAllProperties = true;
                        Pos = new Opc.Da.BrowsePosition(new Opc.ItemIdentifier(), filter);
                        elemChilds = server.Browse(new Opc.ItemIdentifier(element.Name), filter, out Pos);
                    }
                    catch (Exception) { }
                    if ((elemChilds != null) && (elemChilds.Length > 0))
                        foreach (Opc.Da.BrowseElement elementChild in elemChilds)
                        {
                            TreeViewItem childitem = new TreeViewItem();
                            AddChildren(childitem, elementChild, server);
                            item.Items.Add(childitem);
                        }
                    else serverTags.Add(element.ItemName);
                }
                else serverTags.Add(element.ItemName);
            }

    • Edited by Powerhead74 Wednesday, March 11, 2020 6:37 AM
    Wednesday, March 11, 2020 6:35 AM