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 name of the machine that runs the discovery server that will be used for discovery task.
Discovers available OPC-UA servers on the network and returns information about them. 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 and returns information about them.

This method 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
 
<ElementsNotNullAttribute()>
<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)
[ElementsNotNull()]
[NotNull()]
UADiscoveryElementCollection DiscoverNetworkServers( 
   object serverCapabilityFilter,
   string discoveryHost
)
[ElementsNotNull()]
[NotNull()]
UADiscoveryElementCollection^ DiscoverNetworkServers( 
   Object^ serverCapabilityFilter,
   String^ discoveryHost
) 

Parameters

serverCapabilityFilter
List of Server capability filters. Only records with all the specified server capabilities are returned.
discoveryHost
The name of the machine that runs the discovery server that will be used for discovery task.

Return Value

Returns a collection of application elements (servers, OpcLabs.EasyOpc.UA.Discovery.UADiscoveryElement).
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 method 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 .

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 .

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