![](dotnetdiagramimages/OpcLabs_EasyOpcUA_OpcLabs_EasyOpc_UA_Discovery_UADiscoveryElementCollection.png)
'Declaration
<ComDefaultInterfaceAttribute(OpcLabs.EasyOpc.UA.Discovery.ComTypes._UADiscoveryElementCollection)> <ComVisibleAttribute(True)> <GuidAttribute("73413B41-5FC2-483D-8D07-432A14B169B9")> <TypeConverterAttribute(System.ComponentModel.ExpandableObjectConverter)> <DefaultMemberAttribute("Item")> <DebuggerTypeProxyAttribute(System.Collections.Generic.Mscorlib_CollectionDebugView`1)> <DebuggerDisplayAttribute("Count = {Count}")> <SerializableAttribute()> Public NotInheritable Class UADiscoveryElementCollection Inherits System.Collections.ObjectModel.Collection(Of UADiscoveryElement) Implements OpcLabs.EasyOpc.UA.Discovery.ComTypes._UADiscoveryElementCollection, System.Collections.Generic.ICollection(Of UADiscoveryElement), System.Collections.Generic.IEnumerable(Of UADiscoveryElement), System.Collections.Generic.IList(Of UADiscoveryElement), System.Collections.Generic.IReadOnlyCollection(Of UADiscoveryElement), System.Collections.Generic.IReadOnlyList(Of UADiscoveryElement), System.Collections.ICollection, System.Collections.IEnumerable, System.Collections.IList
'Usage
Dim instance As UADiscoveryElementCollection
[ComDefaultInterface(OpcLabs.EasyOpc.UA.Discovery.ComTypes._UADiscoveryElementCollection)] [ComVisible(true)] [Guid("73413B41-5FC2-483D-8D07-432A14B169B9")] [TypeConverter(System.ComponentModel.ExpandableObjectConverter)] [DefaultMember("Item")] [DebuggerTypeProxy(System.Collections.Generic.Mscorlib_CollectionDebugView`1)] [DebuggerDisplay("Count = {Count}")] [Serializable()] public sealed class UADiscoveryElementCollection : System.Collections.ObjectModel.Collection<UADiscoveryElement>, OpcLabs.EasyOpc.UA.Discovery.ComTypes._UADiscoveryElementCollection, System.Collections.Generic.ICollection<UADiscoveryElement>, System.Collections.Generic.IEnumerable<UADiscoveryElement>, System.Collections.Generic.IList<UADiscoveryElement>, System.Collections.Generic.IReadOnlyCollection<UADiscoveryElement>, System.Collections.Generic.IReadOnlyList<UADiscoveryElement>, System.Collections.ICollection, System.Collections.IEnumerable, System.Collections.IList
[ComDefaultInterface(OpcLabs.EasyOpc.UA.Discovery.ComTypes._UADiscoveryElementCollection)] [ComVisible(true)] [Guid("73413B41-5FC2-483D-8D07-432A14B169B9")] [TypeConverter(System.ComponentModel.ExpandableObjectConverter)] [DefaultMember("Item")] [DebuggerTypeProxy(System.Collections.Generic.Mscorlib_CollectionDebugView`1)] [DebuggerDisplay("Count = {Count}")] [Serializable()] public ref class UADiscoveryElementCollection sealed : public System.Collections.ObjectModel.Collection<UADiscoveryElement>, OpcLabs.EasyOpc.UA.Discovery.ComTypes._UADiscoveryElementCollection, System.Collections.Generic.ICollection<UADiscoveryElement>, System.Collections.Generic.IEnumerable<UADiscoveryElement>, System.Collections.Generic.IList<UADiscoveryElement>, System.Collections.Generic.IReadOnlyCollection<UADiscoveryElement>, System.Collections.Generic.IReadOnlyList<UADiscoveryElement>, System.Collections.ICollection, System.Collections.IEnumerable, System.Collections.IList
This collection is returned by the discovery methods.
See also in Knowledge Base: Technical note-OPC UA Discovery in QuickOPC.
OPC UA Discovery allows QuickOPC to find available OPC UA servers, and determine how to make connections to them. There are several approaches to discovery, and they can be combined together to achieve the desired functionality. Clients and servers can be on the same host, on different hosts in the same subnet, or even on completely different locations in an administrative domain.
QuickOPC provides following kinds of discovery:
It is also possible to access the discovery functionality in a common way, using Generalized OPC UA Discovery.
By default, the results (the application element collection) of many of the methods described in this chapter are returned flattened. This means that a single OPC UA application may appear multiple times in the resulting collection, and each time it will have precisely one DiscoveryUriString associated with it.
Alternatively, you can use method overloads with the additional 'flat' argument, and set it true, in order to receive unflattened result. In this case, each OPC UA application will be contained just once in the resulting collection, but it may have one or more discovery URL in its DiscoveryUriStrings property. In this case, do not use the DiscoveryUriString property, because it will contain an empty string if the application has more than one discovery URL.
// This example shows how to obtain application URLs of all OPC Unified Architecture servers on a given machine. // // Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html . // OPC client and subscriber examples in C# on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-CSharp . // Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own // a commercial license in order to use Online Forums, and we reply to every post. using System; using OpcLabs.EasyOpc.UA; using OpcLabs.EasyOpc.UA.Discovery; using OpcLabs.EasyOpc.UA.OperationModel; namespace UADocExamples._EasyUAClient { class DiscoverLocalServers { public static void Overload1() { // Instantiate the client object. var client = new EasyUAClient(); // Obtain collection of server elements. UADiscoveryElementCollection discoveryElementCollection; try { discoveryElementCollection = client.DiscoverLocalServers("opcua.demo-this.com"); } catch (UAException uaException) { Console.WriteLine($"*** Failure: {uaException.GetBaseException().Message}"); return; } // Display results. foreach (UADiscoveryElement discoveryElement in discoveryElementCollection) Console.WriteLine($"discoveryElementCollection[\"{discoveryElement.DiscoveryUriString}\"].ApplicationUriString: {discoveryElement.ApplicationUriString}"); // Example output: // //discoveryElementCollection["opc.tcp://opcua.demo-this.com:51210/UA/SampleServer"].ApplicationUriString: urn: DEMO - 5:UA Sample Server //discoveryElementCollection["http://opcua.demo-this.com:51211/UA/SampleServer"].ApplicationUriString: urn: DEMO - 5:UA Sample Server //discoveryElementCollection["https://opcua.demo-this.com:51212/UA/SampleServer/"].ApplicationUriString: urn: DEMO - 5:UA Sample Server //discoveryElementCollection["http://opcua.demo-this.com:62543/Quickstarts/AlarmConditionServer"].ApplicationUriString: urn: opcua.demo - this.com:Quickstart Alarm Condition Server //discoveryElementCollection["opc.tcp://opcua.demo-this.com:62544/Quickstarts/AlarmConditionServer"].ApplicationUriString: urn: opcua.demo - this.com:Quickstart Alarm Condition Server } } }
# This example shows how to obtain application URLs of all OPC Unified Architecture servers on a given machine. # # Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html . # OPC client and subscriber examples in PowerShell on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-PowerShell . # Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own # a commercial license in order to use Online Forums, and we reply to every post. #requires -Version 5.1 using namespace OpcLabs.EasyOpc.UA using namespace OpcLabs.EasyOpc.UA.Discovery using namespace OpcLabs.EasyOpc.UA.OperationModel # The path below assumes that the current directory is [ProductDir]/Examples-NET/PowerShell/Windows . Add-Type -Path "../../../Components/Opclabs.QuickOpc/net472/OpcLabs.EasyOpcUA.dll" Add-Type -Path "../../../Components/Opclabs.QuickOpc/net472/OpcLabs.EasyOpcUAComponents.dll" # Instantiate the client object. $client = New-Object EasyUAClient # Obtain collection of server elements. try { $discoveryElementCollection = [IEasyUAClientExtension]::DiscoverLocalServers($client, "opcua.demo-this.com") } catch [UAException] { Write-Host "*** Failure: $($PSItem.Exception.GetBaseException().Message)" return } # Display results. foreach ($discoveryElement in $discoveryElementCollection) { Write-Host "discoveryElementCollection[`"$($discoveryElement.DiscoveryUriString)`"].ApplicationUriString: $($discoveryElement.ApplicationUriString)" } # Example output: # #discoveryElementCollection["opc.tcp://opcua.demo-this.com:51210/UA/SampleServer"].ApplicationUriString: urn:DEMO-5:UA Sample Server #discoveryElementCollection["http://opcua.demo-this.com:51211/UA/SampleServer"].ApplicationUriString: urn:DEMO-5:UA Sample Server #discoveryElementCollection["https://opcua.demo-this.com:51212/UA/SampleServer/"].ApplicationUriString: urn:DEMO-5:UA Sample Server #discoveryElementCollection["http://opcua.demo-this.com:62543/Quickstarts/AlarmConditionServer"].ApplicationUriString: urn:opcua.demo-this.com:Quickstart Alarm Condition Server #discoveryElementCollection["opc.tcp://opcua.demo-this.com:62544/Quickstarts/AlarmConditionServer"].ApplicationUriString: urn:opcua.demo-this.com:Quickstart Alarm Condition Server
' This example shows how to obtain application URLs of all OPC Unified Architecture servers on a given machine. ' ' Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html . ' OPC client and subscriber examples in VB.NET on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-VBNET . ' Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own ' a commercial license in order to use Online Forums, and we reply to every post. Imports OpcLabs.EasyOpc.UA Imports OpcLabs.EasyOpc.UA.Discovery Imports OpcLabs.EasyOpc.UA.OperationModel Namespace _EasyUAClient Friend Class DiscoverLocalServers Public Shared Sub Overload1() ' Instantiate the client object Dim client = New EasyUAClient() ' Obtain collection of server elements Dim discoveryElementCollection As UADiscoveryElementCollection Try discoveryElementCollection = client.DiscoverLocalServers("opcua.demo-this.com") Catch uaException As UAException Console.WriteLine("*** Failure: {0}", uaException.GetBaseException.Message) Exit Sub End Try ' Display results For Each discoveryElement As UADiscoveryElement In discoveryElementCollection Console.WriteLine("discoveryElementCollection[""{0}""].ApplicationUriString: {1}", _ discoveryElement.DiscoveryUriString, discoveryElement.ApplicationUriString) Next discoveryElement ' Example output: 'discoveryElementCollection["opc.tcp://opcua.demo-this.com:51210/UA/SampleServer"].ApplicationUriString: urn:Test-PC:UA Sample Server 'discoveryElementCollection["http://opcua.demo-this.com:51211/UA/SampleServer"].ApplicationUriString: urn:Test-PC:UA Sample Server End Sub End Class End Namespace
# This example shows how to obtain application URLs of all OPC Unified Architecture servers on the specified host. # # Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html . # OPC client and subscriber examples in Python on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-Python . # Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own # a commercial license in order to use Online Forums, and we reply to every post. # The QuickOPC package is needed. Install it using "pip install opclabs_quickopc". import opclabs_quickopc # Import .NET namespaces. from OpcLabs.EasyOpc.UA import * from OpcLabs.EasyOpc.UA.OperationModel import * # Instantiate the client object. client = EasyUAClient() # Obtain collection of server elements. try: discoveryElementCollection = IEasyUAClientExtension.DiscoverLocalServers(client, 'opcua.demo-this.com') except UAException as uaException: print('*** Failure: ' + uaException.GetBaseException().Message) exit() # Display results. for discoveryElement in discoveryElementCollection: print('DiscoveryElementCollection["', discoveryElement.DiscoveryUriString, '"].ApplicationUriString: ', discoveryElement.ApplicationUriString, sep='')
System.Object
System.Collections.ObjectModel.Collection<T>
OpcLabs.EasyOpc.UA.Discovery.UADiscoveryElementCollection