QuickOPC User's Guide and Reference
PullServerConditionChanged Method (IEasyUAClientConnectionMonitoringExtension)
Example 



OpcLabs.EasyOpcUA Assembly > OpcLabs.EasyOpc.UA.Services.Extensions Namespace > IEasyUAClientConnectionMonitoringExtension Class : PullServerConditionChanged Method
The client connection monitoring object that will perform the operation.
The number of milliseconds to wait, or System.Threading.Timeout.Infinite (-1) to wait indefinitely.
Attempts to pull an OPC server condition changed event.
Syntax
'Declaration
 
<ExtensionAttribute()>
<CanBeNullAttribute()>
Public Shared Function PullServerConditionChanged( _
   ByVal clientConnectionMonitoring As IEasyUAClientConnectionMonitoring, _
   ByVal millisecondsTimeout As Integer _
) As EasyUAServerConditionChangedEventArgs
'Usage
 
Dim clientConnectionMonitoring As IEasyUAClientConnectionMonitoring
Dim millisecondsTimeout As Integer
Dim value As EasyUAServerConditionChangedEventArgs
 
value = IEasyUAClientConnectionMonitoringExtension.PullServerConditionChanged(clientConnectionMonitoring, millisecondsTimeout)

Parameters

clientConnectionMonitoring
The client connection monitoring object that will perform the operation.
millisecondsTimeout
The number of milliseconds to wait, or System.Threading.Timeout.Infinite (-1) to wait indefinitely.

Return Value

The event arguments, or null if no event is available within the specified time.
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.

Example

COM

Rem This example shows how to monitor connections to and disconnections from the OPC UA server with event pull mechanism.

Option Explicit

' Instantiate the client object.
Dim Client: Set Client = CreateObject("OpcLabs.EasyOpc.UA.EasyUAClient")

' Obtain the client connection monitoring service.
Dim ClientConnectionMonitoring: Set ClientConnectionMonitoring = Client.GetServiceByName("OpcLabs.EasyOpc.UA.Services.IEasyUAClientConnectionMonitoring, OpcLabs.EasyOpcUA")
If ClientConnectionMonitoring Is Nothing Then
    WScript.Echo "The client connection monitoring service is not available."
    WScript.Quit
End If

' In order to use event pull, you must set a non-zero queue capacity upfront.
ClientConnectionMonitoring.PullServerConditionChangedQueueCapacity = 1000

WScript.Echo "Reading (1)"
' The first read will cause a connection to the server.
Dim AttributeData1: Set AttributeData1 = Client.Read("opc.tcp://opcua.demo-this.com:51210/UA/SampleServer", "nsu=http://test.org/UA/Data/ ;i=10853")
WScript.Echo AttributeData1

WScript.Echo "Reading (2)"
' The second read, because it closely follows the first one, will reuse the connection that is already open.
Dim AttributeData2: Set AttributeData2 = Client.Read("opc.tcp://opcua.demo-this.com:51210/UA/SampleServer", "nsu=http://test.org/UA/Data/ ;i=10853")
WScript.Echo AttributeData2

WScript.Echo "Processing server condition changed events for 10 seconds..."
' Because we only started the processing after we have made the reads, there are now events related to opening the 
' connection already in the queue, and they will be consumed first.
' Since the connection is now not used for some time, it will be closed.
Dim endTime: endTime = Now() + 10*(1/24/60/60)
Do
    Dim EventArgs: Set EventArgs = ClientConnectionMonitoring.PullServerConditionChanged(2*1000)
    If Not (EventArgs Is Nothing) Then
        ' Handle the server condition changed event.
        WScript.Echo EventArgs
    End If    
Loop While Now() < endTime

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