QuickOPC User's Guide and Reference
GetConnectionElement Method (IUAReadOnlyPubSubConfigurationExtension)
Example 



View with Navigation Tools
OpcLabs.EasyOpcUA Assembly > OpcLabs.EasyOpc.UA.PubSub.Configuration.Extensions Namespace > IUAReadOnlyPubSubConfigurationExtension Class : GetConnectionElement Method
OPC UA PubSub configuration (read-only).
The name of the PubSub connection.
Gets the element for the PubSub connection with specified name.
Syntax
'Declaration
 
<ExtensionAttribute()>
<NotNullAttribute()>
Public Shared Function GetConnectionElement( _
   ByVal readOnlyPubSubConfiguration As IUAReadOnlyPubSubConfiguration, _
   ByVal pubSubConnectionName As String _
) As UAPubSubConnectionElement
 
'Usage
 
Dim readOnlyPubSubConfiguration As IUAReadOnlyPubSubConfiguration
Dim pubSubConnectionName As String
Dim value As UAPubSubConnectionElement
 
value = IUAReadOnlyPubSubConfigurationExtension.GetConnectionElement(readOnlyPubSubConfiguration, pubSubConnectionName)

Parameters

readOnlyPubSubConfiguration
OPC UA PubSub configuration (read-only).
pubSubConnectionName
The name of the PubSub connection.

Return Value

Returns the PubSub connection element.
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.

There is a logical error in the OPC UA operation.

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.

Example

.NET

COM

// This example obtains and prints out information about PubSub connections, writer groups, and dataset writers in the
// OPC UA PubSub configuration.

using System;
using OpcLabs.BaseLib.Collections.Specialized;
using OpcLabs.EasyOpc.UA.OperationModel;
using OpcLabs.EasyOpc.UA.PubSub.Configuration;
using OpcLabs.EasyOpc.UA.PubSub.InformationModel;
using OpcLabs.EasyOpc.UA.PubSub.InformationModel.Extensions;

namespace UADocExamples.PubSub._IUAReadOnlyPubSubConfiguration
{
    partial class GetMethods
    {
        public static void PubSubComponents()
        {
            // Instantiate the publish-subscribe client object.
            var publishSubscribeClient = new EasyUAPublishSubscribeClient();

            try
            {
                Console.WriteLine("Loading the configuration...");
                // Load the PubSub configuration from a file. The file itself is at the root of the project, and we have
                // specified that it has to be copied to the project's output directory.
                IUAReadOnlyPubSubConfiguration pubSubConfiguration =
                    publishSubscribeClient.LoadReadOnlyConfiguration("UADemoPublisher-Default.uabinary");

                // Alternatively, using the statement below, you can access a live configuration residing in an OPC UA Server
                // with appropriate information model.
                //IUAReadOnlyPubSubConfiguration pubSubConfiguration =
                //    publishSubscribeClient.AccessReadOnlyConfiguration("opc.tcp://localhost:48010");

                // Get the names of PubSub connections in the configuration, regardless of the folder they reside in.
                StringCollection pubSubConnectionNames = pubSubConfiguration.ListConnectionNames();
                foreach (string pubSubConnectionName in pubSubConnectionNames)
                {
                    Console.WriteLine($"PubSub connection: {pubSubConnectionName}");

                    // You can use the statement below to obtain parameters of the PubSub connection.
                    //UAPubSubConnectionElement connectionElement = 
                    //    pubSubConfiguration.GetConnectionElement(pubSubConnectionName);

                    // Get names of the writer groups on this PubSub connection.
                    StringCollection writerGroupNames = pubSubConfiguration.ListWriterGroupNames(pubSubConnectionName);
                    foreach (string writerGroupName in writerGroupNames)
                    {
                        Console.WriteLine($"  Writer group: {writerGroupName}");

                        // You can use the statement below to obtain parameters of the writer group.
                        //UAWriterGroupElement writerGroupElement = 
                        //    pubSubConfiguration.GetWriterGroupElement(pubSubConnectionName, writerGroupName);

                        // Get names of the dataset writers on this writer group.
                        StringCollection dataSetWriterNames =
                            pubSubConfiguration.ListDataSetWriterNames(pubSubConnectionName, writerGroupName);
                        foreach (string dataSetWriterName in dataSetWriterNames)
                        {
                            Console.WriteLine($"    Dataset writer: {dataSetWriterName}");

                            // You can use the statement below to obtain parameters of the dataset writer.
                            //UADataSetWriterElement dataSetWriterElement = pubSubConfiguration.GetDataSetWriterElement(
                            //    pubSubConnectionName, writerGroupName, dataSetWriterName);
                        }
                    }
                }
            }
            catch (UAException uaException)
            {
                Console.WriteLine($"*** Failure: {uaException.InnerException.Message}");
            }

            Console.WriteLine("Finished.");
        }

        // Example output:
        //
        //Loading the configuration...
        //PubSub connection: FixedLayoutConnection
        //  Writer group: FixedLayoutGroup
        //    Dataset writer: SimpleWriter
        //    Dataset writer: AllTypesWriter
        //    Dataset writer: MassTestWriter
        //PubSub connection: DynamicLayoutConnection
        //  Writer group: DynamicLayoutGroup
        //    Dataset writer: SimpleWriter
        //    Dataset writer: MassTestWriter
        //    Dataset writer: AllTypes-DynamicWriter
        //    Dataset writer: EventSimpleWriter
        //PubSub connection: FlexibleLayoutConnection
        //  Writer group: FlexibleLayoutGroup
        //    Dataset writer: SimpleWriter
        //    Dataset writer: MassTestWriter
        //    Dataset writer: AllTypes-DynamicWriter
        //Finished.
    }
}
// This example obtains and prints out information about PubSub connections, writer groups, and dataset writers in the
// OPC UA PubSub configuration.

class procedure GetMethods.PubSubComponents;
var
  //DataSetWriterElement: _UADataSetWriterElement;
  DataSetWriterName: string;
  DataSetWriterNames: _StringCollection;
  //EndpointDescriptor: _UAEndpointDescriptor;
  I, J, K: Integer;
  //PubSubConnectionElement: _UAPubSubConnectionElement;
  PubSubConnectionName: string;
  ConnectionNames: _StringCollection;
  PublishSubscribeClient: _EasyUAPublishSubscribeClient;
  PubSubConfiguration: _UAReadOnlyPubSubConfiguration;
  //WriterGroupElement: _UAWriterGroupElement;
  WriterGroupName: string;
  WriterGroupNames: _StringCollection;
begin
  // Instantiate the publish-subscribe client object.
  PublishSubscribeClient := CoEasyUAPublishSubscribeClient.Create;

  try
    WriteLn('Loading the configuration...');
    // Load the PubSub configuration from a file. The file itself is included alongside the script.
    PubSubConfiguration := PublishSubscribeClient.LoadReadOnlyConfiguration('UADemoPublisher-Default.uabinary');

    // Alternatively, using the statements below, you can access a live configuration residing in an OPC UA Server
    // with appropriate information model.
    //EndpointDescriptor := CoUAEndpointDescriptor.Create;
    //EndpointDescriptor.UrlString := 'opc.tcp://localhost:48010';
    //PubSubConfiguration := PublishSubscribeClient.AccessReadOnlyConfiguration(EndpointDescriptor);

    // Get the names of PubSub connections in the configuration.
    ConnectionNames := PubSubConfiguration.ListConnectionNames;

    for I := 0 to ConnectionNames.Count-1 do
    begin
      PubSubConnectionName := ConnectionNames[I];
      WriteLn('PubSub connection: ', PubSubConnectionName);

      // You can use the statement below to obtain parameters of the PubSub connection.
      //PubSubConnectionElement := PubSubConfiguration.GetConnectionElement(PubSubConnectionName);

      // Get names of the writer groups on this PubSub connection.
      WriterGroupNames := PubSubConfiguration.ListWriterGroupNames(PubSubConnectionName);
      for J := 0 to WriterGroupNames.Count-1 do
      begin
        WriterGroupName := WriterGroupNames[J];
        WriteLn('  Writer group: ', WriterGroupName);

        // You can use the statement below to obtain parameters of the writer group.
        //WriterGroupElement := PubSubConfiguration.GetWriterGroupElement(PubSubConnectionName, WriterGroupName);

        // Get names of the dataset writers on this writer group.
        DataSetWriterNames := PubSubConfiguration.ListDataSetWriterNames(PubSubConnectionName, WriterGroupName);
        for K := 0 to DataSetWriterNames.Count-1 do
        begin
          DataSetWriterName := DataSetWriterNames[K];
          WriteLn('    Dataset writer: ', DataSetWriterName);

          // You can use the statement below to obtain parameters of the dataset writer.
          //DataSetWriterElement := PubSubConfiguration.GetDataSetWriterElement(PubSubConnectionName, WriterGroupName, DataSetWriterName);
        end;
      end;
    end;
  except
    on E: EOleException do
    begin
      WriteLn(Format('*** Failure: %s', [E.GetBaseException.Message]));
    end;
  end;

  WriteLn('Finished.');
end;

// Example output:
//
//Loading the configuration...
//PubSub connection: FixedLayoutConnection
//  Writer group: FixedLayoutGroup
//    Dataset writer: SimpleWriter
//    Dataset writer: AllTypesWriter
//    Dataset writer: MassTestWriter
//PubSub connection: DynamicLayoutConnection
//  Writer group: DynamicLayoutGroup
//    Dataset writer: SimpleWriter
//    Dataset writer: MassTestWriter
//    Dataset writer: AllTypes-DynamicWriter
//    Dataset writer: EventSimpleWriter
//PubSub connection: FlexibleLayoutConnection
//  Writer group: FlexibleLayoutGroup
//    Dataset writer: SimpleWriter
//    Dataset writer: MassTestWriter
//    Dataset writer: AllTypes-DynamicWriter
//Finished.
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