// This example shows how to subscribe to changes of multiple items and obtain the item changed events by pulling them.
using System;
using OpcLabs.EasyOpc.DataAccess;
using OpcLabs.EasyOpc.DataAccess.OperationModel;
namespace DocExamples.DataAccess._EasyDAClient
{
partial class PullItemChanged
{
public static void MultipleItems()
{
// 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.SubscribeMultipleItems(
new[] {
new DAItemGroupArguments("", "OPCLabs.KitServer.2", "Simulation.Random", 1000, null),
new DAItemGroupArguments("", "OPCLabs.KitServer.2", "Trends.Ramp (1 min)", 1000, null),
new DAItemGroupArguments("", "OPCLabs.KitServer.2", "Trends.Sine (1 min)", 1000, null),
// Intentionally specifying an unknown item here, to demonstrate its behavior.
new DAItemGroupArguments("", "OPCLabs.KitServer.2", "SomeUnknownItem", 1000, 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
if (eventArgs.Succeeded)
Console.WriteLine($"{eventArgs.Arguments.ItemDescriptor.ItemId}: {eventArgs.Vtq}");
else
Console.WriteLine($"{eventArgs.Arguments.ItemDescriptor.ItemId} *** Failure: {eventArgs.ErrorMessageBrief}");
} while (Environment.TickCount < endTick);
Console.WriteLine("Unsubscribing item changes...");
client.UnsubscribeAllItems();
Console.WriteLine("Finished.");
}
}
}
# This example shows how to subscribe to changes of multiple items and obtain the item changed events by pulling them.
#requires -Version 5.1
using namespace OpcLabs.EasyOpc.DataAccess
using namespace OpcLabs.EasyOpc.DataAccess.OperationModel
# The path below assumes that the current directory is [ProductDir]/Examples-NET/PowerShell/Windows .
Add-Type -Path "../../../Components/Opclabs.QuickOpc/net472/OpcLabs.EasyOpcClassicCore.dll"
Add-Type -Path "../../../Components/Opclabs.QuickOpc/net472/OpcLabs.EasyOpcClassic.dll"
Add-Type -Path "../../../Components/Opclabs.QuickOpc/net472/OpcLabs.EasyOpcClassicComponents.dll"
# Instantiate the client object.
$client = New-Object EasyDAClient
# In order to use event pull, you must set a non-zero queue capacity upfront.
$client.PullItemChangedQueueCapacity = 1000
Write-Host "Subscribing item changes..."
$handleArray = [OpcLabs.EasyOpc.DataAccess.IEasyDAClientExtension]::SubscribeMultipleItems($client, @(
(New-Object DAItemGroupArguments("", "OPCLabs.KitServer.2", "Simulation.Random", 1000, $null)),
(New-Object DAItemGroupArguments("", "OPCLabs.KitServer.2", "Trends.Ramp (1 min)", 1000, $null)),
(New-Object DAItemGroupArguments("", "OPCLabs.KitServer.2", "Trends.Sine (1 min)", 1000, $null)),
# Intentionally specifying an unknown item here, to demonstrate its behavior.
(New-Object DAItemGroupArguments("", "OPCLabs.KitServer.2", "SomeUnknownItem", 1000, $null))
))
Write-Host "Processing item changes for 1 minute..."
$stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
while ($stopwatch.Elapsed.TotalSeconds -lt 60) {
$eventArgs = [IEasyDAClientExtension]::PullItemChanged($client, 2*1000)
if ($eventArgs -ne $null) {
# Handle the notification event
if ($eventArgs.Succeeded) {
Write-Host "$($eventArgs.Arguments.ItemDescriptor.ItemId): $($eventArgs.Vtq)"
}
else {
Write-Host "$($eventArgs.Arguments.ItemDescriptor.ItemId) *** Failure: $($eventArgs.ErrorMessageBrief)"
}
}
}
Write-Host "Unsubscribing item changes..."
$client.UnsubscribeAllItems()
Write-Host "Finished."
# This example shows how to subscribe to changes of multiple 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.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...')
client.SubscribeMultipleItems([
EasyDAItemSubscriptionArguments('', 'OPCLabs.KitServer.2', 'Simulation.Random', 1000, None),
EasyDAItemSubscriptionArguments('', 'OPCLabs.KitServer.2', 'Trends.Ramp (1 min)', 1000, None),
EasyDAItemSubscriptionArguments('', 'OPCLabs.KitServer.2', 'Trends.Sine (1 min)', 1000, None),
EasyDAItemSubscriptionArguments('', 'OPCLabs.KitServer.2', 'UnknownItem', 1000, None),
])
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.')