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



OpcLabs.EasyOpcClassic Assembly > OpcLabs.EasyOpc.AlarmsAndEvents.ComTypes Namespace > _EasyAEClient Interface : GetConditionState Method
The OPC server involved in the operation.

Because the OpcLabs.EasyOpc.ServerDescriptor has an implicit conversion from System.Guid, System.String and OpcLabs.EasyOpc.ServerElement, in languages that support implicit conversion operators (such as C# or VB.NET), you can simply use a GUID (representing the CLSID of the server), a string (representing the so-called OPC server descriptor string, such as a ProgID or the URL of the server), or a OpcLabs.EasyOpc.ServerElement object (result from OPC browsing), in place of this parameter, and the corresponding OPC server descriptor will be constructed automatically. When the implicit conversion operators are not supported (such as with Python.NET), you can use the OpcLabs.EasyOpc.ServerDescriptor.FromGuid, OpcLabs.EasyOpc.ServerDescriptor.FromString or OpcLabs.EasyOpc.ServerDescriptor.FromServerElement static method instead.

The value of this parameter cannot be null (Nothing in Visual Basic).

Contains fully qualified source name, as returned by browsing. The state of the condition instance associated with this source is returned.

Because the OpcLabs.EasyOpc.AlarmsAndEvents.AENodeDescriptor has an implicit conversion from System.String and OpcLabs.EasyOpc.AlarmsAndEvents.AddressSpace.AENodeElement, in languages that support implicit conversion operators (such as C# or VB.NET), you can simply use a string (representing the qualified name of the node), or a OpcLabs.EasyOpc.AlarmsAndEvents.AddressSpace.AENodeElement object (result from OPC browsing), in place of this parameter, and the corresponding OPC A&E node descriptor will be constructed automatically. When the implicit conversion operators are not supported (such as with Python.NET), you can use the OpcLabs.EasyOpc.AlarmsAndEvents.AENodeDescriptor.FromString or OpcLabs.EasyOpc.AlarmsAndEvents.AENodeDescriptor.FromAENodeElement static method instead.

The value of this parameter cannot be null (Nothing in Visual Basic).

A condition name, as returned by querying. The state of this condition is returned.

The value of this parameter can be null (Nothing in Visual Basic).

Specifies the event attributes to be returned.

The value of this parameter cannot be null (Nothing in Visual Basic).

Returns the current state information for the condition instance corresponding to the source and condition name, passing in a server descriptor. Also allows to retrieve specified event attributes.
Syntax
'Declaration
 
<NotNullAttribute()>
Function GetConditionState( _
   ByVal serverDescriptor As Object, _
   ByVal sourceDescriptor As Object, _
   ByVal conditionName As String, _
   ByVal attributes As Object _
) As AEConditionState
'Usage
 
Dim instance As _EasyAEClient
Dim serverDescriptor As Object
Dim sourceDescriptor As Object
Dim conditionName As String
Dim attributes As Object
Dim value As AEConditionState
 
value = instance.GetConditionState(serverDescriptor, sourceDescriptor, conditionName, attributes)

Parameters

serverDescriptor
The OPC server involved in the operation.

Because the OpcLabs.EasyOpc.ServerDescriptor has an implicit conversion from System.Guid, System.String and OpcLabs.EasyOpc.ServerElement, in languages that support implicit conversion operators (such as C# or VB.NET), you can simply use a GUID (representing the CLSID of the server), a string (representing the so-called OPC server descriptor string, such as a ProgID or the URL of the server), or a OpcLabs.EasyOpc.ServerElement object (result from OPC browsing), in place of this parameter, and the corresponding OPC server descriptor will be constructed automatically. When the implicit conversion operators are not supported (such as with Python.NET), you can use the OpcLabs.EasyOpc.ServerDescriptor.FromGuid, OpcLabs.EasyOpc.ServerDescriptor.FromString or OpcLabs.EasyOpc.ServerDescriptor.FromServerElement static method instead.

The value of this parameter cannot be null (Nothing in Visual Basic).

sourceDescriptor
Contains fully qualified source name, as returned by browsing. The state of the condition instance associated with this source is returned.

Because the OpcLabs.EasyOpc.AlarmsAndEvents.AENodeDescriptor has an implicit conversion from System.String and OpcLabs.EasyOpc.AlarmsAndEvents.AddressSpace.AENodeElement, in languages that support implicit conversion operators (such as C# or VB.NET), you can simply use a string (representing the qualified name of the node), or a OpcLabs.EasyOpc.AlarmsAndEvents.AddressSpace.AENodeElement object (result from OPC browsing), in place of this parameter, and the corresponding OPC A&E node descriptor will be constructed automatically. When the implicit conversion operators are not supported (such as with Python.NET), you can use the OpcLabs.EasyOpc.AlarmsAndEvents.AENodeDescriptor.FromString or OpcLabs.EasyOpc.AlarmsAndEvents.AENodeDescriptor.FromAENodeElement static method instead.

The value of this parameter cannot be null (Nothing in Visual Basic).

conditionName
A condition name, as returned by querying. The state of this condition is returned.

The value of this parameter can be null (Nothing in Visual Basic).

attributes
Specifies the event attributes to be returned.

The value of this parameter cannot be null (Nothing in Visual Basic).

Return Value

If successful, the function returns a OpcLabs.EasyOpc.AlarmsAndEvents.AEConditionState object. The object contains information about the state of the condition.

This method never returns 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.

The OPC "Classic" (or OPC XML-DA) operation has failed. This operation exception in uniformly used to allow common handling of various kinds of errors. The System.Exception.InnerException always contains information about the actual error cause.

This is an operation error that depends on factors external to your program, and thus cannot be always avoided. Your code must handle it appropriately.

Remarks

Some servers may not maintain sufficient condition state information to fully implement this method.

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.

The server(s) can be local or can be remotely accessed via DCOM.

Example

COM

# This example shows how to obtain current state information for the condition instance corresponding to a Source and 
# certain ConditionName.
#
# 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
from pywintypes import com_error

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

sourceDescriptor = win32com.client.Dispatch('OpcLabs.EasyOpc.AlarmsAndEvents.AENodeDescriptor')
sourceDescriptor.QualifiedName = "Simulation.ConditionState1"

# Instantiate the client object
client = win32com.client.Dispatch('OpcLabs.EasyOpc.AlarmsAndEvents.EasyAEClient') 

print('Getting condition state...')
try:
    conditionState = client.GetConditionState(serverDescriptor, sourceDescriptor, 'Simulated', [])
except com_error as e:
    print('*** Failure: ' + e.args[2][1] + ': ' + e.args[2][2])
    exit()

print('ConditionState:')
print('    .ActiveSubcondition: ', conditionState.ActiveSubcondition)
print('    .Enabled: ', conditionState.Enabled)
print('    .Active: ', conditionState.Active)
print('    .Acknowledged: ', conditionState.Acknowledged)
print('    .Quality: ', conditionState.Quality)
# Note that IAEConditionState has many more properties

print()
print('Finished.')
Rem This example shows how to obtain current state information for the condition instance corresponding to a Source and 
Rem certain ConditionName.
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 SourceDescriptor: Set SourceDescriptor = CreateObject("OpcLabs.EasyOpc.AlarmsAndEvents.AENodeDescriptor")
SourceDescriptor.QualifiedName = "Simulation.ConditionState1"

Dim Client: Set Client = CreateObject("OpcLabs.EasyOpc.AlarmsAndEvents.EasyAEClient")
On Error Resume Next
Dim ConditionState: Set ConditionState = Client.GetConditionState(ServerDescriptor, SourceDescriptor, "Simulated", Array())
If Err.Number <> 0 Then
    WScript.Echo "*** Failure: " & Err.Source & ": " & Err.Description
    WScript.Quit
End If
On Error Goto 0

WScript.Echo "ConditionState:"
With ConditionState
    WScript.Echo Space(4) & ".ActiveSubcondition: " & .ActiveSubcondition
    WScript.Echo Space(4) & ".Enabled: " & .Enabled
    WScript.Echo Space(4) & ".Active: " & .Active
    WScript.Echo Space(4) & ".Acknowledged: " & .Acknowledged
    WScript.Echo Space(4) & ".Quality: " & .Quality
    Rem Note that IAEConditionState has many more properties
End With
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