OPC Studio User's Guide and Reference
ChangeItemSubscription Method (_EasyDAClient)
Example 



OpcLabs.EasyOpcClassic Assembly > OpcLabs.EasyOpc.DataAccess.ComTypes Namespace > _EasyDAClient Interface : ChangeItemSubscription Method
Item subscription handle as returned by the SubscribeItem method
The new requested update rate.
Changes parameters of a subscription. Specify handle, and requested update rate.
Syntax
'Declaration
 
Sub ChangeItemSubscription( _
   ByVal handle As Integer, _
   ByVal requestedUpdateRate As Integer _
) 
'Usage
 
Dim instance As _EasyDAClient
Dim handle As Integer
Dim requestedUpdateRate As Integer
 
instance.ChangeItemSubscription(handle, requestedUpdateRate)
void ChangeItemSubscription( 
   int handle,
   int requestedUpdateRate
)
void ChangeItemSubscription( 
   int handle,
   int requestedUpdateRate
) 

Parameters

handle
Item subscription handle as returned by the SubscribeItem method
requestedUpdateRate
The new requested update rate.
Remarks

It is more efficient to change multiple subscriptions using ChangeMultipleItemSubscriptions method.

Example

COM

COM

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

Option Explicit

Dim Client: Set Client = CreateObject("OpcLabs.EasyOpc.DataAccess.EasyDAClient")
WScript.ConnectObject Client, "Client_"

WScript.Echo "Subscribing..."
Dim handle: handle = Client.SubscribeItem("", "OPCLabs.KitServer.2", "Simulation.Random", 1000)

WScript.Echo "Waiting for 10 seconds..."
WScript.Sleep 10*1000

WScript.Echo "Changing subscription..."
Client.ChangeItemSubscription handle, 100

WScript.Echo "Waiting for 10 seconds..."
WScript.Sleep 10*1000

WScript.Echo "Unsubscribing..."
Client.UnsubscribeAllItems

WScript.Echo "Waiting for 10 seconds..."
WScript.Sleep 10*1000

WScript.DisconnectObject Client
Set Client = Nothing



Sub Client_ItemChanged(Sender, e)
    If Not (e.Succeeded) Then
        WScript.Echo "*** Failure: " & e.ErrorMessageBrief
        Exit Sub
    End If

    WScript.Echo e.Vtq
End Sub
// 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;
// This example shows how change the update rate of an existing OPC XML-DA subscription.
//
// Some related documentation: http://php.net/manual/en/function.com-event-sink.php . Pay attention to the comment that says 
// "Be careful how you use this feature; if you are doing something similar to the example below, then it doesn't really make 
// sense to run it in a web server context.". What they are trying to say is that processing a web request should be 
// a short-lived code, which does not fit well with the idea of being subscribed to events and received them over longer time. 
// It is possible to write such code, but it is only useful when processing the request is allowed to take relatively long. Or, 
// when you are using PHP from command-line, or otherwise - not to serve a web page directly.
// 
// Subscribing to QuickOPC-COM events in the context of PHP Web application, while not imposing the limitations to the request 
// processing time, has to be "worked around", e.g. using the "event pull" mechanism.
//
// Find all latest examples here : https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .

class DEasyDAClientEvents {
    function ItemChanged($varSender, $varE)
    {
        if ($varE->Succeeded)
        {
        print $varE->Vtq->ToString();
            print "\n";
        }
        else
        {
            printf("*** Failure: %s\n", $varE->ErrorMessageBrief);
        }
    }
}

$ItemSubscriptionArguments1 = new COM("OpcLabs.EasyOpc.DataAccess.OperationModel.EasyDAItemSubscriptionArguments");
$ItemSubscriptionArguments1->ServerDescriptor->UrlString = "http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx";
$ItemSubscriptionArguments1->ItemDescriptor->ItemID = "Dynamic/Analog Types/Int";
$ItemSubscriptionArguments1->GroupParameters->RequestedUpdateRate = 2000;

$arguments[0] = $ItemSubscriptionArguments1;

// Instantiate the client object.
$Client = new COM("OpcLabs.EasyOpc.DataAccess.EasyDAClient");
$Events = new DEasyDAClientEvents();
com_event_sink($Client, $Events, "DEasyDAClientEvents");

print "Subscribing...\n";
$handles = $Client->SubscribeMultipleItems($arguments);

print "Waiting for 20 seconds...\n";
$startTime = time(); do { com_message_pump(1000); } while (time() < $startTime + 20);

print "Changing subscription...";
$Client->ChangeItemSubscription($handles[0], 500);

print "Waiting for 10 seconds...\n";
$startTime = time(); do { com_message_pump(1000); } while (time() < $startTime + 10);

print "Unsubscribing...\n";
$Client->UnsubscribeAllItems;

print "Waiting for 10 seconds...\n";
$startTime = time(); do { com_message_pump(1000); } while (time() < $startTime + 10);
Rem This example shows how change the update rate of an existing OPC XML-DA subscription.
Rem
Rem Find all latest examples here : https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .

' The client object, with events
'Public WithEvents Client1 As EasyDAClient

Private Sub ChangeItemSubscription_MainXml_Command_Click()
    OutputText = ""
    
    Dim ItemSubscriptionArguments1 As New EasyDAItemSubscriptionArguments
    ItemSubscriptionArguments1.serverDescriptor.UrlString = "http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx"
    ItemSubscriptionArguments1.ItemDescriptor.ItemId = "Dynamic/Analog Types/Int"
    ItemSubscriptionArguments1.GroupParameters.RequestedUpdateRate = 2000

    Dim arguments(0) As Variant
    Set arguments(0) = ItemSubscriptionArguments1

    ' Instantiate the client object and hook events
    Set Client1 = New EasyDAClient

    OutputText = OutputText & "Subscribing..." & vbCrLf
    Dim handles() As Variant
    handles = Client1.SubscribeMultipleItems(arguments)
    
    OutputText = OutputText & "Waiting for 20 seconds..." & vbCrLf
    Pause 20000

    OutputText = OutputText & "Changing subscription..." & vbCrLf
    Call Client1.ChangeItemSubscription(handles(0), 500)

    OutputText = OutputText & "Waiting for 10 seconds..." & vbCrLf
    Pause 10000

    OutputText = OutputText & "Unsubscribing..." & vbCrLf
    Client1.UnsubscribeAllItems

    OutputText = OutputText & "Waiting for 10 seconds..." & vbCrLf
    Pause 10000

    Set Client1 = Nothing
End Sub

Public Sub Client1_ItemChanged(ByVal sender As Variant, ByVal eventArgs As EasyDAItemChangedEventArgs)
    If Not eventArgs.Succeeded Then
        OutputText = OutputText & "*** Failure: " & eventArgs.ErrorMessageBrief & vbCrLf
        Exit Sub
    End If
    OutputText = OutputText & eventArgs.vtq & vbCrLf
End Sub
Rem This example shows how change the update rate of an existing OPC XML-DA subscription.
Rem
Rem Find all latest examples here : https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .

Option Explicit

Dim ItemSubscriptionArguments1: Set ItemSubscriptionArguments1 = CreateObject("OpcLabs.EasyOpc.DataAccess.OperationModel.EasyDAItemSubscriptionArguments")
ItemSubscriptionArguments1.ServerDescriptor.UrlString = "http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx"
ItemSubscriptionArguments1.ItemDescriptor.ItemID = "Dynamic/Analog Types/Int"
ItemSubscriptionArguments1.GroupParameters.RequestedUpdateRate = 2000

Dim arguments(0)
Set arguments(0) = ItemSubscriptionArguments1

Dim Client: Set Client = CreateObject("OpcLabs.EasyOpc.DataAccess.EasyDAClient")
WScript.ConnectObject Client, "Client_"

WScript.Echo "Subscribing..."
Dim handles: handles = Client.SubscribeMultipleItems(arguments)


WScript.Echo "Waiting for 20 seconds..."
WScript.Sleep 20*1000

WScript.Echo "Changing subscription..."
Client.ChangeItemSubscription handles(0), 500

WScript.Echo "Waiting for 10 seconds..."
WScript.Sleep 10*1000

WScript.Echo "Unsubscribing..."
Client.UnsubscribeAllItems

WScript.Echo "Waiting for 10 seconds..."
WScript.Sleep 10*1000

WScript.DisconnectObject Client
Set Client = Nothing


' Item changed event handler
Sub Client_ItemChanged(Sender, e)
    If Not (e.Succeeded) Then
        WScript.Echo "*** Failure: " & e.ErrorMessageBrief
        Exit Sub
    End If

    WScript.Echo e.Vtq
End Sub
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