Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

AVEVA Enterprise SCADA PubSub API Reference

Subscribe to and unsubscribe from a PubSub topic

This scenario guides you through the steps required to subscribe to and unsubscribe from a PubSub topic.

To identify the code associated with each step, see the code comments in the Example code section.

To subscribe to and unsubscribe from a PubSub topic

  1. Open the Program.cs file from the created project.
  2. Open a PubSub connection.
  3. Confirm there is a connection with the PubSub system.
  4. Subscribe to a PubSub topic with a finite or non-finite timeout.
  5. Receive data from the underlying PubSub connection. Data is blocked until available or the timeout has expired.
  6. Unsubscribe from a PubSub topic by using one of the following methods:
    • Using the Disconnect method.
      // Disconnect, which will unsubscribe, clean up, and disconnect from the engine.
      pubsubConnection.Disconnect();               
    • Once the using block is finished, disposing the connection will remove the publisher, clean up, and disconnect from the engine. If a using block is used, calling Disconnect explicity is optional.

Example code

internal void AddSubscriptionWithConnectionFactoryAndUnsubscribe()
{
    try
    {
        IPubSubConnectionFactory pubSubConnectionFactory = new PubSubConnectionFactory();
        // Open a connection.
        using (var pubsubConnection = pubSubConnectionFactory.OpenConnection())
        {
            // Check if there is connection with the PubSub system.
            if (pubsubConnection.IsConnected())
            {
                var topic = "es.realtime.db.analog.DeviceRollupAnalog01.curval";
                // Subscribe to a PubSub topic with a finite or non-finite timeout.
                var subscription = pubsubConnection.Subscribe(topic, Timeout.InfiniteTimeSpan, true);
                 // Receive data from the underlying PubSub connection. Data is blocked until available or the timeout has expired.
                var pubsubMsg = subscription.Receive();                       
                Console.WriteLine(
quot;Current topic has:
{pubsubMsg.GetDouble()} value."); // Unsubscribe from a PubSub topic. pubsubConnection.Disconnect(); } } } catch (Exception ex) { Console.WriteLine("Error:" + ex.Message); } }
TitleResults for “How to create a CRG?”Also Available in