// This example shows how to subscribe to events and obtain the notification events by pulling them.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// OPC client and subscriber examples in PHP on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-PHP .
// 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.
$ServerDescriptor = new COM("OpcLabs.EasyOpc.ServerDescriptor");
$ServerDescriptor->ServerClass = "OPCLabs.KitEventServer.2";
$Client = new COM("OpcLabs.EasyOpc.AlarmsAndEvents.EasyAEClient");
// In order to use event pull, you must set a non-zero queue capacity upfront.
$Client->PullNotificationQueueCapacity = 1000;
print "Subscribing events...\n";
$SubscriptionParameters = new COM("OpcLabs.EasyOpc.AlarmsAndEvents.AESubscriptionParameters");
$SubscriptionParameters->NotificationRate = 1000;
$handle = $Client->SubscribeEvents($ServerDescriptor, $SubscriptionParameters, TRUE, NULL);
print "Processing event notifications for 1 minute...\n";
$endTime = time() + 60;
do {
$EventArgs = $Client->PullNotification(2*1000);
if (!is_null($EventArgs)) {
// Handle the notification event
print $EventArgs->ToString();
print "\n";
}
} while (time() < $endTime);
print "Unsubscribing events...\n";
$Client->UnsubscribeEvents($handle);
print "Finished.\n";
REM This example shows how to subscribe to events and obtain the notification events by pulling them.
REM
REM Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
REM OPC client and subscriber examples in Visual Basic on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-VB .
REM Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
REM a commercial license in order to use Online Forums, and we reply to every post.
Private Sub PullNotification_Main_Command_Click()
OutputText = ""
Dim eventArgs As EasyAENotificationEventArgs
Dim serverDescriptor As New serverDescriptor
serverDescriptor.ServerClass = "OPCLabs.KitEventServer.2"
' Instantiate the client object
Dim client As New EasyAEClient
' In order to use event pull, you must set a non-zero queue capacity upfront.
client.PullNotificationQueueCapacity = 1000
OutputText = OutputText & "Subscribing events..." & vbCrLf
Dim subscriptionParameters As New AESubscriptionParameters
subscriptionParameters.notificationRate = 1000
Dim handle
Dim state
handle = client.SubscribeEvents(serverDescriptor, subscriptionParameters, True, state)
OutputText = OutputText & "Processing event notifications for 1 minute..." & vbCrLf
Dim endTick As Long
endTick = GetTickCount + 60000
While GetTickCount < endTick
Set eventArgs = client.PullNotification(2 * 1000)
If Not eventArgs Is Nothing Then
' Handle the notification event
OutputText = OutputText & eventArgs & vbCrLf
End If
Wend
OutputText = OutputText & "Unsubscribing events..." & vbCrLf
client.UnsubscribeEvents handle
OutputText = OutputText & "Finished." & vbCrLf
End Sub
# This example shows how to subscribe to events and obtain the notification events by pulling them.
#
# 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 *
# Instantiate the client object
client = EasyAEClient()
# In order to use event pull, you must set a non-zero queue capacity upfront.
client.PullNotificationQueueCapacity = 1000
print('Subscribing events...')
handle = IEasyAEClientExtension.SubscribeEvents(client, '', 'OPCLabs.KitEventServer.2', 1000)
print('Processing event notifications for 1 minute...')
endTime = time.time() + 60
while time.time() < endTime:
eventArgs = IEasyAEClientExtension.PullNotification(client, 2*1000)
if eventArgs is not None:
# Handle the notification event
print(eventArgs)
print('Unsubscribing events...')
client.UnsubscribeAllEvents()
print('Finished.')