OPC Studio User's Guide and Reference
ChangeItemSubscription(IEasyDAClient,DAHandleGroupArguments) Method
Example 



OpcLabs.EasyOpcClassicCore Assembly > OpcLabs.EasyOpc.DataAccess Namespace > IEasyDAClientExtension Class > ChangeItemSubscription Method : ChangeItemSubscription(IEasyDAClient,DAHandleGroupArguments) Method
The client object that will perform the operation.
Holds an integer handle, and OPC group parameters
Changes parameters of a subscription. Specify an object holding the handle and group parameters.
Syntax
'Declaration
 
<ExtensionAttribute()>
Public Overloads Shared Sub ChangeItemSubscription( _
   ByVal client As IEasyDAClient, _
   ByVal handleGroupArguments As DAHandleGroupArguments _
) 
'Usage
 
Dim client As IEasyDAClient
Dim handleGroupArguments As DAHandleGroupArguments
 
IEasyDAClientExtension.ChangeItemSubscription(client, handleGroupArguments)
[Extension()]
public static void ChangeItemSubscription( 
   IEasyDAClient client,
   DAHandleGroupArguments handleGroupArguments
)
[Extension()]
public:
static void ChangeItemSubscription( 
   IEasyDAClient^ client,
   DAHandleGroupArguments^ handleGroupArguments
) 

Parameters

client
The client object that will perform the operation.
handleGroupArguments
Holds an integer handle, and OPC group parameters
Exceptions
ExceptionDescription

One of the arguments provided to a method is not valid.

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.

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.

Remarks

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

Example

.NET

.NET

// This example shows how change the update rate of an existing 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._EasyDAClient
{
    partial class ChangeItemSubscription
    {
        public static void Main1()
        {
            // Instantiate the client object.
            using (var client = new EasyDAClient())
            {
                client.ItemChanged += client_ItemChanged;

                Console.WriteLine("Subscribing...");
                int handle = client.SubscribeItem("", "OPCLabs.KitServer.2", "Simulation.Random", 1000);

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

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

                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);
        }
    }
}
# This example shows how change the update rate of an existing subscription.
#
# 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 .
# The QuickOPC package is needed. Install it using "pip install opclabs_quickopc".
import opclabs_quickopc
import time

# Import .NET namespaces.
from OpcLabs.EasyOpc.DataAccess import *


# Item changed event handler
def itemChanged(sender, e):
    if e.Succeeded:
        print(e.Vtq)
    else:
        print('*** Failure: ', e.ErrorMessageBrief, sep='')


# Instantiate the client object.
client = EasyDAClient()

client.ItemChanged += itemChanged

print('Subscribing item...')
handle = IEasyDAClientExtension.SubscribeItem(client, '', 'OPCLabs.KitServer.2', 'Simulation.Random', 1000)

print('Processing item change notifications for 10 seconds...')
time.sleep(10)

print('Changing item subscription...')
IEasyDAClientExtension.ChangeItemSubscription(client, handle, DAGroupParameters(100))

print('Processing item change notifications for 10 seconds...')
time.sleep(10)

print('Unsubscribing item...')
IEasyDAClientExtension.UnsubscribeItem(client, handle)

print('Waiting for 10 seconds...')
time.sleep(10)

client.ItemChanged -= itemChanged

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

Imports System.Threading
Imports OpcLabs.EasyOpc.DataAccess
Imports OpcLabs.EasyOpc.DataAccess.OperationModel

Namespace DataAccess._EasyDAClient

    Partial Friend Class ChangeItemSubscription
        Public Shared Sub Main1()
            Using client = New EasyDAClient()
                AddHandler client.ItemChanged, AddressOf client_ItemChanged

                Console.WriteLine("Subscribing...")
                Dim handle As Integer = client.SubscribeItem("", "OPCLabs.KitServer.2", "Simulation.Random", 1000)

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

                Console.WriteLine("Changing subscription...")
                client.ChangeItemSubscription(handle, New DAGroupParameters(100))

                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)
            End Using
        End Sub

        ' Item changed event handler
        Private Shared Sub client_ItemChanged(ByVal sender As Object, ByVal e As EasyDAItemChangedEventArgs)
            If e.Succeeded Then
                Console.WriteLine(e.Vtq)
            Else
                Console.WriteLine("*** Failure: {0}", e.ErrorMessageBrief)
            End If
        End Sub
    End Class
End Namespace
// 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);
        }
    }
}
# 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 .
# OPC client and subscriber examples in Python on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-Python .
# The QuickOPC package is needed. Install it using "pip install opclabs_quickopc".
import opclabs_quickopc
import time

# Import .NET namespaces.
from OpcLabs.EasyOpc import *
from OpcLabs.EasyOpc.DataAccess import *


# Item changed event handler
def itemChanged(sender, e):
    if e.Succeeded:
        print(e.Vtq)
    else:
        print('*** Failure: ', e.ErrorMessageBrief, sep='')


# Instantiate the client object.
client = EasyDAClient()

client.ItemChanged += itemChanged

print('Subscribing item...')
handle = IEasyDAClientExtension.SubscribeItem(client,
    ServerDescriptor('http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx'),
    DAItemDescriptor('Dynamic/Analog Types/Int'),
    DAGroupParameters(2000),
    None) # state

print('Processing item change notifications for 20 seconds...')
time.sleep(20)

print('Changing item subscription...')
IEasyDAClientExtension.ChangeItemSubscription(client, handle, DAGroupParameters(500))

print('Processing item change notifications for 10 seconds...')
time.sleep(10)

print('Unsubscribing item...')
IEasyDAClientExtension.UnsubscribeItem(client, handle)

print('Waiting for 10 seconds...')
time.sleep(10)

client.ItemChanged -= itemChanged

print('Finished.')
' 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 .

Imports System.Threading
Imports OpcLabs.EasyOpc.DataAccess
Imports OpcLabs.EasyOpc.DataAccess.OperationModel

Namespace DataAccess.Xml

    Partial Friend Class ChangeItemSubscription
        Public Shared Sub Main1Xml()
            Using client = New EasyDAClient()
                AddHandler client.ItemChanged, AddressOf client_ItemChanged

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

                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)
            End Using
        End Sub

        ' Item changed event handler
        Private Shared Sub client_ItemChanged(ByVal sender As Object, ByVal e As EasyDAItemChangedEventArgs)
            If e.Succeeded Then
                Console.WriteLine(e.Vtq)
            Else
                Console.WriteLine("*** Failure: {0}", e.ErrorMessageBrief)
            End If
        End Sub
    End Class
End Namespace
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