// This example shows how to subscribe to events and display the event message with each notification. It also shows how to
// unsubscribe afterwards.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// OPC client and subscriber examples in C# on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-CSharp .
// Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
// a commercial license in order to use Online Forums, and we reply to every post.
using System;
using System.Threading;
using OpcLabs.EasyOpc.AlarmsAndEvents;
using OpcLabs.EasyOpc.AlarmsAndEvents.OperationModel;
namespace DocExamples.AlarmsAndEvents._EasyAEClient
{
partial class SubscribeEvents
{
public static void Main1()
{
// Instantiate the client object.
using (var client = new EasyAEClient())
{
var eventHandler = new EasyAENotificationEventHandler(client_Notification);
client.Notification += eventHandler;
int handle = client.SubscribeEvents("", "OPCLabs.KitEventServer.2", 1000);
Console.WriteLine("Processing event notifications for 1 minute...");
Thread.Sleep(60 * 1000);
client.UnsubscribeEvents(handle);
}
}
// Notification event handler
static void client_Notification(object sender, EasyAENotificationEventArgs e)
{
if (!e.Succeeded)
{
Console.WriteLine("*** Failure: {0}", e.ErrorMessageBrief);
return;
}
if (!(e.EventData is null))
Console.WriteLine(e.EventData.Message);
}
}
}
# This example shows how to subscribe to events and display the event message with each notification. It also shows how to
# unsubscribe afterwards.
#
# Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
# OPC client and subscriber examples in PowerShell on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-PowerShell .
# Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
# a commercial license in order to use Online Forums, and we reply to every post.
#requires -Version 5.1
using namespace OpcLabs.EasyOpc.AlarmsAndEvents
# 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 EasyAEClient
# Notification event handler
Register-ObjectEvent -InputObject $client -EventName Notification -Action {
if (-not $EventArgs.Succeeded) {
Write-Host "*** Failure: $($EventArgs.ErrorMessageBrief)"
#return
}
if ($EventArgs.EventData -ne $null) {
Write-Host $EventArgs.EventData.Message
}
}
Write-Host "Subscribing events..."
$handle = [IEasyAEClientExtension]::SubscribeEvents($client, "", "OPCLabs.KitEventServer.2", 1000)
Write-Host "Processing event notifications for 1 minute..."
$stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
while ($stopwatch.Elapsed.TotalSeconds -lt 60) {
Start-Sleep -Seconds 1
}
Write-Host "Unsubscribing events..."
$client.UnsubscribeEvents($handle)
Write-Host "Finished."
' This example shows how to subscribe to events and display the event message with each notification. It also shows how to
' unsubscribe afterwards.
'
' Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
' OPC client and subscriber examples in VB.NET on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-VBNET .
' Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
' a commercial license in order to use Online Forums, and we reply to every post.
Imports System.Threading
Imports OpcLabs.EasyOpc.AlarmsAndEvents
Imports OpcLabs.EasyOpc.AlarmsAndEvents.OperationModel
Namespace AlarmsAndEvents._EasyAEClient
Partial Friend Class SubscribeEvents
Public Shared Sub Main1()
Using client = New EasyAEClient()
Dim eventHandler = New EasyAENotificationEventHandler(AddressOf client_Notification)
AddHandler client.Notification, eventHandler
Dim handle As Integer = client.SubscribeEvents("", "OPCLabs.KitEventServer.2", 1000)
Console.WriteLine("Processing event notifications for 1 minute...")
Thread.Sleep(60 * 1000)
client.UnsubscribeEvents(handle)
End Using
End Sub
' Notification event handler
Private Shared Sub client_Notification(ByVal sender As Object, ByVal e As EasyAENotificationEventArgs)
If Not e.Succeeded Then
Console.WriteLine("*** Failure: {0}", e.ErrorMessageBrief)
Exit Sub
End If
If e.EventData IsNot Nothing Then
Console.WriteLine(e.EventData.Message)
End If
End Sub
End Class
End Namespace
# This example shows how to subscribe to events and display the event message with each notification. It also shows how
# to unsubscribe afterwards.
#
# Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
# OPC client and subscriber examples in Python on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-Python .
# Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
# a commercial license in order to use Online Forums, and we reply to every post.
# 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.AlarmsAndEvents import *
# Notification event handler
def notification(sender, e):
if not e.Succeeded:
print('*** Failure: ', e.ErrorMessageBrief, sep='')
return
else:
if e.EventData is not None:
print(e.EventData.Message)
# Instantiate the client object
client = EasyAEClient()
client.Notification += notification
print('Subscribing events...')
handle = IEasyAEClientExtension.SubscribeEvents(client, '', 'OPCLabs.KitEventServer.2', 1000)
print('Processing event notifications for 1 minute...')
time.sleep(60)
print('Unsubscribing events...')
client.UnsubscribeAllEvents()
client.Notification -= notification
print('Finished.')