// This example shows how to obtain dictionary of parameters of all monitored item subscriptions.
using System;
using OpcLabs.EasyOpc.UA;
using OpcLabs.EasyOpc.UA.OperationModel;
namespace UADocExamples._EasyUAClient
{
class GetMonitoredItemArgumentsDictionary
{
public static void Main1()
{
UAEndpointDescriptor endpointDescriptor =
"opc.tcp://opcua.demo-this.com:51210/UA/SampleServer";
// or "http://opcua.demo-this.com:51211/UA/SampleServer" (currently not supported)
// or "https://opcua.demo-this.com:51212/UA/SampleServer/"
// Instantiate the client object and hook events.
var client = new EasyUAClient();
client.DataChangeNotification += client_DataChangeNotification;
Console.WriteLine("Subscribing...");
client.SubscribeMultipleMonitoredItems(new[]
{
new EasyUAMonitoredItemArguments(null, endpointDescriptor,
"nsu=http://test.org/UA/Data/ ;i=10845", 1000),
new EasyUAMonitoredItemArguments(null, endpointDescriptor,
"nsu=http://test.org/UA/Data/ ;i=10853", 1000),
new EasyUAMonitoredItemArguments(null, endpointDescriptor,
"nsu=http://test.org/UA/Data/ ;i=10855", 1000)
});
Console.WriteLine("Getting monitored item arguments dictionary...");
EasyUAMonitoredItemArgumentsDictionary monitoredItemArgumentsDictionary =
client.GetMonitoredItemArgumentsDictionary();
foreach (EasyUAMonitoredItemArguments monitoredItemArguments in monitoredItemArgumentsDictionary.Values)
{
Console.WriteLine();
Console.WriteLine($"NodeDescriptor: {monitoredItemArguments.NodeDescriptor}");
Console.WriteLine($"SamplingInterval: {monitoredItemArguments.MonitoringParameters.SamplingInterval}");
Console.WriteLine($"PublishingInterval: {monitoredItemArguments.SubscriptionParameters.PublishingInterval}");
}
Console.WriteLine();
Console.WriteLine("Waiting for 5 seconds...");
System.Threading.Thread.Sleep(5 * 1000);
Console.WriteLine("Unsubscribing...");
client.UnsubscribeAllMonitoredItems();
Console.WriteLine("Waiting for 5 seconds...");
System.Threading.Thread.Sleep(5 * 1000);
Console.WriteLine("Finished.");
}
static void client_DataChangeNotification(object sender, EasyUADataChangeNotificationEventArgs e)
{
// Your code would do the processing here.
}
// Example output:
//
//Subscribing...
//Getting monitored item arguments dictionary...
//
//NodeDescriptor: NodeId="nsu=http://test.org/UA/Data/ ;i=10845"
//SamplingInterval: 1000
//PublishingInterval: 0
//
//NodeDescriptor: NodeId="nsu=http://test.org/UA/Data/ ;i=10853"
//SamplingInterval: 1000
//PublishingInterval: 0
//
//NodeDescriptor: NodeId="nsu=http://test.org/UA/Data/ ;i=10855"
//SamplingInterval: 1000
//PublishingInterval: 0
//
//Waiting for 5 seconds...
//Unsubscribing...
//Waiting for 5 seconds...
//Finished.
}
}
# This example shows how to obtain dictionary of parameters of all monitored item subscriptions.
#requires -Version 5.1
using namespace OpcLabs.EasyOpc.UA
using namespace OpcLabs.EasyOpc.UA.OperationModel
# The path below assumes that the current directory is [ProductDir]/Examples-NET/PowerShell/Windows .
Add-Type -Path "../../../Components/Opclabs.QuickOpc/net472/OpcLabs.EasyOpcUA.dll"
Add-Type -Path "../../../Components/Opclabs.QuickOpc/net472/OpcLabs.EasyOpcUAComponents.dll"
[UAEndpointDescriptor]$endpointDescriptor =
"opc.tcp://opcua.demo-this.com:51210/UA/SampleServer"
# or "http://opcua.demo-this.com:51211/UA/SampleServer" (currently not supported)
# or "https://opcua.demo-this.com:51212/UA/SampleServer/"
# Instantiate the client object.
$client = New-Object EasyUAClient
# Data change notification handler
Register-ObjectEvent -InputObject $client -EventName DataChangeNotification -Action {
# Your code would do the processing here.
}
Write-Host "Subscribing..."
$handleArray = $client.SubscribeMultipleMonitoredItems(@(
(New-Object UAMonitoredItemArguments(
(New-Object UAAttributeArguments($endpointDescriptor, [UANodeDescriptor]"nsu=http://test.org/UA/Data/ ;i=10845")),
1000)),
(New-Object UAMonitoredItemArguments(
(New-Object UAAttributeArguments($endpointDescriptor, [UANodeDescriptor]"nsu=http://test.org/UA/Data/ ;i=10853")),
1000)),
(New-Object UAMonitoredItemArguments(
(New-Object UAAttributeArguments($endpointDescriptor, [UANodeDescriptor]"nsu=http://test.org/UA/Data/ ;i=10855")),
1000))
))
Write-Host "Getting monitored item arguments dictionary..."
$monitoredItemArgumentsDictionary = $client.GetMonitoredItemArgumentsDictionary()
foreach ($monitoredItemArguments in $monitoredItemArgumentsDictionary.Values) {
Write-Host
Write-Host "NodeDescriptor: $($monitoredItemArguments.NodeDescriptor)"
Write-Host "SamplingInterval: $($monitoredItemArguments.MonitoringParameters.SamplingInterval)"
Write-Host "PublishingInterval: $($monitoredItemArguments.SubscriptionParameters.PublishingInterval)"
}
Write-Host
Write-Host "Waiting for 5 seconds..."
Start-Sleep -Seconds 5
Write-Host "Unsubscribing..."
$client.UnsubscribeAllMonitoredItems()
Write-Host "Waiting for 5 seconds..."
Start-Sleep -Seconds 5
Write-Host "Finished."
# Example output:
#
#Subscribing...
#Getting monitored item arguments dictionary...
#
#NodeDescriptor: NodeId="nsu=http://test.org/UA/Data/ ;i=10845"
#SamplingInterval: 1000
#PublishingInterval: 0
#
#NodeDescriptor: NodeId="nsu=http://test.org/UA/Data/ ;i=10853"
#SamplingInterval: 1000
#PublishingInterval: 0
#
#NodeDescriptor: NodeId="nsu=http://test.org/UA/Data/ ;i=10855"
#SamplingInterval: 1000
#PublishingInterval: 0
#
#Waiting for 5 seconds...
#Unsubscribing...
#Waiting for 5 seconds...
#Finished.
# This example shows how to obtain dictionary of parameters of all monitored item subscriptions.
# The QuickOPC package is needed. Install it using "pip install opclabs_quickopc".
import opclabs_quickopc
import time
# Import .NET namespaces.
from OpcLabs.EasyOpc.UA import *
from OpcLabs.EasyOpc.UA.OperationModel import *
def dataChangeNotification(sender, e):
# Your code would do the processing here.
pass
endpointDescriptor = UAEndpointDescriptor('opc.tcp://opcua.demo-this.com:51210/UA/SampleServer')
# or 'http://opcua.demo-this.com:51211/UA/SampleServer' (currently not supported)
# or 'https://opcua.demo-this.com:51212/UA/SampleServer/'
# Instantiate the client object and hook events.
client = EasyUAClient()
client.DataChangeNotification += dataChangeNotification
print('Subscribing...')
handleArray = client.SubscribeMultipleMonitoredItems([
EasyUAMonitoredItemArguments(
None,
UAEndpointDescriptor('opc.tcp://opcua.demo-this.com:51210/UA/SampleServer'),
UANodeDescriptor('nsu=http://test.org/UA/Data/ ;i=10845'),
UAMonitoringParameters(1000)),
EasyUAMonitoredItemArguments(
None,
UAEndpointDescriptor('opc.tcp://opcua.demo-this.com:51210/UA/SampleServer'),
UANodeDescriptor('nsu=http://test.org/UA/Data/ ;i=10853'),
UAMonitoringParameters(1000)),
EasyUAMonitoredItemArguments(
None,
UAEndpointDescriptor('opc.tcp://opcua.demo-this.com:51210/UA/SampleServer'),
UANodeDescriptor('nsu=http://test.org/UA/Data/ ;i=10855'),
UAMonitoringParameters(1000)),
])
print('Getting monitored item arguments dictionary...')
monitoredItemArgumentsDictionary = client.GetMonitoredItemArgumentsDictionary()
for monitoredItemArguments in monitoredItemArgumentsDictionary.Values:
print()
print('NodeDescriptor: ', monitoredItemArguments.NodeDescriptor, sep='')
print('SamplingInterval: ', monitoredItemArguments.MonitoringParameters.SamplingInterval, sep='')
print('PublishingInterval: ', monitoredItemArguments.SubscriptionParameters.PublishingInterval, sep='')
print()
print('Waiting for 5 seconds...')
time.sleep(5)
print('Unsubscribing...')
client.UnsubscribeAllMonitoredItems()
print('Waiting for 5 seconds...')
time.sleep(5)
print('Finished.')
' This example shows how to obtain dictionary of parameters of all monitored item subscriptions.
Imports OpcLabs.EasyOpc.UA
Imports OpcLabs.EasyOpc.UA.OperationModel
Namespace _EasyUAClient
Friend Class GetMonitoredItemArgumentsDictionary
Public Shared Sub Main1()
' Define which server we will work with.
Dim endpointDescriptor As UAEndpointDescriptor =
"opc.tcp://opcua.demo-this.com:51210/UA/SampleServer"
' or "http://opcua.demo-this.com:51211/UA/SampleServer" (currently not supported)
' or "https://opcua.demo-this.com:51212/UA/SampleServer/"
' Instantiate the client object and hook events
Dim client = New EasyUAClient()
AddHandler client.DataChangeNotification, AddressOf client_DataChangeNotification
Console.WriteLine("Subscribing...")
client.SubscribeMultipleMonitoredItems(New EasyUAMonitoredItemArguments() _
{ _
New EasyUAMonitoredItemArguments(Nothing, endpointDescriptor, "nsu=http://test.org/UA/Data/ ;i=10845", 1000), _
New EasyUAMonitoredItemArguments(Nothing, endpointDescriptor, "nsu=http://test.org/UA/Data/ ;i=10853", 1000), _
New EasyUAMonitoredItemArguments(Nothing, endpointDescriptor, "nsu=http://test.org/UA/Data/ ;i=10855", 1000) _
} _
)
Console.WriteLine("Getting monitored item arguments dictionary...")
Dim monitoredItemArgumentsDictionary As EasyUAMonitoredItemArgumentsDictionary = _
client.GetMonitoredItemArgumentsDictionary()
For Each monitoredItemArguments As EasyUAMonitoredItemArguments In monitoredItemArgumentsDictionary.Values
Console.WriteLine()
Console.WriteLine("NodeDescriptor: {0}", monitoredItemArguments.NodeDescriptor)
Console.WriteLine("SamplingInterval: {0}", monitoredItemArguments.MonitoringParameters.SamplingInterval)
Console.WriteLine("PublishingInterval: {0}", monitoredItemArguments.SubscriptionParameters.PublishingInterval)
Next monitoredItemArguments
Console.WriteLine("Waiting for 5 seconds...")
Threading.Thread.Sleep(5 * 1000)
Console.WriteLine("Unsubscribing...")
client.UnsubscribeAllMonitoredItems()
Console.WriteLine("Waiting for 5 seconds...")
Threading.Thread.Sleep(5 * 1000)
End Sub
Private Shared Sub client_DataChangeNotification(ByVal sender As Object, ByVal e As EasyUADataChangeNotificationEventArgs)
' Your code would do the processing here
End Sub
End Class
End Namespace