OPC Studio User's Guide and Reference
DiscoverNetworkServers Method (_EasyUAClient)
Example 



OpcLabs.EasyOpcUA Assembly > OpcLabs.EasyOpc.UA.ComTypes Namespace > _EasyUAClient Interface : DiscoverNetworkServers Method
List of Server capability filters. Only records with all the specified server capabilities are returned.

The value of this parameter can be null (Nothing in Visual Basic).

The name of the machine that runs the discovery server that will be used for discovery task.

The value of this parameter can be null (Nothing in Visual Basic).

Discovers available OPC-UA servers on the network and returns information about them, using the specified discovery host, and specifying the capabilities that the servers must have.
Discovers available OPC-UA servers on the network.

This method discovers available OPC-UA servers on the network and returns information about them. It uses the so-called Local Discovery Server with Multicast Extensions (LDS-NE). You can influence how the discovery works using the properties in SharedParameters.

Invokes the FindServersOnNetwork service.

See also in Knowledge Base: Technical note-OPC UA Discovery in QuickOPC.

Syntax
'Declaration
 
<NotNullAttribute()>
Function DiscoverNetworkServers( _
   ByVal serverCapabilityFilter As Object, _
   ByVal discoveryHost As String _
) As UADiscoveryElementCollection
'Usage
 
Dim instance As _EasyUAClient
Dim serverCapabilityFilter As Object
Dim discoveryHost As String
Dim value As UADiscoveryElementCollection
 
value = instance.DiscoverNetworkServers(serverCapabilityFilter, discoveryHost)

Parameters

serverCapabilityFilter
List of Server capability filters. Only records with all the specified server capabilities are returned.

The value of this parameter can be null (Nothing in Visual Basic).

discoveryHost
The name of the machine that runs the discovery server that will be used for discovery task.

The value of this parameter can be null (Nothing in Visual Basic).

Return Value

Returns a collection of application elements (servers, OpcLabs.EasyOpc.UA.Discovery.UADiscoveryElement).

This method never returns null (Nothing in Visual Basic).

The individual elements of the returned value are never null (Nothing in Visual Basic).

Exceptions
ExceptionDescription

A null reference (Nothing in Visual Basic) is passed to a method that does not accept it as a valid argument.

This is a usage error, i.e. it will never occur (the exception will not be thrown) in a correctly written program. Your code should not catch this exception.

The OPC UA operation has failed. This operation exception in uniformly used to allow common handling of various kinds of errors. The System.Exception.InnerException always contains information about the actual error cause.

This is an operation error that depends on factors external to your program, and thus cannot be always avoided. Your code must handle it appropriately.

Remarks

This member or type is for use from COM. It is not meant to be used from .NET or Python. Refer to the corresponding .NET member or type instead, if you are developing in .NET or Python.

This is an extension method (info: C#, VB.NET). In languages that have support for extensions methods (such as C# and VB.NET), you can use the extension method as if it were a regular method on the object that is its first parameter. In other languages (such as with Python.NET), you will call the extension as a static method, and pass it the object on which it acts as its first parameter.

This method discovers available OPC-UA servers on the network and returns information about them. It uses the so-called Local Discovery Server with Multicast Extensions (LDS-NE). You can influence how the discovery works using the properties in SharedParameters.

Invokes the FindServersOnNetwork service.

See also in Knowledge Base: Technical note-OPC UA Discovery in QuickOPC.

Example

COM

REM This example shows how to obtain information about OPC UA servers available on the network.
REM
REM Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
REM OPC client and subscriber examples in Visual Basic on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-VB .
REM Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
REM a commercial license in order to use Online Forums, and we reply to every post.

Public Sub DiscoverNetworkServers_Main_Command_Click()
    OutputText = ""

    ' Instantiate the client object
    Dim Client As New EasyUAClient

    ' Obtain collection of application elements
    On Error Resume Next
    Dim DiscoveryElementCollection As UADiscoveryElementCollection
    Set DiscoveryElementCollection = Client.DiscoverNetworkServers(Nothing, "opcua.demo-this.com")
    If Err.Number <> 0 Then
        OutputText = OutputText & "*** Failure: " & Err.Source & ": " & Err.Description & vbCrLf
        Exit Sub
    End If
    On Error GoTo 0
    
    ' Display results
    Dim DiscoveryElement As UADiscoveryElement: For Each DiscoveryElement In DiscoveryElementCollection
        OutputText = OutputText & vbCrLf
        OutputText = OutputText & "Server name: " & DiscoveryElement.ServerName & vbCrLf
        OutputText = OutputText & "Discovery URI string: " & DiscoveryElement.DiscoveryUriString & vbCrLf
        OutputText = OutputText & "Server capabilities: " & DiscoveryElement.serverCapabilities.ToString & vbCrLf
    Next
End Sub
Rem This example shows how to obtain information about OPC UA servers available on the network.
Rem
Rem Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
Rem OPC client and subscriber examples in VBScript on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-VBScript .
Rem Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
Rem a commercial license in order to use Online Forums, and we reply to every post.

Option Explicit

' Instantiate the client object
Dim Client: Set Client = CreateObject("OpcLabs.EasyOpc.UA.EasyUAClient")

' Obtain collection of application elements
On Error Resume Next
Dim DiscoveryElementCollection: Set DiscoveryElementCollection = _
    Client.DiscoverNetworkServers(Nothing, "opcua.demo-this.com")
If Err.Number <> 0 Then
    WScript.Echo "*** Failure: " & Err.Source & ": " & Err.Description
    WScript.Quit
End If
On Error Goto 0

' Display results
Dim DiscoveryElement: For Each DiscoveryElement In DiscoveryElementCollection
    WScript.Echo
    WScript.Echo "Server name: " & DiscoveryElement.ServerName
    WScript.Echo "Discovery URI string: " & DiscoveryElement.DiscoveryUriString
    Dim s: s = ""
    Dim serverCapability: For Each serverCapability In DiscoveryElement.ServerCapabilities
        s = s & serverCapability & " "
    Next
    WScript.Echo "Server capabilities: " & s
Next
Requirements

Target Platforms: .NET Framework: Windows 10 (selected versions), Windows 11 (selected versions), Windows Server 2016, Windows Server 2022; .NET: Linux, macOS, Microsoft Windows

See Also