OPC Studio User's Guide and Reference
Examples - OPC Alarms&Events - Information about an event category

.NET

// This example shows information available about OPC event category.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .

using System;
using System.Diagnostics;
using OpcLabs.EasyOpc.AlarmsAndEvents;
using OpcLabs.EasyOpc.AlarmsAndEvents.AddressSpace;
using OpcLabs.EasyOpc.OperationModel;

namespace DocExamples.AlarmsAndEvents._AECategoryElement 
{ 
    class Properties 
    { 
        public static void Main1()
        {
            // Instantiate the client object.
            var client = new EasyAEClient();

            AECategoryElementCollection categoryElements;
            try
            {
                categoryElements = client.QueryEventCategories("", "OPCLabs.KitEventServer.2");
            }
            catch (OpcException opcException)
            {
                Console.WriteLine("*** Failure: {0}", opcException.GetBaseException().Message);
                return;
            }

            foreach (AECategoryElement categoryElement in categoryElements)
            {
                Debug.Assert(!(categoryElement is null));

                Console.WriteLine("Information about category {0}:", categoryElement);
                Console.WriteLine("    .CategoryId: {0}", categoryElement.CategoryId);
                Console.WriteLine("    .Description: {0}", categoryElement.Description);
                Console.WriteLine("    .ConditionElements:");
                if (!(categoryElement.ConditionElements.Keys is null))
                    foreach (string conditionKey in categoryElement.ConditionElements.Keys)
                        Console.WriteLine("        {0}", conditionKey);
                Console.WriteLine("    .AttributeElements:");
                if (!(categoryElement.AttributeElements.Keys is null))
                    foreach (long attributeKey in categoryElement.AttributeElements.Keys)
                        Console.WriteLine("        {0}", attributeKey);
            }
        }
    } 
}
# This example shows information available about OPC event category.
#
# 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 .
# The QuickOPC package is needed. Install it using "pip install opclabs_quickopc".
import opclabs_quickopc

# Import .NET namespaces.
from OpcLabs.EasyOpc.AlarmsAndEvents import *
from OpcLabs.EasyOpc.OperationModel import *


# Instantiate the client object.
client = EasyAEClient()

try:
    categoryElements = IEasyAEClientExtension.QueryEventCategories(client, '', 'OPCLabs.KitEventServer.2')
except OpcException as opcException:
    print('*** Failure: ' + opcException.GetBaseException().Message, sep='')
    exit()

# Display results
for categoryElement in categoryElements:
    assert categoryElement is not None
    print('Information about category ', categoryElement, sep='')
    print('    .CategoryId: ', categoryElement.CategoryId, sep='')
    print('    .Description: ', categoryElement.Description, sep='')
    print('    .ConditionElements:')
    if categoryElement.ConditionElements.Keys is not None:
        for conditionKey in categoryElement.ConditionElements.Keys:
            print('        ', conditionKey, sep='')
    print('    .AttributeElements:')
    if categoryElement.AttributeElements.Keys is not None:
        for attributeKey in categoryElement.AttributeElements.Keys:
            print('        ', attributeKey, sep='')
' This example shows information available about OPC event category.
'
' Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .

Imports OpcLabs.EasyOpc.AlarmsAndEvents
Imports OpcLabs.EasyOpc.AlarmsAndEvents.AddressSpace
Imports OpcLabs.EasyOpc.OperationModel

Namespace AlarmsAndEvents._AECategoryElement

    Friend Class Properties
        Public Shared Sub Main1()
            Dim client = New EasyAEClient()

            Dim categoryElements As AECategoryElementCollection
            Try
                categoryElements = client.QueryEventCategories("", "OPCLabs.KitEventServer.2")
            Catch opcException As OpcException
                Console.WriteLine("*** Failure: {0}", opcException.GetBaseException().Message)
                Exit Sub
            End Try

            For Each categoryElement As AECategoryElement In categoryElements
                Debug.Assert(categoryElement IsNot Nothing)

                Console.WriteLine("Information about category {0}:", categoryElement)
                Console.WriteLine("    .CategoryId: {0}", categoryElement.CategoryId)
                Console.WriteLine("    .Description: {0}", categoryElement.Description)
                Console.WriteLine("    .ConditionElements:")
                If categoryElement.ConditionElements.Keys IsNot Nothing Then
                    For Each conditionKey As String In categoryElement.ConditionElements.Keys
                        Console.WriteLine("        {0}", conditionKey)
                    Next conditionKey
                End If
                Console.WriteLine("    .AttributeElements:")
                If categoryElement.AttributeElements.Keys IsNot Nothing Then
                    For Each attributeKey As Long In categoryElement.AttributeElements.Keys
                        Console.WriteLine("        {0}", attributeKey)
                    Next attributeKey
                End If
            Next categoryElement
        End Sub
    End Class

End Namespace

COM

Rem This example shows information available about OPC event category.
Rem
Rem Find all latest examples here : https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .

Option Explicit

Const AEEventTypes_All = 7

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

Dim Client: Set Client = CreateObject("OpcLabs.EasyOpc.AlarmsAndEvents.EasyAEClient")
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 "Information about category " & CategoryElement & ":"
    With CategoryElement
        WScript.Echo Space(4) & ".CategoryId: " & .CategoryId
        WScript.Echo Space(4) & ".Description: " & .Description
        WScript.Echo Space(4) & ".ConditionElements:"
        Dim ConditionElement: For Each ConditionElement In .ConditionElements: WScript.Echo Space(8) & ConditionElement: Next
        WScript.Echo Space(4) & ".AttributeElements:"
        Dim AttributeElement: For Each AttributeElement In .AttributeElements: WScript.Echo Space(8) & AttributeElement: Next
    End With
Next

 

See Also

Conceptual