// This example shows how to display specific fields of incoming events that are derived from base event type.
using System;
using OpcLabs.EasyOpc.UA;
using OpcLabs.EasyOpc.UA.AddressSpace.Standard;
using OpcLabs.EasyOpc.UA.AlarmsAndConditions;
using OpcLabs.EasyOpc.UA.OperationModel;
namespace UADocExamples.AlarmsAndConditions
{
class BaseEvent
{
public static void Main1()
{
UAEndpointDescriptor endpointDescriptor =
"opc.tcp://opcua.demo-this.com:62544/Quickstarts/AlarmConditionServer";
// Instantiate the client object and hook events.
var client = new EasyUAClient();
client.EventNotification += client_EventNotification;
Console.WriteLine("Subscribing...");
client.SubscribeEvent(endpointDescriptor, UAObjectIds.Server, 1000);
Console.WriteLine("Processing event notifications for 30 seconds...");
System.Threading.Thread.Sleep(30 * 1000);
Console.WriteLine("Unsubscribing...");
client.UnsubscribeAllMonitoredItems();
Console.WriteLine("Waiting for 5 seconds...");
System.Threading.Thread.Sleep(5 * 1000);
Console.WriteLine("Finished.");
}
static void client_EventNotification(object sender, EasyUAEventNotificationEventArgs e)
{
Console.WriteLine();
// Display the event.
if (e.EventData is null)
{
Console.WriteLine(e);
return;
}
UABaseEventObject baseEventObject = e.EventData.BaseEvent;
Console.WriteLine($"Source name: {baseEventObject.SourceName}");
Console.WriteLine($"Message: {baseEventObject.Message}");
Console.WriteLine($"Severity: {baseEventObject.Severity}");
}
}
}
# This example shows how to display specific fields of incoming events that are derived from base event type.
#requires -Version 5.1
using namespace OpcLabs.EasyOpc.UA
using namespace OpcLabs.EasyOpc.UA.AddressSpace
using namespace OpcLabs.EasyOpc.UA.AddressSpace.Standard
# 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"
# Define which server we will work with.
[UAEndpointDescriptor]$endpointDescriptor = "opc.tcp://opcua.demo-this.com:62544/Quickstarts/AlarmConditionServer"
# Instantiate the client object.
$client = New-Object EasyUAClient
# Event notification handler
Register-ObjectEvent -InputObject $client -EventName EventNotification -Action {
Write-Host
# Display the event.
if ($EventArgs.EventData -eq $null) {
Write-Host $EventArgs
return
}
$baseEventObject = $EventArgs.EventData.BaseEvent
Write-Host "Source name: $($baseEventObject.SourceName)"
Write-Host "Message: $($baseEventObject.Message)"
Write-Host "Severity: $($baseEventObject.Severity)"
}
Write-Host "Subscribing..."
[IEasyUAClientExtension]::SubscribeEvent($client, $endpointDescriptor, [UAObjectIds]::Server, 1000)
Write-Host "Processing event notifications for 30 seconds..."
$stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
while ($stopwatch.Elapsed.TotalSeconds -lt 30) {
Start-Sleep -Seconds 1
}
Write-Host "Unsubscribing..."
$client.UnsubscribeAllMonitoredItems()
Write-Host "Waiting for 5 seconds..."
Start-Sleep -Seconds 5
Write-Host "Finished."
# This example shows how to display specific fields of incoming events that are derived from base event type.
# 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.AddressSpace.Standard import *
from OpcLabs.EasyOpc.UA.AlarmsAndConditions import *
from OpcLabs.EasyOpc.UA.OperationModel import *
def eventNotification(sender, eventArgs):
print()
# Display the event.
if eventArgs.EventData is None:
print(eventArgs)
return
baseEventObject = eventArgs.EventData.BaseEvent
print('Source name: ', baseEventObject.SourceName, sep='')
print('Message: ', baseEventObject.Message, sep='')
print('Severity: ', baseEventObject.Severity, sep='')
# Define which server we will work with.
endpointDescriptor = UAEndpointDescriptor('opc.tcp://opcua.demo-this.com:62544/Quickstarts/AlarmConditionServer')
# Instantiate the client object and hook events.
client = EasyUAClient()
client.EventNotification += eventNotification
print('Subscribing...')
IEasyUAClientExtension.SubscribeEvent(
client,
endpointDescriptor,
UANodeDescriptor(UAObjectIds.Server),
1000)
print('Processing event notifications for 30 seconds...')
time.sleep(30)
print('Unsubscribing...')
client.UnsubscribeAllMonitoredItems()
print('Waiting for 5 seconds...')
time.sleep(5)
print('Finished.')
' This example shows how to display specific fields of incoming events that are derived from base event type.
Imports OpcLabs.EasyOpc.UA
Imports OpcLabs.EasyOpc.UA.AddressSpace.Standard
Imports OpcLabs.EasyOpc.UA.OperationModel
Namespace AlarmsAndConditions
Friend Class BaseEvent
Public Shared Sub Main1()
' Instantiate the client object and hook events
Dim client = New EasyUAClient()
AddHandler client.EventNotification, AddressOf client_EventNotification
Console.WriteLine("Subscribing...")
client.SubscribeEvent( _
"opc.tcp://opcua.demo-this.com:62544/Quickstarts/AlarmConditionServer", _
UAObjectIds.Server, _
1000)
Console.WriteLine("Processing event notifications for 30 seconds...")
Threading.Thread.Sleep(30 * 1000)
Console.WriteLine("Unsubscribing...")
client.UnsubscribeAllMonitoredItems()
Console.WriteLine("Waiting for 5 seconds...")
Threading.Thread.Sleep(5 * 1000)
End Sub
Private Shared Sub client_EventNotification(ByVal sender As Object, ByVal e As EasyUAEventNotificationEventArgs)
Console.WriteLine()
' Display the event
If e.EventData Is Nothing Then
Console.WriteLine(e)
Exit Sub
End If
Dim baseEventObject = e.EventData.BaseEvent
Console.WriteLine("Source name: {0}", baseEventObject.SourceName)
Console.WriteLine("Message: {0}", baseEventObject.Message)
Console.WriteLine("Severity: {0}", baseEventObject.Severity)
End Sub
End Class
End Namespace