OPC Studio 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.

This is typically obtained by calling System.IServiceProvider.GetService(System.Type) on the OpcLabs.EasyOpc.UA.IEasyUAClient (EasyUAClient object) with the type of OpcLabs.EasyOpc.UA.Services.IEasyUAClientConnectionMonitoring as an argument.

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

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

This is typically obtained by calling System.IServiceProvider.GetService(System.Type) on the OpcLabs.EasyOpc.UA.IEasyUAClient (EasyUAClient object) with the type of OpcLabs.EasyOpc.UA.Services.IEasyUAClientConnectionMonitoring as an argument.

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

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 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
Rem This example shows how to monitor connections to and disconnections from the OPC UA server with event pull mechanism.
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

' 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