OPC Studio User's Guide and Reference
_EasyAEClient Interface
Members  Example 



OpcLabs.EasyOpcClassic Assembly > OpcLabs.EasyOpc.AlarmsAndEvents.ComTypes Namespace : _EasyAEClient Interface
Exposes OpcLabs.EasyOpc.AlarmsAndEvents.IEasyAEClient to COM clients.
Object Model
_EasyAEClient Interface_AliasProvider InterfaceEasyAEInstanceParameters ClassEasyAEAdaptableParameters ClassStringObjectDictionary Class
Syntax
'Declaration
 
<CLSCompliantAttribute(False)>
<ComVisibleAttribute(True)>
<GuidAttribute("F8A67414-B0C8-4F78-BFE5-968A7ED0E81E")>
<InterfaceTypeAttribute(ComInterfaceType.InterfaceIsDual)>
Public Interface _EasyAEClient 
'Usage
 
Dim instance As _EasyAEClient
[CLSCompliant(false)]
[ComVisible(true)]
[Guid("F8A67414-B0C8-4F78-BFE5-968A7ED0E81E")]
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
public interface _EasyAEClient 
[CLSCompliant(false)]
[ComVisible(true)]
[Guid("F8A67414-B0C8-4F78-BFE5-968A7ED0E81E")]
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
public interface class _EasyAEClient 
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.

Example

COM

// 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 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.

type
  TClientEventHandlers = class
    // Notification event handler
    procedure OnNotification(
      ASender: TObject;
      sender: OleVariant;
      const eventArgs: _EasyAENotificationEventArgs);
  end;

procedure TClientEventHandlers.OnNotification(
  ASender: TObject;
  sender: OleVariant;
  const eventArgs: _EasyAENotificationEventArgs);
begin
  if not eventArgs.Succeeded then
    WriteLn(Format('*** Failure: %s', [eventArgs.ErrorMessageBrief]));
  if eventArgs.EventData <> nil then
      WriteLn(eventArgs.EventData.Message);
end;

class procedure SubscribeEvents.Main;
var
  Client: TEasyAEClient;
  ClientEventHandlers: TClientEventHandlers;
  Handle: Integer;
  ServerDescriptor: _ServerDescriptor;
  State: OleVariant;
  SubscriptionParameters: _AESubscriptionParameters;
begin
  ServerDescriptor := CoServerDescriptor.Create;
  ServerDescriptor.ServerClass := 'OPCLabs.KitEventServer.2';

  // Instantiate the client object and hook events
  Client := TEasyAEClient.Create(nil);
  ClientEventHandlers := TClientEventHandlers.Create;
  Client.OnNotification := ClientEventHandlers.OnNotification;

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

  WriteLn('Processing event notifications for 1 minute...');
  PumpSleep(60*1000);

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

  WriteLn('Finished.');
  FreeAndNil(Client);
  FreeAndNil(ClientEventHandlers);
end;
// 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 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.

class DEasyEAClientEvents {
    function Notification($Sender, $E)
    {
        if (!($E->Succeeded))
        {
            printf("*** Failure: %s\n", $E->ErrorMessageBrief);
            Exit();
        }

        if (!is_null($E->EventData))
        {
            print $E->EventData->Message;
            print "\n";
        }
    }
}

$ServerDescriptor = new COM("OpcLabs.EasyOpc.ServerDescriptor");
$ServerDescriptor->ServerClass = "OPCLabs.KitEventServer.2";

$Client = new COM("OpcLabs.EasyOpc.AlarmsAndEvents.EasyAEClient");
$Events = new DEasyEAClientEvents();
com_event_sink($Client, $Events, "DEasyEAClientEvents");

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";
$startTime = time(); do { com_message_pump(1000); } while (time() < $startTime + 60);

print "Unsubscribing events...\n";
$Client->UnsubscribeEvents($handle);

print "Finished.\n";
REM This example shows how to subscribe to events and display the event message with each notification. It also shows how to
REM unsubscribe afterwards.
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 SubscribeEvents_Main_Command_Click()
    OutputText = ""
    
    Dim serverDescriptor As New serverDescriptor
    serverDescriptor.ServerClass = "OPCLabs.KitEventServer.2"
    
    ' Instantiate the client object and hook events
    Set Client1 = New EasyAEClient
    
    OutputText = OutputText & "Subscribing..." & vbCrLf
    Dim subscriptionParameters As New AESubscriptionParameters
    subscriptionParameters.notificationRate = 1000
    Dim handle
    Dim state
    handle = Client1.SubscribeEvents(serverDescriptor, subscriptionParameters, True, state)

    OutputText = OutputText & "Processing event notifications for 1 minute..." & vbCrLf
    Pause 60000

    OutputText = OutputText & "Unsubscribing events..." & vbCrLf
    Client1.UnsubscribeEvents handle

    OutputText = OutputText & "Waiting for 5 seconds..." & vbCrLf
    Pause 5000

    OutputText = OutputText & "Finished." & vbCrLf

    Set Client1 = Nothing
End Sub

Private Sub Client1_OnNotification(ByVal sender As Variant, ByVal eventArgs As EasyAENotificationEventArgs)
    If Not eventArgs.Succeeded Then
        OutputText = OutputText & eventArgs.ErrorMessageBrief & vbCrLf
        Exit Sub
    End If
    If Not eventArgs.EventData Is Nothing Then
        OutputText = OutputText & eventArgs.EventData.Message & vbCrLf
    End If
End Sub
Rem This example shows how to subscribe to events and display the event message with each notification. It also shows how to
Rem unsubscribe afterwards.
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")
WScript.ConnectObject Client, "Client_"

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..."
WScript.Sleep 60*1000

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

WScript.Echo "Finished."



Rem Notification event handler
Sub Client_Notification(Sender, e)
    If Not e.Succeeded Then
        WScript.Echo "*** Failure: " & e.ErrorMessageBrief
        Exit Sub
    End If

    If Not e.EventData Is Nothing Then WScript.Echo e.EventData.Message
End Sub
Rem This example shows how to work with Software Toolbox TOP Server 5 Alarms and Events.
Rem Use simdemo_WithA&E.opf configuration file and write a value above 1000 to Channel1.Device1.Tag1 or Channel1.Device1.Tag2.
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

Const AEEventTypes_All = 7

'Dim progID: progID = "Kepware.KEPServerEX_AE.V5"
Dim progID: progID = "SWToolbox.TOPServer_AE.V5"

Dim ServerDescriptor: Set ServerDescriptor = CreateObject("OpcLabs.EasyOpc.ServerDescriptor")
ServerDescriptor.ServerClass = progID

Dim Client: Set Client = CreateObject("OpcLabs.EasyOpc.AlarmsAndEvents.EasyAEClient")

Rem Browse for some areas and sources

On Error Resume Next
Dim AreaElements: Set AreaElements = Client.BrowseAreas("", progID, "")
If Err.Number <> 0 Then
    WScript.Echo "*** Failure: " & Err.Source & ": " & Err.Description
    WScript.Quit
End If
On Error Goto 0

Dim AreaElement: For Each AreaElement In AreaElements
    WScript.Echo "AreaElements(""" & AreaElement.Name & """):"
    With AreaElement
        WScript.Echo Space(4) & ".QualifiedName: " & .QualifiedName
    End With

    On Error Resume Next
    Dim SourceElements: Set SourceElements = Client.BrowseSources("", progID, AreaElement.QualifiedName)
    If Err.Number <> 0 Then
        WScript.Echo "*** Failure: " & Err.Source & ": " & Err.Description
        WScript.Quit
    End If
    On Error Goto 0

    Dim SourceElement: For Each SourceElement In SourceElements
        WScript.Echo Space(4) & "SourceElement(""" & SourceElement.Name & """):"
        With SourceElement
            WScript.Echo Space(8) & ".QualifiedName: " & .QualifiedName
        End With
    Next
Next

Rem Query for event categories

On Error Resume Next
Dim CategoryElements: Set CategoryElements = Client.QueryEventCategories(ServerDescriptor, AEEventTypes_All)
If Err.Number <> 0 Then
    WScript.Echo "*** Failure: " & Err.Source & ": " & Err.Description
    WScript.Quit
End If
On Error Goto 0

Dim CategoryElement: For Each CategoryElement In CategoryElements
    WScript.Echo "CategoryElements(" & CategoryElement.CategoryId & ").Description: " & CategoryElement.Description
Next

Rem Subscribe to events, wait, and unsubscribe

WScript.ConnectObject Client, "Client_"

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..."
WScript.Sleep 60*1000

Client.UnsubscribeEvents handle



Rem Notification event handler
Sub Client_Notification(Sender, e)
    On Error Resume Next
    WScript.Echo
    WScript.Echo "e.Exception.Message: " & e.Exception.Message
    WScript.Echo "e.Exception.Source: " & e.Exception.Source
    WScript.Echo "e.Exception.ErrorCode: " & e.Exception.ErrorCode
    WScript.Echo "e.Arguments.State: " & e.Arguments.State
    WScript.Echo "e.Arguments.ServerDescriptor.MachineName: " & e.Arguments.ServerDescriptor.MachineName
    WScript.Echo "e.Arguments.ServerDescriptor.ServerClass: " & e.Arguments.ServerDescriptor.ServerClass
    WScript.Echo "e.Arguments.SubscriptionParameters.Active: " & e.Arguments.SubscriptionParameters.Active
    WScript.Echo "e.Arguments.SubscriptionParameters.NotificationRate: " & e.Arguments.SubscriptionParameters.NotificationRate
    Rem IMPROVE: Display Arguments.SubscriptionParameters.Filter details
    WScript.Echo "e.Arguments.SubscriptionParameters.Filter: " & e.Arguments.SubscriptionParameters.Filter  
    Rem IMPROVE: Display Arguments.SubscriptionParameters.ReturnedAttributesByCategory details
    WScript.Echo "e.Arguments.SubscriptionParameters.ReturnedAttributesByCategory: " & e.Arguments.SubscriptionParameters.ReturnedAttributesByCategory
    WScript.Echo "e.Refresh: " & e.Refresh
    WScript.Echo "e.RefreshComplete: " & e.RefreshComplete
    WScript.Echo "e.EnabledChanged: " & e.EnabledChanged 
    WScript.Echo "e.ActiveChanged: " & e.ActiveChanged 
    WScript.Echo "e.AcknowledgedChanged: " & e.AcknowledgedChanged 
    WScript.Echo "e.QualityChanged: " & e.QualityChanged  
    WScript.Echo "e.SeverityChanged: " & e.SeverityChanged 
    WScript.Echo "e.SubconditionChanged: " & e.SubconditionChanged 
    WScript.Echo "e.MessageChanged: " & e.MessageChanged
    WScript.Echo "e.AttributeChanged: " & e.AttributeChanged 
    WScript.Echo "e.EventData.QualifiedSourceName: " & e.EventData.QualifiedSourceName 
    WScript.Echo "e.EventData.Time: " & e.EventData.Time
    WScript.Echo "e.EventData.TimeLocal: " & e.EventData.TimeLocal
    WScript.Echo "e.EventData.Message: " & e.EventData.Message
    WScript.Echo "e.EventData.EventType: " & e.EventData.EventType 
    WScript.Echo "e.EventData.CategoryId: " & e.EventData.CategoryId 
    WScript.Echo "e.EventData.Severity: " & e.EventData.Severity 
    Rem IMPROVE: Display EventData.AttributeValues details
    WScript.Echo "e.EventData.AttributeValues: " & e.EventData.AttributeValues 
    WScript.Echo "e.EventData.ConditionName: " & e.EventData.ConditionName 
    WScript.Echo "e.EventData.SubconditionName: " & e.EventData.SubconditionName 
    WScript.Echo "e.EventData.Enabled: " & e.EventData.Enabled 
    WScript.Echo "e.EventData.Active: " & e.EventData.Active 
    WScript.Echo "e.EventData.Acknowledged: " & e.EventData.Acknowledged 
    WScript.Echo "e.EventData.Quality: " & e.EventData.Quality 
    WScript.Echo "e.EventData.AcknowledgeRequired: " & e.EventData.AcknowledgeRequired 
    WScript.Echo "e.EventData.ActiveTime: " & e.EventData.ActiveTime
    WScript.Echo "e.EventData.ActiveTimeLocal: " & e.EventData.ActiveTimeLocal
    WScript.Echo "e.EventData.Cookie: " & e.EventData.Cookie 
    WScript.Echo "e.EventData.ActorId: " & e.EventData.ActorId 
End Sub
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