OPC Studio User's Guide and Reference
PullNotification Method (_EasyAEClient)
Example 



OpcLabs.EasyOpcClassic Assembly > OpcLabs.EasyOpc.AlarmsAndEvents.ComTypes Namespace > _EasyAEClient Interface : PullNotification Method
The number of milliseconds to wait, or System.Threading.Timeout.Infinite (-1) to wait indefinitely.

Valid values of this parameter are in the range from -1 to 2147483647 (Int32.MaxValue).

Attempts to pull an OPC event subscribed to by the OpcLabs.EasyOpc.AlarmsAndEvents.IEasyAEClient.SubscribeEvents method. Returns refresh or standard event notifications.
Syntax
'Declaration
 
<CanBeNullAttribute()>
Function PullNotification( _
   ByVal millisecondsTimeout As Integer _
) As EasyAENotificationEventArgs
'Usage
 
Dim instance As _EasyAEClient
Dim millisecondsTimeout As Integer
Dim value As EasyAENotificationEventArgs
 
value = instance.PullNotification(millisecondsTimeout)
[CanBeNull()]
EasyAENotificationEventArgs PullNotification( 
   int millisecondsTimeout
)
[CanBeNull()]
EasyAENotificationEventArgs^ PullNotification( 
   int millisecondsTimeout
) 

Parameters

millisecondsTimeout
The number of milliseconds to wait, or System.Threading.Timeout.Infinite (-1) to wait indefinitely.

Valid values of this parameter are in the range from -1 to 2147483647 (Int32.MaxValue).

Return Value

The event arguments, or null if no event is available within the specified time.

This method can return null (Nothing in Visual Basic).

Exceptions
ExceptionDescription

A null reference (Nothing in Visual Basic) is passed to a method that does not accept it as a valid argument.

This is a usage error, i.e. it will never occur (the exception will not be thrown) in a correctly written program. Your code should not catch this exception.

The value of an argument is outside the allowable range of values as defined by the invoked method.

This is a usage error, i.e. it will never occur (the exception will not be thrown) in a correctly written program. Your code should not catch this exception.

Remarks

This member or type is for use from COM. It is not meant to be used from .NET or Python. Refer to the corresponding .NET member or type instead, if you are developing in .NET or Python.

This is an extension method (info: C#, VB.NET). In languages that have support for extensions methods (such as C# and VB.NET), you can use the extension method as if it were a regular method on the object that is its first parameter. In other languages (such as with Python.NET), you will call the extension as a static method, and pass it the object on which it acts as its first parameter.

Example

COM

// 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 Object Pascal (Delphi) on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-OP .
// 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.

class procedure PullNotification.Main;
var
  Client: OpcLabs_EasyOpcClassic_TLB._EasyAEClient;
  EndTick: Cardinal;
  EventArgs: _EasyAENotificationEventArgs;
  Handle: Integer;
  ServerDescriptor: _ServerDescriptor;
  State: OleVariant;
  SubscriptionParameters: _AESubscriptionParameters;
begin
  ServerDescriptor := CoServerDescriptor.Create;
  ServerDescriptor.ServerClass := 'OPCLabs.KitEventServer.2';

  // Instantiate the client object
  Client := CoEasyAEClient.Create;
  // In order to use event pull, you must set a non-zero queue capacity upfront.
  Client.PullNotificationQueueCapacity := 1000;

  WriteLn('Subscribing events...');
  SubscriptionParameters := CoAESubscriptionParameters.Create;
  SubscriptionParameters.NotificationRate := 1000;
  Handle := Client.SubscribeEvents(ServerDescriptor, SubscriptionParameters, true, State);

  WriteLn('Processing event notifications for 1 minute...');
  EndTick := Ticks + 60*1000;
  while Ticks < EndTick do
  begin
    EventArgs := Client.PullNotification(2*1000);
    if EventArgs <> nil then
      // Handle the notification event
      WriteLn(EventArgs.ToString);
  end;

  WriteLn('Unsubscribing events...');
  Client.UnsubscribeEvents(Handle);

  WriteLn('Finished.');
end;
// 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";
# This example shows how to subscribe to events and obtain the notification events by pulling them.
#
# The Python for Windows (pywin32) extensions package is needed. Install it using "pip install pypiwin32".
# CAUTION: We now recommend using Python.NET package instead. Full set of examples with Python.NET is available!
#
# Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
import time
import win32com.client

serverDescriptor = win32com.client.Dispatch('OpcLabs.EasyOpc.ServerDescriptor')
serverDescriptor.UrlString = 'opcae://localhost/OPCLabs.KitEventServer.2'
#serverDescriptor.ServerClass = 'OPCLabs.KitEventServer.2'

# Instantiate the client object
client = win32com.client.Dispatch('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...')
subscriptionParameters = win32com.client.Dispatch('OpcLabs.EasyOpc.AlarmsAndEvents.AESubscriptionParameters')
subscriptionParameters.NotificationRate = 1000
handle = client.SubscribeEvents(serverDescriptor, subscriptionParameters, True, None)

print('Processing event notifications for 1 minute...')
endTime = time.time() + 60
while time.time() < endTime:
    eventArgs = client.PullNotification(2*1000)
    if eventArgs is not None:
        # Handle the notification event
        print(eventArgs)

print('Unsubscribing events...')
client.UnsubscribeAllEvents()

print('Finished.')
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
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 VBScript on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-VBScript .
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.

Option Explicit

Dim ServerDescriptor: Set ServerDescriptor = CreateObject("OpcLabs.EasyOpc.ServerDescriptor")
ServerDescriptor.ServerClass = "OPCLabs.KitEventServer.2"

Dim Client: Set Client = CreateObject("OpcLabs.EasyOpc.AlarmsAndEvents.EasyAEClient")
' In order to use event pull, you must set a non-zero queue capacity upfront.
Client.PullNotificationQueueCapacity = 1000

WScript.Echo "Subscribing events..."
Dim SubscriptionParameters: Set SubscriptionParameters = CreateObject("OpcLabs.EasyOpc.AlarmsAndEvents.AESubscriptionParameters")
SubscriptionParameters.NotificationRate = 1000
Dim handle: handle = Client.SubscribeEvents(ServerDescriptor, SubscriptionParameters, True, Nothing)

WScript.Echo "Processing event notifications for 1 minute..."
Dim endTime: endTime = Now() + 60*(1/24/60/60)
Do
    Dim EventArgs: Set EventArgs = Client.PullNotification(2*1000)
    If Not (EventArgs Is Nothing) Then
        ' Handle the notification event
        WScript.Echo EventArgs
    End If    
Loop While Now() < endTime

WScript.Echo "Unsubscribing events..."
Client.UnsubscribeEvents handle

WScript.Echo "Finished."
Requirements

Target Platforms: .NET Framework: Windows 10 (selected versions), Windows 11 (selected versions), Windows Server 2016, Windows Server 2022; .NET: Linux, macOS, Microsoft Windows

See Also