OPC Studio User's Guide and Reference
BrowseServers(IEasyDAClient) Method
Example 



OpcLabs.EasyOpcClassicCore Assembly > OpcLabs.EasyOpc.DataAccess Namespace > IEasyDAClientExtension Class > BrowseServers Method : BrowseServers(IEasyDAClient) Method
The client object that will perform the operation.

This is typically the EasyDAClient object.

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

Browses the local computer and returns information about OPC (Data Access) servers found.
Syntax
'Declaration
 
<ExtensionAttribute()>
<NotNullAttribute()>
Public Overloads Shared Function BrowseServers( _
   ByVal client As IEasyDAClient _
) As ServerElementCollection
'Usage
 
Dim client As IEasyDAClient
Dim value As ServerElementCollection
 
value = IEasyDAClientExtension.BrowseServers(client)
[Extension()]
[NotNull()]
public static ServerElementCollection BrowseServers( 
   IEasyDAClient client
)
[Extension()]
[NotNull()]
public:
static ServerElementCollection^ BrowseServers( 
   IEasyDAClient^ client
) 

Parameters

client
The client object that will perform the operation.

This is typically the EasyDAClient object.

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

Return Value

The method returns a keyed collection of OpcLabs.EasyOpc.ServerElement values, each containing information about a particular OPC server found on the specified machine. The keys of the keyed collection are the server's CLSIDs.

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 "Classic" (or OPC XML-DA) 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

The server(s) can be local or can be remotely accessed via DCOM.

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.

Example
// This example shows how to obtain all ProgIDs of all OPC Data Access servers on the local 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;
using OpcLabs.EasyOpc.DataAccess;
using OpcLabs.EasyOpc.OperationModel;

namespace DocExamples.DataAccess._EasyDAClient
{
    class BrowseServers
    {
        public static void Main1()
        {
            // Instantiate the client object.
            var client = new EasyDAClient();
            ServerElementCollection serverElements;
            try
            {
                serverElements = client.BrowseServers("");
            }
            catch (OpcException opcException)
            {
                Console.WriteLine("*** Failure: {0}", opcException.GetBaseException().Message);
                return;
            }

            foreach (ServerElement serverElement in serverElements)
                Console.WriteLine($"ServerElements(\"{serverElement.ClsidString}\").ProgId: {serverElement.ProgId}");
        }


        // Example output:
        //
        //ServerElements("c8a12f17-1e03-401e-b53d-6c654dd576da").ProgId: OPCLabs.KitServer.2
    }
}
' This example shows how to obtain all ProgIDs of all OPC Data Access servers on the local 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
Imports OpcLabs.EasyOpc.DataAccess
Imports OpcLabs.EasyOpc.OperationModel

Namespace DataAccess._EasyDAClient
    Partial Friend Class BrowseServers
        Shared Sub Main1()
            Dim client = New EasyDAClient()

            Dim serverElements As ServerElementCollection
            Try
                serverElements = client.BrowseServers("")
            Catch opcException As OpcException
                Console.WriteLine("*** Failure: {0}", opcException.GetBaseException().Message)
                Exit Sub
            End Try

            For Each serverElement In serverElements
                Console.WriteLine($"ServerElements(""{serverElement.ClsidString}"").ProgId: {serverElement.ProgId}")
            Next serverElement

        End Sub

        ' Example output:
        '
        'ServerElements("c8a12f17-1e03-401e-b53d-6c654dd576da").ProgId: OPCLabs.KitServer.2
    End Class
End Namespace
// This example shows how to obtain all ProgIDs of all OPC Data Access servers on the local machine.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// 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.

var Client = new ActiveXObject("OpcLabs.EasyOpc.DataAccess.EasyDAClient");
var ServerElements = Client.BrowseServers("")

for (var objEnum = new Enumerator(ServerElements) ; !objEnum.atEnd() ; objEnum.moveNext()) {
    var ServerElement = objEnum.item();
    WScript.Echo("ServerElements(\"" + ServerElement.UrlString + "\").ProgId: " + ServerElement.ProgId);
}
// This example shows how to obtain all ProgIDs of all OPC Data Access servers on the local machine.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// OPC client and subscriber examples in PHP on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-PHP .
// 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.

$Client = new COM("OpcLabs.EasyOpc.DataAccess.EasyDAClient");

try
{
    $ServerElements = $Client->BrowseServers("");
}
catch (com_exception $e)
{
    printf("*** Failure: %s\n", $e->getMessage());
    Exit();
}

foreach ($ServerElements as $ServerElement)
{
    printf("ServerElements(\"s\").ProgIds\n", $ServerElement->ClsidString, $ServerElement->ProgId);
}
# This example shows how to obtain all ProgIDs of all OPC Data Access servers on the local machine.
#
# The Python for Windows (pywin32) extensions package is needed. Install it using "pip install pypiwin32".
# CAUTION: We now recommend using Python.NET package instead. Full set of examples with Python.NET is available!
#
# Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
import win32com.client
from pywintypes import com_error

# Instantiate the client object
client = win32com.client.Dispatch('OpcLabs.EasyOpc.DataAccess.EasyDAClient') 

# Perform the operation
try:
    serverElements = client.BrowseServers('')
except com_error as e:
    print('*** Failure: ' + e.args[2][1] + ': ' + e.args[2][2])
    exit()

# Display results
for serverElement in serverElements:
    print('ServerElements("' + serverElement.ClsidString + '"): ' + serverElement.ProgId)
Rem This example shows how to obtain all ProgIDs of all OPC Data Access servers on the local machine.
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

Dim Client: Set Client = CreateObject("OpcLabs.EasyOpc.DataAccess.EasyDAClient")
On Error Resume Next
Dim ServerElements: Set ServerElements = Client.BrowseServers("")
If Err.Number <> 0 Then
    WScript.Echo "*** Failure: " & Err.Source & ": " & Err.Description
    WScript.Quit
End If
On Error Goto 0

Dim ServerElement: For Each ServerElement In ServerElements
    WScript.Echo "ServerElements(""" & ServerElement.ClsidString & """).ProgId: " & ServerElement.ProgId
Next
# This example shows how to obtain all ProgIDs of all OPC Data Access servers on the local machine.
#
# 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.DataAccess import *
from OpcLabs.EasyOpc.OperationModel import *


# Instantiate the client object
client = EasyDAClient()

# Perform the operation
try:
    serverElements = IEasyDAClientExtension.BrowseServers(client, '')
except OpcException as opcException:
    print('*** Failure: ' + opcException.GetBaseException().Message)
    exit()

# Display results
for serverElement in serverElements:
    print('ServerElements("' + serverElement.ClsidString + '"): ' + serverElement.ProgId)
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