// This example shows how subscribe to changes of multiple items and display the value of the item with each change.
using System;
using System.Threading;
using OpcLabs.EasyOpc.DataAccess;
using OpcLabs.EasyOpc.DataAccess.OperationModel;
namespace DocExamples.DataAccess._EasyDAClient
{
partial class SubscribeMultipleItems
{
public static void Main1()
{
// Instantiate the client object.
using (var client = new EasyDAClient())
{
client.ItemChanged += client_Main1_ItemChanged;
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),
new DAItemGroupArguments("", "OPCLabs.KitServer.2", "Simulation.Register_I4", 1000, null)
});
Console.WriteLine("Processing item changed events for 1 minute...");
Thread.Sleep(60 * 1000);
Console.WriteLine("Unsubscribing item changes...");
}
Console.WriteLine("Finished.");
}
// Item changed event handler
static void client_Main1_ItemChanged(object sender, EasyDAItemChangedEventArgs e)
{
if (e.Succeeded)
Console.WriteLine($"{e.Arguments.ItemDescriptor.ItemId}: {e.Vtq}");
else
Console.WriteLine($"{e.Arguments.ItemDescriptor.ItemId} *** Failure: {e.ErrorMessageBrief}");
}
}
}
# This example shows how subscribe to changes of multiple items and display the value of the item with each change.
#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
# Item changed event handler
Register-ObjectEvent -InputObject $client -EventName ItemChanged -Action {
if ($EventArgs.Succeeded) {
Write-Host "$($EventArgs.Arguments.ItemDescriptor.ItemId): $($EventArgs.Vtq)"
}
else {
Write-Host "$($EventArgs.Arguments.ItemDescriptor.ItemId) *** Failure: $($EventArgs.ErrorMessageBrief)"
}
}
Write-Host "Subscribing item changes..."
$handleArray = [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)),
(New-Object DAItemGroupArguments("", "OPCLabs.KitServer.2", "Simulation.Register_I4", 1000, $null))
))
Write-Host "Processing item changed events for 1 minute..."
$stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
while ($stopwatch.Elapsed.TotalSeconds -lt 30) {
Start-Sleep -Seconds 1
}
Write-Host "Unsubscribing item changes..."
$client.UnsubscribeAllItems()
Write-Host "Finished."
# This example shows how subscribe to changes of multiple items and display the value of the item with each change.
# 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 *
# Item changed event handler.
def itemChanged(sender, e):
if e.Succeeded:
print(e.Arguments.ItemDescriptor.ItemId, ': ', e.Vtq, sep='')
else:
print(e.Arguments.ItemDescriptor.ItemId, ' *** Failure: ', e.ErrorMessageBrief, sep='')
# Instantiate the client object.
client = EasyDAClient()
client.ItemChanged += itemChanged
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', 'Simulation.Register_I4', 1000, None),
])
print('Processing item change notifications for 1 minute...')
time.sleep(60)
print('Unsubscribing all items...')
client.UnsubscribeAllItems()
client.ItemChanged -= itemChanged
print('Finished.')
' This example shows how subscribe to changes of multiple items and display the value of the item with each change.
Imports System.Threading
Imports OpcLabs.EasyOpc.DataAccess
Imports OpcLabs.EasyOpc.DataAccess.OperationModel
Namespace DataAccess._EasyDAClient
Partial Friend Class SubscribeMultipleItems
Public Shared Sub Main1()
Using client = New EasyDAClient()
AddHandler client.ItemChanged, AddressOf client_ItemChanged_Main1
client.SubscribeMultipleItems(New DAItemGroupArguments() { _
New DAItemGroupArguments("", "OPCLabs.KitServer.2", "Simulation.Random", 1000, Nothing), _
New DAItemGroupArguments("", "OPCLabs.KitServer.2", "Trends.Ramp (1 min)", 1000, Nothing), _
New DAItemGroupArguments("", "OPCLabs.KitServer.2", "Trends.Sine (1 min)", 1000, Nothing), _
New DAItemGroupArguments("", "OPCLabs.KitServer.2", "Simulation.Register_I4", 1000, Nothing) _
})
Console.WriteLine("Processing item changed events for 1 minute...")
Thread.Sleep(60 * 1000)
End Using
End Sub
' Item changed event handler
Private Shared Sub client_ItemChanged_Main1(ByVal sender As Object, ByVal e As EasyDAItemChangedEventArgs)
' Display the data
If e.Succeeded Then
Console.WriteLine("{0}: {1}", e.Arguments.ItemDescriptor.ItemId, e.Vtq)
Else
Console.WriteLine("{0} *** Failure: {1}", e.Arguments.ItemDescriptor.ItemId, e.ErrorMessageBrief)
End If
End Sub
End Class
End Namespace