QuickOPC User's Guide and Reference
Examples - OPC XML-DA - Event pull

Example with single item:

// This example shows how to subscribe to OPC XML-DA item changes and obtain the events by pulling them.

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

namespace DocExamples.DataAccess.Xml
{
    class PullItemChanged
    {
        public static void Main1Xml()
        {
            // Instantiate the client object.
            // In order to use event pull, you must set a non-zero queue capacity upfront.
            var client = new EasyDAClient { PullItemChangedQueueCapacity = 1000 };

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

            Console.WriteLine("Processing item changes for 1 minute...");
            int endTick = Environment.TickCount + 60 * 1000;
            do
            {
                EasyDAItemChangedEventArgs eventArgs = client.PullItemChanged(2 * 1000);
                if (!(eventArgs is null))
                    // Handle the notification event
                    Console.WriteLine(eventArgs);
            } while (Environment.TickCount < endTick);

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

            Console.WriteLine("Finished.");
        }
    }
}
# This example shows how to subscribe to OPC XML-DA item changes and obtain the events by pulling them.

# 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 *


# Instantiate the client object
client = EasyDAClient()
# In order to use event pull, you must set a non-zero queue capacity upfront.
client.PullItemChangedQueueCapacity = 1000

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

print('Processing item changes for 1 minute...')
endTime = time.time() + 60
while time.time() < endTime:
    eventArgs = IEasyDAClientExtension.PullItemChanged(client, 2*1000)
    if eventArgs is not None:
        # Handle the notification event
        print(eventArgs)

print('Unsubscribing item changes...')
client.UnsubscribeAllItems()

print('Finished.')
' This example shows how to subscribe to OPC XML-DA item changes and obtain the events by pulling them.

Imports OpcLabs.EasyOpc.DataAccess
Imports OpcLabs.EasyOpc.DataAccess.OperationModel

Namespace DataAccess.Xml
    Partial Friend Class PullItemChanged
        Public Shared Sub Main1Xml()
            ' In order to use event pull, you must set a non-zero queue capacity upfront.
            Dim client = New EasyDAClient() With {.PullItemChangedQueueCapacity = 1000}

            Console.WriteLine("Subscribing item changes...")
            client.SubscribeItem(
                    "http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx",
                    "Dynamic/Analog Types/Int",
                    1000,
                    state:=Nothing)

            Console.WriteLine("Processing item changes for 1 minute...")
            Dim endTick As Integer = Environment.TickCount + 60 * 1000
            Do
                Dim eventArgs As EasyDAItemChangedEventArgs = client.PullItemChanged(2 * 1000)
                If Not eventArgs Is Nothing Then
                    ' Handle the notification event
                    Console.WriteLine(eventArgs)
                End If
            Loop While Environment.TickCount < endTick

            Console.WriteLine("Unsubscribing item changes...")
            client.UnsubscribeAllItems()

            Console.WriteLine("Finished.")
        End Sub
    End Class
End Namespace

Example with multiple items:

.NET

# This example shows how to subscribe to changes of multiple OPC XML-DA items and obtain the item changed events by pulling them.

# 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 *
from OpcLabs.EasyOpc.DataAccess.OperationModel import *


# Instantiate the client object
client = EasyDAClient()
# In order to use event pull, you must set a non-zero queue capacity upfront.
client.PullItemChangedQueueCapacity = 1000

print('Subscribing item changes...')

itemSubscriptionArguments1 = EasyDAItemSubscriptionArguments(
    ServerDescriptor('http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx'),
    DAItemDescriptor('Dynamic/Analog Types/Double'),
    DAGroupParameters(1000),
    None)

itemSubscriptionArguments2 = EasyDAItemSubscriptionArguments(
    ServerDescriptor('http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx'),
    DAItemDescriptor('Dynamic/Analog Types/Double[]'),
    DAGroupParameters(1000),
    None)

itemSubscriptionArguments3 = EasyDAItemSubscriptionArguments(
    ServerDescriptor('http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx'),
    DAItemDescriptor('Dynamic/Analog Types/Int'),
    DAGroupParameters(1000),
    None)

# Intentionally specifying an unknown item here, to demonstrate its behavior.
itemSubscriptionArguments4 = EasyDAItemSubscriptionArguments(
    ServerDescriptor('http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx'),
    DAItemDescriptor('SomeUnknownItem'),
    DAGroupParameters(1000),
    None)

client.SubscribeMultipleItems([
    itemSubscriptionArguments1,
    itemSubscriptionArguments2,
    itemSubscriptionArguments3,
    itemSubscriptionArguments4,
    ])

print('Processing item changes for 1 minute...')
endTime = time.time() + 60
while time.time() < endTime:
    eventArgs = IEasyDAClientExtension.PullItemChanged(client, 2*1000)
    if eventArgs is not None:
        # Handle the notification event
        if (eventArgs.Succeeded):
            print(eventArgs.Arguments.ItemDescriptor.ItemId, ': ', eventArgs.Vtq, sep='')
        else:
            print(eventArgs.Arguments.ItemDescriptor.ItemId, ' *** Failure: ', eventArgs.ErrorMessageBrief, sep='')

print('Unsubscribing item changes...')
client.UnsubscribeAllItems()

print('Finished.')

COM

# This example shows how to subscribe to changes of multiple OPC XML-DA items and obtain the item changed events by pulling them.

# The Python for Windows (pywin32) extensions package is needed. Install it using "pip install pypiwin32".
# CAUTION: We now recommend using Python.NET package instead. Full set of examples with Python.NET is available!
import time
import win32com.client

# Instantiate the client object
client = win32com.client.Dispatch('OpcLabs.EasyOpc.DataAccess.EasyDAClient') 
# In order to use event pull, you must set a non-zero queue capacity upfront.
client.PullItemChangedQueueCapacity = 1000

print('Subscribing item changes...')

itemSubscriptionArguments1 = win32com.client.Dispatch('OpcLabs.EasyOpc.DataAccess.OperationModel.EasyDAItemSubscriptionArguments')
itemSubscriptionArguments1.ServerDescriptor.UrlString = 'http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx'
itemSubscriptionArguments1.ItemDescriptor.ItemID = 'Dynamic/Analog Types/Double'
itemSubscriptionArguments1.GroupParameters.RequestedUpdateRate = 1000

itemSubscriptionArguments2 = win32com.client.Dispatch('OpcLabs.EasyOpc.DataAccess.OperationModel.EasyDAItemSubscriptionArguments')
itemSubscriptionArguments2.ServerDescriptor.UrlString = 'http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx'
itemSubscriptionArguments2.ItemDescriptor.ItemID = 'Dynamic/Analog Types/Double[]'
itemSubscriptionArguments2.GroupParameters.RequestedUpdateRate = 1000

itemSubscriptionArguments3 = win32com.client.Dispatch('OpcLabs.EasyOpc.DataAccess.OperationModel.EasyDAItemSubscriptionArguments')
itemSubscriptionArguments3.ServerDescriptor.UrlString = 'http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx'
itemSubscriptionArguments3.ItemDescriptor.ItemID = 'Dynamic/Analog Types/Int'
itemSubscriptionArguments3.GroupParameters.RequestedUpdateRate = 1000

# Intentionally specifying an unknown item here, to demonstrate its behavior.
itemSubscriptionArguments4 = win32com.client.Dispatch('OpcLabs.EasyOpc.DataAccess.OperationModel.EasyDAItemSubscriptionArguments')
itemSubscriptionArguments4.ServerDescriptor.UrlString = 'http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx'
itemSubscriptionArguments4.ItemDescriptor.ItemID = 'SomeUnknownItem'
itemSubscriptionArguments4.GroupParameters.RequestedUpdateRate = 1000

arguments = [
    itemSubscriptionArguments1,
    itemSubscriptionArguments2,
    itemSubscriptionArguments3,
    itemSubscriptionArguments4,
    ]
client.SubscribeMultipleItems(arguments)

print('Processing item changes for 1 minute...')
endTime = time.time() + 60
while time.time() < endTime:
    eventArgs = client.PullItemChanged(2*1000)
    if eventArgs is not None:
        # Handle the notification event
        if (eventArgs.Succeeded):
            print(eventArgs.Arguments.ItemDescriptor.ItemId, ': ', eventArgs.Vtq, sep='')
        else:
            print(eventArgs.Arguments.ItemDescriptor.ItemId, ' *** Failure: ', eventArgs.ErrorMessageBrief, sep='')

print('Unsubscribing item changes...')
client.UnsubscribeAllItems()

print('Finished.')
QuickOPC supports OPC XML-DA also on Linux and macOS.
See Also

Examples - OPC Data Access

Conceptual