OPC Studio User's Guide and Reference
Examples - OPC XML-DA - Change update rate of a single subscription
View with Navigation Tools

.NET

// This example shows how change the update rate of an existing OPC XML-DA subscription.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .

using System;
using System.Threading;
using OpcLabs.EasyOpc.DataAccess;
using OpcLabs.EasyOpc.DataAccess.OperationModel;

namespace DocExamples.DataAccess.Xml
{
    class ChangeItemSubscription
    {
        public static void Main1Xml()
        {
            // Instantiate the client object.
            using (var client = new EasyDAClient())
            {
                client.ItemChanged += client_ItemChanged;

                Console.WriteLine("Subscribing...");
                int handle = client.SubscribeItem(
                    "http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx",
                    "Dynamic/Analog Types/Int",
                    2000,
                    state: null);

                Console.WriteLine("Waiting for 20 seconds...");
                Thread.Sleep(20 * 1000);

                Console.WriteLine("Changing subscription...");
                client.ChangeItemSubscription(handle, new DAGroupParameters(500));

                Console.WriteLine("Waiting for 10 seconds...");
                Thread.Sleep(10 * 1000);

                Console.WriteLine("Unsubscribing...");
                client.UnsubscribeAllItems();

                Console.WriteLine("Waiting for 10 seconds...");
                Thread.Sleep(10 * 1000);
            }
        }

        // Item changed event handler
        static void client_ItemChanged(object sender, EasyDAItemChangedEventArgs e)
        {
            if (e.Succeeded)
                Console.WriteLine(e.Vtq);
            else
                Console.WriteLine("*** Failure: {0}", e.ErrorMessageBrief);
        }
    }
}

COM

// This example shows how change the update rate of an existing OPC XML-DA subscription.
//
// Find all latest examples here : https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .

type
  TChangeItemSubscription_ClientEventHandlers = class
    // Item changed event handler
    procedure OnItemChanged(
      ASender: TObject;
      sender: OleVariant;
      const eventArgs: _EasyDAItemChangedEventArgs);
  end;

procedure TChangeItemSubscription_ClientEventHandlers.OnItemChanged(
  ASender: TObject;
  sender: OleVariant;
  const eventArgs: _EasyDAItemChangedEventArgs);
begin
  if Not eventArgs.Succeeded then
  begin
    WriteLn('*** Failure: ', eventArgs.ErrorMessageBrief);
    Exit;
  end;

  WriteLn(eventArgs.Vtq.ToString)
end;

class procedure ChangeItemSubscription.MainXml;
var
  Arguments: OleVariant;
  Client: TEasyDAClient;
  ClientEventHandlers: TChangeItemSubscription_ClientEventHandlers;
  HandleArray: OleVariant;
  ItemSubscriptionArguments1: _EasyDAItemSubscriptionArguments;
begin
  ItemSubscriptionArguments1 := CoEasyDAItemSubscriptionArguments.Create;
  ItemSubscriptionArguments1.ServerDescriptor.UrlString := 'http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx';
  ItemSubscriptionArguments1.ItemDescriptor.ItemID := 'Dynamic/Analog Types/Int';
  ItemSubscriptionArguments1.GroupParameters.RequestedUpdateRate := 2000;

  Arguments := VarArrayCreate([0, 0], varVariant);
  Arguments[0] := ItemSubscriptionArguments1;

  // Instantiate the client object and hook events
  Client := TEasyDAClient.Create(nil);
  ClientEventHandlers := TChangeItemSubscription_ClientEventHandlers.Create;
  Client.OnItemChanged := ClientEventHandlers.OnItemChanged;

  WriteLn('Subscribing...');
  TVarData(HandleArray).VType := varArray or varVariant;
  TVarData(HandleArray).VArray := PVarArray(
    Client.SubscribeMultipleItems(Arguments));

  WriteLn('Waiting for 20 seconds...');
  PumpSleep(20*1000);

  WriteLn('Changing subscription...');
  Client.ChangeItemSubscription(HandleArray[0], 500);

  WriteLn('Waiting for 10 seconds...');
  PumpSleep(10*1000);

  WriteLn('Unsubscribing...');
  Client.UnsubscribeAllItems;

  WriteLn('Waiting for 10 seconds...');
  PumpSleep(10*1000);

  VarClear(HandleArray);
  VarClear(Arguments);
  FreeAndNil(Client);
  FreeAndNil(ClientEventHandlers);
end;

 

OPC Data Client supports OPC XML-DA also on Linux and macOS.
See Also

Examples - OPC Data Access

Conceptual