'Declaration
Event DataChangeNotification As EasyUADataChangeNotificationEventHandler
'Usage
Dim instance As IEasyUAClient Dim handler As EasyUADataChangeNotificationEventHandler AddHandler instance.DataChangeNotification, handler
event EasyUADataChangeNotificationEventHandler DataChangeNotification
event EasyUADataChangeNotificationEventHandler^ DataChangeNotification
Event Data
The event handler receives an argument of type EasyUADataChangeNotificationEventArgs containing data related to this event. The following EasyUADataChangeNotificationEventArgs properties provide information specific to this event.
Property | Description |
---|---|
Arguments | Holds arguments that were used to subscribe to a monitored item in an OPC-UA server. |
AttributeData | Attribute data: the value of an attribute, together with status code and timestamps. |
Diagnostics | Diagnostics information (such as warnings) assembled during the operation. (Inherited from OpcLabs.BaseLib.OperationModel.OperationEventArgs) |
DiagnosticsCount | Count of diagnostic information elements assembled during the operation. (Inherited from OpcLabs.BaseLib.OperationModel.OperationEventArgs) |
DiagnosticsSummary | Textual summary of diagnostics information, one message per line. (Inherited from OpcLabs.BaseLib.OperationModel.OperationEventArgs) |
ErrorId | Gets or sets the error ID of the error. (Inherited from OpcLabs.BaseLib.OperationModel.OperationEventArgs) |
ErrorMessage | Gets or sets a message that describes the current exception. (Inherited from OpcLabs.BaseLib.OperationModel.OperationEventArgs) |
ErrorMessageBrief | The first line of the error message. (Inherited from OpcLabs.BaseLib.OperationModel.OperationEventArgs) |
Exception | Gets the current exception. Contains null reference when no exception. (Inherited from OpcLabs.BaseLib.OperationModel.OperationEventArgs) |
NormalizedDiagnostics | A normalized OpcLabs.BaseLib.OperationModel.OperationEventArgs.Diagnostics collection. (Inherited from OpcLabs.BaseLib.OperationModel.OperationEventArgs) |
NormalizedException | A normalized OpcLabs.BaseLib.OperationModel.OperationEventArgs.Exception object, or null if there was no error. (Inherited from OpcLabs.BaseLib.OperationModel.OperationEventArgs) |
StatusInfo | Status information corresponding to the contents of the event arguments. |
Succeeded | Gets indication whether the operation has succeeded. (Inherited from OpcLabs.BaseLib.OperationModel.OperationEventArgs) |
Example
- CSharp
- PowerShell
- VB.NET
- Python
- CSharp
- PowerShell
- VB.NET
- Python
- CSharp
- PowerShell
- VB.NET
- Visual Basic (VB 6.0)
- Python
- CSharp
- VB.NET
- Python
- CSharp
- VB.NET
- Python
- CSharp
- VB.NET
- Object Pascal
- PHP
- CSharp
- VB.NET
- Python
// This example shows how to subscribe to changes of a single monitored item and display the value of the item with each // change. // // Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html . // OPC client and subscriber examples in C# on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-CSharp . // 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. using System; using OpcLabs.EasyOpc.UA; using OpcLabs.EasyOpc.UA.OperationModel; namespace UADocExamples._EasyUAClient { partial class SubscribeDataChange { public static void Overload1() { UAEndpointDescriptor endpointDescriptor = "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer"; // or "http://opcua.demo-this.com:51211/UA/SampleServer" (currently not supported) // or "https://opcua.demo-this.com:51212/UA/SampleServer/" // Instantiate the client object and hook events. var client = new EasyUAClient(); client.DataChangeNotification += client_DataChangeNotification; Console.WriteLine("Subscribing..."); client.SubscribeDataChange(endpointDescriptor, "nsu=http://test.org/UA/Data/ ;i=10853", 1000); Console.WriteLine("Processing data change events for 20 seconds..."); System.Threading.Thread.Sleep(20 * 1000); Console.WriteLine("Unsubscribing..."); client.UnsubscribeAllMonitoredItems(); Console.WriteLine("Waiting for 5 seconds..."); System.Threading.Thread.Sleep(5 * 1000); Console.WriteLine("Finished."); } static void client_DataChangeNotification(object sender, EasyUADataChangeNotificationEventArgs e) { // Display value. if (e.Succeeded) Console.WriteLine($"Value: {e.AttributeData.Value}"); else Console.WriteLine($"*** Failure: {e.ErrorMessageBrief}"); } } }
# This example shows how to subscribe to changes of a single monitored item and display the value of the item with each # change. # # Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html . # OPC client and subscriber examples in PowerShell on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-PowerShell . # 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. #requires -Version 5.1 using namespace OpcLabs.EasyOpc.UA # The path below assumes that the current directory is [ProductDir]/Examples-NET/PowerShell/Windows . Add-Type -Path "../../../Components/Opclabs.QuickOpc/net472/OpcLabs.EasyOpcUA.dll" Add-Type -Path "../../../Components/Opclabs.QuickOpc/net472/OpcLabs.EasyOpcUAComponents.dll" [UAEndpointDescriptor]$endpointDescriptor = "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer" # or "http://opcua.demo-this.com:51211/UA/SampleServer" (currently not supported) # or "https://opcua.demo-this.com:51212/UA/SampleServer/" # Instantiate the client object. $client = New-Object EasyUAClient # Data change notification handler Register-ObjectEvent -InputObject $client -EventName DataChangeNotification -Action { # Display value. if ($EventArgs.Succeeded) { Write-Host "Value: $($EventArgs.AttributeData.Value)" } else { Write-Host "*** Failure: $($EventArgs.ErrorMessageBrief)" } } Write-Host "Subscribing..." $client.SubscribeDataChange($endpointDescriptor, "nsu=http://test.org/UA/Data/ ;i=10853", 1000) Write-Host "Processing data change events for 20 seconds..." $stopwatch = [System.Diagnostics.Stopwatch]::StartNew() while ($stopwatch.Elapsed.TotalSeconds -lt 20) { Start-Sleep -Seconds 1 } Write-Host "Unsubscribing..." $client.UnsubscribeAllMonitoredItems() Write-Host "Waiting for 5 seconds..." Start-Sleep -Seconds 5 Write-Host "Finished."
' This example shows how to subscribe to changes of a single monitored item and display the value of the item with each change. ' ' Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html . ' OPC client and subscriber examples in VB.NET on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-VBNET . ' 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. Imports OpcLabs.EasyOpc.UA Imports OpcLabs.EasyOpc.UA.OperationModel Namespace _EasyUAClient Friend Class SubscribeDataChange Public Shared Sub Overload1() ' Define which server we will work with. Dim endpointDescriptor As UAEndpointDescriptor = "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer" ' or "http://opcua.demo-this.com:51211/UA/SampleServer" (currently not supported) ' or "https://opcua.demo-this.com:51212/UA/SampleServer/" ' Instantiate the client object and hook events Dim client = New EasyUAClient() AddHandler client.DataChangeNotification, AddressOf client_DataChangeNotification Console.WriteLine("Subscribing...") client.SubscribeDataChange(endpointDescriptor, "nsu=http://test.org/UA/Data/ ;i=10853", 1000) Console.WriteLine("Processing monitored item changed events for 10 seconds...") Threading.Thread.Sleep(10 * 1000) Console.WriteLine("Unsubscribing...") client.UnsubscribeAllMonitoredItems() Console.WriteLine("Waiting for 5 seconds...") Threading.Thread.Sleep(5 * 1000) End Sub Private Shared Sub client_DataChangeNotification(ByVal sender As Object, ByVal e As EasyUADataChangeNotificationEventArgs) ' Display value If e.Succeeded Then Console.WriteLine("Value: {0}", e.AttributeData.Value) Else Console.WriteLine("*** Failure: {0}", e.ErrorMessageBrief) End If End Sub End Class End Namespace
# This example shows how to subscribe to changes of a single monitored item and display the value of the item with each # change. # # 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 . # 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. # The QuickOPC package is needed. Install it using "pip install opclabs_quickopc". import opclabs_quickopc import time # Import .NET namespaces. from OpcLabs.EasyOpc.UA import * from OpcLabs.EasyOpc.UA.OperationModel import * def dataChangeNotification(sender, e): # Display value. if e.Succeeded: print('Value: ', e.AttributeData.Value, sep='') else: print('*** Failure: ', e.ErrorMessageBrief, sep='') endpointDescriptor = UAEndpointDescriptor('opc.tcp://opcua.demo-this.com:51210/UA/SampleServer') # or 'http://opcua.demo-this.com:51211/UA/SampleServer' (currently not supported) # or 'https://opcua.demo-this.com:51212/UA/SampleServer/' # Instantiate the client object and hook events. client = EasyUAClient() client.DataChangeNotification += dataChangeNotification print('Subscribing...') IEasyUAClientExtension.SubscribeDataChange(client, endpointDescriptor, UANodeDescriptor('nsu=http://test.org/UA/Data/ ;i=10853'), 1000) print('Processing data change events for 20 seconds...') time.sleep(20) print('Unsubscribing...') client.UnsubscribeAllMonitoredItems() print('Waiting for 5 seconds...') time.sleep(5) print('Finished.')
// This example shows how to subscribe to changes of multiple monitored items and display the value of the monitored item with // each change. // // Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html . // OPC client and subscriber examples in C# on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-CSharp . // 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. using System; using OpcLabs.EasyOpc.UA; using OpcLabs.EasyOpc.UA.OperationModel; namespace UADocExamples._EasyUAClient { partial class SubscribeMultipleMonitoredItems { public static void Main1() { UAEndpointDescriptor endpointDescriptor = "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer"; // or "http://opcua.demo-this.com:51211/UA/SampleServer" (currently not supported) // or "https://opcua.demo-this.com:51212/UA/SampleServer/" // Instantiate the client object and hook events. var client = new EasyUAClient(); client.DataChangeNotification += client_DataChangeNotification_Main1; Console.WriteLine("Subscribing..."); client.SubscribeMultipleMonitoredItems(new[] { new EasyUAMonitoredItemArguments(null, endpointDescriptor, "nsu=http://test.org/UA/Data/ ;i=10845", 1000), new EasyUAMonitoredItemArguments(null, endpointDescriptor, "nsu=http://test.org/UA/Data/ ;i=10853", 1000), new EasyUAMonitoredItemArguments(null, endpointDescriptor, "nsu=http://test.org/UA/Data/ ;i=10855", 1000) }); Console.WriteLine("Processing monitored item changed events for 10 seconds..."); System.Threading.Thread.Sleep(10 * 1000); Console.WriteLine("Unsubscribing..."); client.UnsubscribeAllMonitoredItems(); Console.WriteLine("Waiting for 5 seconds..."); System.Threading.Thread.Sleep(5 * 1000); Console.WriteLine("Finished."); } static void client_DataChangeNotification_Main1(object sender, EasyUADataChangeNotificationEventArgs e) { // Display value. if (e.Succeeded) Console.WriteLine($"{e.Arguments.NodeDescriptor}: {e.AttributeData.Value}"); else Console.WriteLine($"{e.Arguments.NodeDescriptor} *** Failure: {e.ErrorMessageBrief}"); } } }
# This example shows how to subscribe to changes of multiple monitored items and display the value of the monitored item with # each change. # # Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html . # OPC client and subscriber examples in PowerShell on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-PowerShell . # 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. #requires -Version 5.1 using namespace OpcLabs.EasyOpc.UA using namespace OpcLabs.EasyOpc.UA.OperationModel # The path below assumes that the current directory is [ProductDir]/Examples-NET/PowerShell/Windows . Add-Type -Path "../../../Components/Opclabs.QuickOpc/net472/OpcLabs.EasyOpcUA.dll" Add-Type -Path "../../../Components/Opclabs.QuickOpc/net472/OpcLabs.EasyOpcUAComponents.dll" [UAEndpointDescriptor]$endpointDescriptor = "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer" # or "http://opcua.demo-this.com:51211/UA/SampleServer" (currently not supported) # or "https://opcua.demo-this.com:51212/UA/SampleServer/" # Instantiate the client object. $client = New-Object EasyUAClient # Data change notification handler Register-ObjectEvent -InputObject $client -EventName DataChangeNotification -Action { # Display value. if ($EventArgs.Succeeded) { Write-Host "$($EventArgs.Arguments.NodeDescriptor): $($EventArgs.AttributeData.Value)" } else { Write-Host "$($EventArgs.Arguments.NodeDescriptor) *** Failure: $($EventArgs.ErrorMessageBrief)" } } Write-Host "Subscribing..." $handleArray = $client.SubscribeMultipleMonitoredItems(@( (New-Object UAMonitoredItemArguments( (New-Object UAAttributeArguments($endpointDescriptor, [UANodeDescriptor]"nsu=http://test.org/UA/Data/ ;i=10845")), 1000)), (New-Object UAMonitoredItemArguments( (New-Object UAAttributeArguments($endpointDescriptor, [UANodeDescriptor]"nsu=http://test.org/UA/Data/ ;i=10853")), 1000)), (New-Object UAMonitoredItemArguments( (New-Object UAAttributeArguments($endpointDescriptor, [UANodeDescriptor]"nsu=http://test.org/UA/Data/ ;i=10855")), 1000)) )) Write-Host Write-Host "Processing monitored item changed events for 10 seconds..." $stopwatch = [System.Diagnostics.Stopwatch]::StartNew() while ($stopwatch.Elapsed.TotalSeconds -lt 10) { Start-Sleep -Seconds 1 } Write-Host "Unsubscribing..." $client.UnsubscribeAllMonitoredItems() Write-Host "Waiting for 5 seconds..." Start-Sleep -Seconds 5 Write-Host "Finished."
' This example shows how to subscribe to changes of multiple monitored items and display the value of the monitored item with ' each change. ' ' Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html . ' OPC client and subscriber examples in VB.NET on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-VBNET . ' 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. Imports OpcLabs.EasyOpc.UA Imports OpcLabs.EasyOpc.UA.OperationModel Namespace _EasyUAClient Partial Friend Class SubscribeMultipleMonitoredItems Public Shared Sub Main1() ' Define which server we will work with. Dim endpointDescriptor As UAEndpointDescriptor = "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer" ' or "http://opcua.demo-this.com:51211/UA/SampleServer" (currently not supported) ' or "https://opcua.demo-this.com:51212/UA/SampleServer/" ' Instantiate the client object and hook events Dim client = New EasyUAClient() AddHandler client.DataChangeNotification, AddressOf client_DataChangeNotification Console.WriteLine("Subscribing...") client.SubscribeMultipleMonitoredItems(New EasyUAMonitoredItemArguments() _ { New EasyUAMonitoredItemArguments(Nothing, endpointDescriptor, "nsu=http://test.org/UA/Data/ ;i=10845", 1000), New EasyUAMonitoredItemArguments(Nothing, endpointDescriptor, "nsu=http://test.org/UA/Data/ ;i=10853", 1000), New EasyUAMonitoredItemArguments(Nothing, endpointDescriptor, "nsu=http://test.org/UA/Data/ ;i=10855", 1000) } ) Console.WriteLine("Processing monitored item changed events for 10 seconds...") Threading.Thread.Sleep(10 * 1000) Console.WriteLine("Unsubscribing...") client.UnsubscribeAllMonitoredItems() Console.WriteLine("Waiting for 5 seconds...") Threading.Thread.Sleep(5 * 1000) End Sub Private Shared Sub client_DataChangeNotification(ByVal sender As Object, ByVal e As EasyUADataChangeNotificationEventArgs) ' Display value If e.Succeeded Then Console.WriteLine($"{e.Arguments.NodeDescriptor}: {e.AttributeData.Value}") Else Console.WriteLine($"{e.Arguments.NodeDescriptor} *** Failure: {e.ErrorMessageBrief}") End If End Sub End Class End Namespace
# This example shows how to subscribe to changes of multiple monitored items and display the value of the monitored item # with each change. # # 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 . # 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. # The QuickOPC package is needed. Install it using "pip install opclabs_quickopc". import opclabs_quickopc import time # Import .NET namespaces. from OpcLabs.EasyOpc.UA import * from OpcLabs.EasyOpc.UA.OperationModel import * def dataChangeNotification(sender, e): # Display value. if e.Succeeded: print(e.Arguments.NodeDescriptor, ': ', e.AttributeData.Value, sep='') else: print(e.Arguments.NodeDescriptor, ' *** Failure: ', e.ErrorMessageBrief, sep='') endpointDescriptor = UAEndpointDescriptor('opc.tcp://opcua.demo-this.com:51210/UA/SampleServer') # or 'http://opcua.demo-this.com:51211/UA/SampleServer' (currently not supported) # or 'https://opcua.demo-this.com:51212/UA/SampleServer/' # Instantiate the client object and hook events. client = EasyUAClient() client.DataChangeNotification += dataChangeNotification print('Subscribing...') client.SubscribeMultipleMonitoredItems([ EasyUAMonitoredItemArguments( None, endpointDescriptor, UANodeDescriptor('nsu=http://test.org/UA/Data/ ;i=10845'), UAMonitoringParameters(1000)), EasyUAMonitoredItemArguments( None, endpointDescriptor, UANodeDescriptor('nsu=http://test.org/UA/Data/ ;i=10853'), UAMonitoringParameters(1000)), EasyUAMonitoredItemArguments( None, endpointDescriptor, UANodeDescriptor('nsu=http://test.org/UA/Data/ ;i=10855'), UAMonitoringParameters(1000)), ]) print('Processing data change events for 10 seconds...') time.sleep(10) print('Unsubscribing...') client.UnsubscribeAllMonitoredItems() print('Waiting for 5 seconds...') time.sleep(5) print('Finished.')
// This example shows how to subscribe to changes of multiple monitored items // and display each change, identifying the different subscriptions by an // integer. // // Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html . // OPC client and subscriber examples in C# on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-CSharp . // 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. using System; using System.Threading; using OpcLabs.EasyOpc.UA; using OpcLabs.EasyOpc.UA.OperationModel; namespace UADocExamples._EasyUAClient { partial class SubscribeMultipleMonitoredItems { public static void StateAsInteger() { UAEndpointDescriptor endpointDescriptor = "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer"; // or "http://opcua.demo-this.com:51211/UA/SampleServer" (currently not supported) // or "https://opcua.demo-this.com:51212/UA/SampleServer/" // Instantiate the client object and hook events. var client = new EasyUAClient(); client.DataChangeNotification += ClientOnDataChangeNotification_StateAsInteger; Console.WriteLine("Subscribing..."); int[] handleArray = client.SubscribeMultipleMonitoredItems(new[] { new EasyUAMonitoredItemArguments(null, endpointDescriptor, "nsu=http://test.org/UA/Data/ ;i=10845", 1000) {State = 1}, // An integer we have chosen to identify the subscription new EasyUAMonitoredItemArguments(null, endpointDescriptor, "nsu=http://test.org/UA/Data/ ;i=10853", 1000) {State = 2}, // An integer we have chosen to identify the subscription new EasyUAMonitoredItemArguments(null, endpointDescriptor, "nsu=http://test.org/UA/Data/ ;i=10855", 1000) {State = 3} // An integer we have chosen to identify the subscription }); for (int i = 0; i < handleArray.Length; i++) Console.WriteLine($"handleArray[{i}]: {handleArray[i]}"); Console.WriteLine("Processing monitored item changed events for 10 seconds..."); Thread.Sleep(10 * 1000); Console.WriteLine("Unsubscribing..."); client.UnsubscribeAllMonitoredItems(); Console.WriteLine("Waiting for 5 seconds..."); Thread.Sleep(5 * 1000); Console.WriteLine("Finished."); } static void ClientOnDataChangeNotification_StateAsInteger(object sender, EasyUADataChangeNotificationEventArgs eventArgs) { // Obtain the integer state we have passed in. var stateAsInteger = (int) eventArgs.Arguments.State; // Display the data. if (eventArgs.Succeeded) Console.WriteLine($"{stateAsInteger}: {eventArgs.AttributeData}"); else Console.WriteLine($"{stateAsInteger} *** Failure: {eventArgs.ErrorMessageBrief}"); } } }
# This example shows how to subscribe to changes of multiple monitored items # and display each change, identifying the different subscriptions by an # integer. # # Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html . # OPC client and subscriber examples in PowerShell on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-PowerShell . # 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. #requires -Version 5.1 using namespace OpcLabs.EasyOpc.UA using namespace OpcLabs.EasyOpc.UA.OperationModel # The path below assumes that the current directory is [ProductDir]/Examples-NET/PowerShell/Windows . Add-Type -Path "../../../Components/Opclabs.QuickOpc/net472/OpcLabs.EasyOpcUA.dll" Add-Type -Path "../../../Components/Opclabs.QuickOpc/net472/OpcLabs.EasyOpcUAComponents.dll" [UAEndpointDescriptor]$endpointDescriptor = "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer" # or "http://opcua.demo-this.com:51211/UA/SampleServer" (currently not supported) # or "https://opcua.demo-this.com:51212/UA/SampleServer/" # Instantiate the client object. $client = New-Object EasyUAClient # Data change notification handler Register-ObjectEvent -InputObject $client -EventName DataChangeNotification -Action { # Obtain the integer state we have passed in. [int]$stateAsInteger = $EventArgs.Arguments.State # Display the data. if ($EventArgs.Succeeded) { Write-Host "$($stateAsinteger): $($EventArgs.AttributeData)" } else { Write-Host "$($stateAsinteger) *** Failure: $($EventArgs.ErrorMessageBrief)" } } Write-Host "Subscribing..." $handleArray = $client.SubscribeMultipleMonitoredItems(@( (New-Object UAMonitoredItemArguments( (New-Object UAAttributeArguments($endpointDescriptor, [UANodeDescriptor]"nsu=http://test.org/UA/Data/ ;i=10845")), 1000) -Property @{State = 1}), # An integer we have chosen to identify the subscription (New-Object UAMonitoredItemArguments( (New-Object UAAttributeArguments($endpointDescriptor, [UANodeDescriptor]"nsu=http://test.org/UA/Data/ ;i=10853")), 1000) -Property @{State = 2}), # An integer we have chosen to identify the subscription (New-Object UAMonitoredItemArguments( (New-Object UAAttributeArguments($endpointDescriptor, [UANodeDescriptor]"nsu=http://test.org/UA/Data/ ;i=10855")), 1000) -Property @{State = 3}) # An integer we have chosen to identify the subscription )) for ($i = 0; $i -lt $handleArray.Length; $i++) { Write-Host "handleArray[$($i)]: $($handleArray[$i])" } Write-Host Write-Host "Processing monitored item changed events for 10 seconds..." $stopwatch = [System.Diagnostics.Stopwatch]::StartNew() while ($stopwatch.Elapsed.TotalSeconds -lt 10) { Start-Sleep -Seconds 1 } Write-Host "Unsubscribing..." $client.UnsubscribeAllMonitoredItems() Write-Host "Waiting for 5 seconds..." Start-Sleep -Seconds 5 Write-Host "Finished."
' This example shows how to subscribe to changes of multiple monitored items ' and display each change, identifying the different subscriptions by an ' integer. ' ' Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html . ' OPC client and subscriber examples in VB.NET on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-VBNET . ' 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. Imports OpcLabs.EasyOpc.UA Imports OpcLabs.EasyOpc.UA.OperationModel Namespace _EasyUAClient Partial Friend Class SubscribeMultipleMonitoredItems Public Shared Sub StateAsInteger() ' Define which server we will work with. Dim endpointDescriptor As UAEndpointDescriptor = "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer" ' or "http://opcua.demo-this.com:51211/UA/SampleServer" (currently not supported) ' or "https://opcua.demo-this.com:51212/UA/SampleServer/" ' Instantiate the client object and hook events Dim client = New EasyUAClient() AddHandler client.DataChangeNotification, AddressOf ClientOnDataChangeNotification_StateAsInteger Console.WriteLine("Subscribing...") Dim handleArray() As Integer = client.SubscribeMultipleMonitoredItems(New EasyUAMonitoredItemArguments() _ { _ New EasyUAMonitoredItemArguments(Nothing, endpointDescriptor, _ "nsu=http://test.org/UA/Data/ ;i=10845", 1000) _ With {.State = 1}, _ New EasyUAMonitoredItemArguments(Nothing, endpointDescriptor, _ "nsu=http://test.org/UA/Data/ ;i=10853", 1000) _ With {.State = 2}, _ New EasyUAMonitoredItemArguments(Nothing, endpointDescriptor, _ "nsu=http://test.org/UA/Data/ ;i=10855", 1000) _ With {.State = 3} _ } _ ) ' An integer we have chosen to identify the subscription For i As Integer = 0 To handleArray.Length - 1 Console.WriteLine("handleArray[{0}]: {1}", i, handleArray(i)) Next i Console.WriteLine("Processing monitored item changed events for 10 seconds...") Threading.Thread.Sleep(10 * 1000) Console.WriteLine("Unsubscribing...") client.UnsubscribeAllMonitoredItems() Console.WriteLine("Waiting for 5 seconds...") Threading.Thread.Sleep(5 * 1000) Console.WriteLine("Finished.") End Sub Private Shared Sub ClientOnDataChangeNotification_StateAsInteger(ByVal sender As Object, ByVal eventArgs As EasyUADataChangeNotificationEventArgs) ' Obtain the integer state we have passed in. Dim stateAsInteger As Integer = CInt(eventArgs.Arguments.State) ' Display the data If eventArgs.Succeeded Then Console.WriteLine("{0}: {1}", stateAsInteger, eventArgs.AttributeData) Else Console.WriteLine("{0} *** Failure: {1}", stateAsInteger, eventArgs.ErrorMessageBrief) End If End Sub End Class End Namespace
REM This example shows how to subscribe to changes of multiple monitored items REM and display each change, identifying the different subscriptions by an REM integer. 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. ' The client object, with events 'Public WithEvents Client6 As EasyUAClient Public Sub SubscribeMultipleMonitoredItems_StateAsInteger_Command_Click() OutputText = "" Set Client6 = New EasyUAClient OutputText = OutputText & "Subscribing..." & vbCrLf Dim MonitoringParameters As New UAMonitoringParameters MonitoringParameters.SamplingInterval = 1000 Dim MonitoredItemArguments1 As New EasyUAMonitoredItemArguments MonitoredItemArguments1.endpointDescriptor.UrlString = "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer" MonitoredItemArguments1.nodeDescriptor.NodeId.expandedText = "nsu=http://test.org/UA/Data/ ;i=10845" Set MonitoredItemArguments1.MonitoringParameters = MonitoringParameters MonitoredItemArguments1.SetState 1 ' An integer we have chosen to identify the subscription Dim MonitoredItemArguments2 As New EasyUAMonitoredItemArguments MonitoredItemArguments2.endpointDescriptor.UrlString = "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer" MonitoredItemArguments2.nodeDescriptor.NodeId.expandedText = "nsu=http://test.org/UA/Data/ ;i=10853" Set MonitoredItemArguments2.MonitoringParameters = MonitoringParameters MonitoredItemArguments2.SetState 2 ' An integer we have chosen to identify the subscription Dim MonitoredItemArguments3 As New EasyUAMonitoredItemArguments MonitoredItemArguments3.endpointDescriptor.UrlString = "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer" MonitoredItemArguments3.nodeDescriptor.NodeId.expandedText = "nsu=http://test.org/UA/Data/ ;i=10855" Set MonitoredItemArguments3.MonitoringParameters = MonitoringParameters MonitoredItemArguments3.SetState 3 ' An integer we have chosen to identify the subscription Dim arguments(2) As Variant Set arguments(0) = MonitoredItemArguments1 Set arguments(1) = MonitoredItemArguments2 Set arguments(2) = MonitoredItemArguments3 Dim handleArray As Variant handleArray = Client6.SubscribeMultipleMonitoredItems(arguments) Dim i As Long: For i = LBound(handleArray) To UBound(handleArray) OutputText = OutputText & "handleArray(" & i & "): " & handleArray(i) & vbCrLf Next OutputText = OutputText & "Processing monitored item changed events for 10 seconds..." & vbCrLf Pause 10000 OutputText = OutputText & "Unsubscribing..." & vbCrLf Call Client6.UnsubscribeAllMonitoredItems OutputText = OutputText & "Waiting for 5 seconds..." & vbCrLf Pause 5000 Set Client2 = Nothing OutputText = OutputText & "Finished." & vbCrLf End Sub Public Sub Client6_DataChangeNotification(ByVal sender As Variant, ByVal eventArgs As EasyUADataChangeNotificationEventArgs) ' Obtain the integer state we have passed in. Dim stateAsInteger As Integer: stateAsInteger = eventArgs.arguments.State If eventArgs.Succeeded Then OutputText = OutputText & stateAsInteger & ": " & eventArgs.AttributeData & vbCrLf Else OutputText = OutputText & stateAsInteger & " *** Failure: " & eventArgs.ErrorMessageBrief & vbCrLf End If End Sub
# This example shows how to subscribe to changes of multiple monitored items # and display each change, identifying the different subscriptions by an # integer. # # 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 . # 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. # The QuickOPC package is needed. Install it using "pip install opclabs_quickopc". import opclabs_quickopc import time # Import .NET namespaces. from OpcLabs.EasyOpc.UA import * from OpcLabs.EasyOpc.UA.OperationModel import * def dataChangeNotification(sender, eventArgs): # Obtain the integer state we have passed in. stateAsInteger = int(eventArgs.Arguments.State) # Display value. if eventArgs.Succeeded: print(stateAsInteger, ': ', eventArgs.AttributeData.Value, sep='') else: print(stateAsInteger, ' *** Failure: ', eventArgs.ErrorMessageBrief, sep='') endpointDescriptor = UAEndpointDescriptor('opc.tcp://opcua.demo-this.com:51210/UA/SampleServer') # or 'http://opcua.demo-this.com:51211/UA/SampleServer' (currently not supported) # or 'https://opcua.demo-this.com:51212/UA/SampleServer/' # Instantiate the client object and hook events. client = EasyUAClient() client.DataChangeNotification += dataChangeNotification print('Subscribing...') monitoredItemArguments1 = EasyUAMonitoredItemArguments( None, endpointDescriptor, UANodeDescriptor('nsu=http://test.org/UA/Data/ ;i=10845'), UAMonitoringParameters(1000)) monitoredItemArguments1.State = 1 # an integer we have chosen to identify the subscription monitoredItemArguments2 = EasyUAMonitoredItemArguments( None, endpointDescriptor, UANodeDescriptor('nsu=http://test.org/UA/Data/ ;i=10853'), UAMonitoringParameters(1000)) monitoredItemArguments2.State = 2 # an integer we have chosen to identify the subscription monitoredItemArguments3 = EasyUAMonitoredItemArguments( None, endpointDescriptor, UANodeDescriptor('nsu=http://test.org/UA/Data/ ;i=10855'), UAMonitoringParameters(1000)) monitoredItemArguments3.State = 3 # an integer we have chosen to identify the subscription client.SubscribeMultipleMonitoredItems([ monitoredItemArguments1, monitoredItemArguments2, monitoredItemArguments3, ]) print('Processing data change events for 10 seconds...') time.sleep(10) print('Unsubscribing...') client.UnsubscribeAllMonitoredItems() print('Waiting for 5 seconds...') time.sleep(5) print('Finished.')
// This example shows how to subscribe to changes of multiple monitored items // and display each change, identifying the different subscriptions by an // object. // // Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html . // OPC client and subscriber examples in C# on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-CSharp . // 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. using System; using System.Threading; using OpcLabs.EasyOpc.UA; using OpcLabs.EasyOpc.UA.OperationModel; namespace UADocExamples._EasyUAClient { partial class SubscribeMultipleMonitoredItems { class CustomObject { public CustomObject(string name) { Name = name; } public string Name { get; } } public static void StateAsObject() { UAEndpointDescriptor endpointDescriptor = "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer"; // or "http://opcua.demo-this.com:51211/UA/SampleServer" (currently not supported) // or "https://opcua.demo-this.com:51212/UA/SampleServer/" // Instantiate the client object and hook events var client = new EasyUAClient(); client.DataChangeNotification += ClientOnDataChangeNotification_StateAsObject; Console.WriteLine("Subscribing..."); int[] handleArray = client.SubscribeMultipleMonitoredItems(new[] { new EasyUAMonitoredItemArguments(null, endpointDescriptor, "nsu=http://test.org/UA/Data/ ;i=10845", 1000) {State = new CustomObject("First")}, // A custom object that corresponds to the subscription new EasyUAMonitoredItemArguments(null, endpointDescriptor, "nsu=http://test.org/UA/Data/ ;i=10853", 1000) {State = new CustomObject("Second")}, // A custom object that corresponds to the subscription new EasyUAMonitoredItemArguments(null, endpointDescriptor, "nsu=http://test.org/UA/Data/ ;i=10855", 1000) {State = new CustomObject("Third")}, // A custom object that corresponds to the subscription }); for (int i = 0; i < handleArray.Length; i++) Console.WriteLine($"handleArray[{i}]: {handleArray[i]}"); Console.WriteLine("Processing monitored item changed events for 10 seconds..."); Thread.Sleep(10 * 1000); Console.WriteLine("Unsubscribing..."); client.UnsubscribeAllMonitoredItems(); Console.WriteLine("Waiting for 5 seconds..."); Thread.Sleep(5 * 1000); Console.WriteLine("Finished."); } static void ClientOnDataChangeNotification_StateAsObject(object sender, EasyUADataChangeNotificationEventArgs eventArgs) { // Obtain the custom object we have passed in. var stateAsObject = (CustomObject) eventArgs.Arguments.State; // Display the data if (eventArgs.Succeeded) Console.WriteLine($"{stateAsObject.Name}: {eventArgs.AttributeData}"); else Console.WriteLine($"{stateAsObject.Name} *** Failure: {eventArgs.ErrorMessageBrief}"); } } }
' This example shows how to subscribe to changes of multiple monitored items ' and display each change, identifying the different subscriptions by an ' object. ' ' Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html . ' OPC client and subscriber examples in VB.NET on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-VBNET . ' 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. Imports OpcLabs.EasyOpc.UA Imports OpcLabs.EasyOpc.UA.OperationModel Namespace _EasyUAClient Partial Friend Class SubscribeMultipleMonitoredItems Class CustomObject Public Sub New(ByVal name As String) _Name = name End Sub Public ReadOnly Property Name As String Get Return _Name End Get End Property Private ReadOnly _Name As String End Class Public Shared Sub StateAsObject() ' Define which server we will work with. Dim endpointDescriptor As UAEndpointDescriptor = "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer" ' or "http://opcua.demo-this.com:51211/UA/SampleServer" (currently not supported) ' or "https://opcua.demo-this.com:51212/UA/SampleServer/" ' Instantiate the client object and hook events Dim client = New EasyUAClient() AddHandler client.DataChangeNotification, AddressOf ClientOnDataChangeNotification_StateAsObject Console.WriteLine("Subscribing...") Dim handleArray() As Integer = client.SubscribeMultipleMonitoredItems(New EasyUAMonitoredItemArguments() _ { _ New EasyUAMonitoredItemArguments(Nothing, endpointDescriptor, _ "nsu=http://test.org/UA/Data/ ;i=10845", 1000) _ With {.State = New CustomObject("First")}, _ New EasyUAMonitoredItemArguments(Nothing, endpointDescriptor, _ "nsu=http://test.org/UA/Data/ ;i=10853", 1000) _ With {.State = New CustomObject("Second")}, _ New EasyUAMonitoredItemArguments(Nothing, endpointDescriptor, _ "nsu=http://test.org/UA/Data/ ;i=10855", 1000) _ With {.State = New CustomObject("Third")} _ } _ ) ' A custom object that corresponds to the subscription For i As Integer = 0 To handleArray.Length - 1 Console.WriteLine("handleArray[{0}]: {1}", i, handleArray(i)) Next i Console.WriteLine("Processing monitored item changed events for 10 seconds...") Threading.Thread.Sleep(10 * 1000) Console.WriteLine("Unsubscribing...") client.UnsubscribeAllMonitoredItems() Console.WriteLine("Waiting for 5 seconds...") Threading.Thread.Sleep(5 * 1000) Console.WriteLine("Finished.") End Sub Private Shared Sub ClientOnDataChangeNotification_StateAsObject(ByVal sender As Object, ByVal eventArgs As EasyUADataChangeNotificationEventArgs) ' Obtain the custom object we have passed in. Dim stateAsObject As CustomObject = CType(eventArgs.Arguments.State, CustomObject) ' Display the data If eventArgs.Succeeded Then Console.WriteLine("{0}: {1}", stateAsObject.Name, eventArgs.AttributeData) Else Console.WriteLine("{0} *** Failure: {1}", stateAsObject.Name, eventArgs.ErrorMessageBrief) End If End Sub End Class End Namespace
# This example shows how to subscribe to changes of multiple monitored items # and display each change, identifying the different subscriptions by an # object. # # 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 . # 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. # The QuickOPC package is needed. Install it using "pip install opclabs_quickopc". import opclabs_quickopc import time # Import .NET namespaces. from OpcLabs.EasyOpc.UA import * from OpcLabs.EasyOpc.UA.OperationModel import * class CustomObject(object): def __init__(self, name): self.name = name def dataChangeNotification(sender, eventArgs): # Obtain the custom object we have passed in. stateAsObject = eventArgs.Arguments.State # Display value. if eventArgs.Succeeded: print(stateAsObject.name, ': ', eventArgs.AttributeData.Value, sep='') else: print(stateAsObject.name, ' *** Failure: ', eventArgs.ErrorMessageBrief, sep='') endpointDescriptor = UAEndpointDescriptor('opc.tcp://opcua.demo-this.com:51210/UA/SampleServer') # or 'http://opcua.demo-this.com:51211/UA/SampleServer' (currently not supported) # or 'https://opcua.demo-this.com:51212/UA/SampleServer/' # Instantiate the client object and hook events. client = EasyUAClient() client.DataChangeNotification += dataChangeNotification print('Subscribing...') monitoredItemArguments1 = EasyUAMonitoredItemArguments( None, endpointDescriptor, UANodeDescriptor('nsu=http://test.org/UA/Data/ ;i=10845'), UAMonitoringParameters(1000)) monitoredItemArguments1.State = CustomObject('First') # a custom object that corresponds to the subscription monitoredItemArguments2 = EasyUAMonitoredItemArguments( None, endpointDescriptor, UANodeDescriptor('nsu=http://test.org/UA/Data/ ;i=10853'), UAMonitoringParameters(1000)) monitoredItemArguments2.State = CustomObject('Second') # a custom object that corresponds to the subscription monitoredItemArguments3 = EasyUAMonitoredItemArguments( None, endpointDescriptor, UANodeDescriptor('nsu=http://test.org/UA/Data/ ;i=10855'), UAMonitoringParameters(1000)) monitoredItemArguments3.State = CustomObject('Third') # a custom object that corresponds to the subscription client.SubscribeMultipleMonitoredItems([ monitoredItemArguments1, monitoredItemArguments2, monitoredItemArguments3, ]) print('Processing data change events for 10 seconds...') time.sleep(10) print('Unsubscribing...') client.UnsubscribeAllMonitoredItems() print('Waiting for 5 seconds...') time.sleep(5) print('Finished.')
// This example shows how to subscribe to changes of all data variables under a specified object in OPC UA address space. // // Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html . // OPC client and subscriber examples in C# on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-CSharp . // 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. using System; using System.Linq; using OpcLabs.EasyOpc.UA; using OpcLabs.EasyOpc.UA.AddressSpace; using OpcLabs.EasyOpc.UA.OperationModel; namespace UADocExamples._EasyUAClient { partial class SubscribeMultipleMonitoredItems { public static void AllInObject() { UAEndpointDescriptor endpointDescriptor = "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer"; // or "http://opcua.demo-this.com:51211/UA/SampleServer" (currently not supported) // or "https://opcua.demo-this.com:51212/UA/SampleServer/" // Instantiate the client object and hook events var client = new EasyUAClient(); client.DataChangeNotification += client_DataChangeNotification_AllInObject; // Obtain variables under "Scalar" node Console.WriteLine("Browsing..."); UANodeElementCollection nodeElementCollection; try { nodeElementCollection = client.BrowseDataVariables(endpointDescriptor, "nsu=http://test.org/UA/Data/ ;ns=2;i=10787"); } catch (UAException uaException) { Console.WriteLine("*** Failure: {0}", uaException.GetBaseException().Message); return; } // Create array with monitored item arguments EasyUAMonitoredItemArguments[] monitoredItemArgumentsArray = nodeElementCollection .Select(element => new EasyUAMonitoredItemArguments(null, endpointDescriptor, element)) .ToArray(); Console.WriteLine("Subscribing..."); client.SubscribeMultipleMonitoredItems(monitoredItemArgumentsArray); Console.WriteLine("Processing monitored item changed events for 20 seconds..."); System.Threading.Thread.Sleep(20 * 1000); Console.WriteLine("Unsubscribing..."); client.UnsubscribeAllMonitoredItems(); Console.WriteLine("Waiting for 5 seconds..."); System.Threading.Thread.Sleep(5 * 1000); } static void client_DataChangeNotification_AllInObject(object sender, EasyUADataChangeNotificationEventArgs e) { // Display value if (e.Succeeded) Console.WriteLine("{0}: {1}", e.Arguments.NodeDescriptor, e.AttributeData.Value); else Console.WriteLine("{0} *** Failure: {1}", e.Arguments.NodeDescriptor, e.ErrorMessageBrief); } } }
' This example shows how to subscribe to changes of all data variables under a specified object in OPC UA address space. ' ' Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html . ' OPC client and subscriber examples in VB.NET on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-VBNET . ' 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. Imports System.Linq Imports OpcLabs.EasyOpc.UA Imports OpcLabs.EasyOpc.UA.AddressSpace Imports OpcLabs.EasyOpc.UA.OperationModel Namespace _EasyUAClient Partial Friend Class SubscribeMultipleMonitoredItems Public Shared Sub AllInObject() ' Define which server we will work with. Dim endpointDescriptor As UAEndpointDescriptor = "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer" ' or "http://opcua.demo-this.com:51211/UA/SampleServer" (currently not supported) ' or "https://opcua.demo-this.com:51212/UA/SampleServer/" ' Instantiate the client object and hook events Dim client = New EasyUAClient() AddHandler client.DataChangeNotification, AddressOf client_DataChangeNotification_AllInObject ' Obtain variables under "Scalar" node Console.WriteLine("Subscribing...") Dim nodeElementCollection As UANodeElementCollection Try nodeElementCollection = client.BrowseDataVariables(endpointDescriptor, "nsu=http://test.org/UA/Data/ ;ns=2;i=10787") Catch uaException As UAException Console.WriteLine("*** Failure: {0}", uaException.GetBaseException.Message) Exit Sub End Try ' Create array with monitored item arguments Dim monitoredItemArgumentsArray() As EasyUAMonitoredItemArguments = nodeElementCollection.Select(Function(element) New EasyUAMonitoredItemArguments(Nothing, endpointDescriptor, element)).ToArray() Console.WriteLine("Subscribing...") client.SubscribeMultipleMonitoredItems(monitoredItemArgumentsArray) Console.WriteLine("Processing monitored item changed events for 20 seconds...") Threading.Thread.Sleep(20 * 1000) Console.WriteLine("Unsubscribing...") client.UnsubscribeAllMonitoredItems() Console.WriteLine("Waiting for 5 seconds...") Threading.Thread.Sleep(5 * 1000) End Sub Private Shared Sub client_DataChangeNotification_AllInObject(ByVal sender As Object, ByVal e As EasyUADataChangeNotificationEventArgs) ' Display value If e.Succeeded Then Console.WriteLine("{0}: {1}", e.Arguments.NodeDescriptor, e.AttributeData.Value) Else Console.WriteLine("{0} *** Failure: {1}", e.Arguments.NodeDescriptor, e.ErrorMessageBrief) End If End Sub End Class End Namespace
# This example shows how to subscribe to changes of multiple monitored items and display the value of the monitored item # with each change. # # 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 . # 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. # The QuickOPC package is needed. Install it using "pip install opclabs_quickopc". import opclabs_quickopc import time # Import .NET namespaces. from OpcLabs.EasyOpc.UA import * from OpcLabs.EasyOpc.UA.OperationModel import * def dataChangeNotification(sender, e): # Display value. if e.Succeeded: print(e.Arguments.NodeDescriptor, ': ', e.AttributeData.Value, sep='') else: print(e.Arguments.NodeDescriptor, ' *** Failure: ', e.ErrorMessageBrief, sep='') endpointDescriptor = UAEndpointDescriptor('opc.tcp://opcua.demo-this.com:51210/UA/SampleServer') # or 'http://opcua.demo-this.com:51211/UA/SampleServer' (currently not supported) # or 'https://opcua.demo-this.com:51212/UA/SampleServer/' # Instantiate the client object and hook events. client = EasyUAClient() client.DataChangeNotification += dataChangeNotification # Obtain variables under "Scalar" node. print('Browsing...') try: nodeElementCollection = IEasyUAClientExtension.BrowseDataVariables(client, endpointDescriptor, UANodeDescriptor('nsu=http://test.org/UA/Data/ ;ns=2;i=10787')) except UAException as uaException: print('*** Failure: ' + uaException.GetBaseException().Message) exit() # Create array with monitored item arguments. monitoredItemArgumentsArray = list(map( lambda element: EasyUAMonitoredItemArguments(None, endpointDescriptor, element.ToUANodeDescriptor()), nodeElementCollection)) print('Subscribing...') client.SubscribeMultipleMonitoredItems(monitoredItemArgumentsArray) print('Processing data change events for 20 seconds...') time.sleep(20) print('Unsubscribing...') client.UnsubscribeAllMonitoredItems() print('Waiting for 5 seconds...') time.sleep(5) print('Finished.')
// Shows how to subscribe to complex data with OPC UA Complex Data plug-in. // // Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html . // OPC client and subscriber examples in C# on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-CSharp . // 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. using System; using OpcLabs.EasyOpc.UA; using OpcLabs.EasyOpc.UA.OperationModel; namespace UADocExamples.ComplexData._EasyUAClient { class SubscribeDataChange { public static void Main1() { // Define which server and node we will work with. UAEndpointDescriptor endpointDescriptor = "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer"; // or "http://opcua.demo-this.com:51211/UA/SampleServer" (currently not supported) // or "https://opcua.demo-this.com:51212/UA/SampleServer/" UANodeDescriptor nodeDescriptor = "nsu=http://test.org/UA/Data/ ;i=10867"; // [ObjectsFolder]/Data.Dynamic.Scalar.StructureValue // Instantiate the client object and hook the event handler. var client = new EasyUAClient(); client.DataChangeNotification += client_DataChangeNotification; // Subscribe to a node which returns complex data. This is done in the same way as regular subscribes - just // the data returned is different. Console.WriteLine("Subscribing..."); client.SubscribeDataChange(endpointDescriptor, nodeDescriptor, samplingInterval:1000); Console.WriteLine("Processing data change events for 20 seconds..."); System.Threading.Thread.Sleep(20 * 1000); Console.WriteLine("Unsubscribing..."); client.UnsubscribeAllMonitoredItems(); Console.WriteLine("Waiting for 5 seconds..."); System.Threading.Thread.Sleep(5 * 1000); // Unhook the event handler. client.DataChangeNotification -= client_DataChangeNotification; // Example output: // //Subscribing... //Processing data change events for 20 seconds... //(ScalarValueDataType) structured //(ArrayValueDataType) structured //(ArrayValueDataType) structured //(ArrayValueDataType) structured //(ArrayValueDataType) structured //(ArrayValueDataType) structured //(ArrayValueDataType) structured //(ArrayValueDataType) structured //(ScalarValueDataType) structured //(ScalarValueDataType) structured //(ArrayValueDataType) structured //(ArrayValueDataType) structured //(ScalarValueDataType) structured //(ArrayValueDataType) structured //(ArrayValueDataType) structured //(ScalarValueDataType) structured //(ScalarValueDataType) structured //(ScalarValueDataType) structured //Unsubscribing... //Waiting for 5 seconds... } static void client_DataChangeNotification(object sender, EasyUADataChangeNotificationEventArgs e) { // Display value if (e.Succeeded) Console.WriteLine("Value: {0}", e.AttributeData.Value); else Console.WriteLine("*** Failure: {0}", e.ErrorMessageBrief); // For processing the internals of the data, refer to examples for GenericData and DataType classes. } } }
' Shows how to subscribe to complex data with OPC UA Complex Data plug-in. ' ' Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html . ' OPC client and subscriber examples in VB.NET on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-VBNET . ' 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. Imports System Imports OpcLabs.EasyOpc.UA Imports OpcLabs.EasyOpc.UA.OperationModel Namespace ComplexData._EasyUAClient Friend Class SubscribeDataChange Public Shared Sub Main1() ' Define which server we will work with. Dim endpointDescriptor As UAEndpointDescriptor = "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer" ' or "http://opcua.demo-this.com:51211/UA/SampleServer" (currently not supported) ' or "https://opcua.demo-this.com:51212/UA/SampleServer/" ' Define which node we will work with. Dim nodeDescriptor As UANodeDescriptor = _ "nsu=http://test.org/UA/Data/ ;i=10867" ' [ObjectsFolder]/Data.Dynamic.Scalar.StructureValue ' Instantiate the client object and hook the event handler. Dim client = New EasyUAClient AddHandler client.DataChangeNotification, AddressOf client_DataChangeNotification ' Subscribe to a node which returns complex data. This is done in the same way as regular subscribes - just ' the data returned is different. Console.WriteLine("Subscribing...") client.SubscribeDataChange(endpointDescriptor, nodeDescriptor, samplingInterval:=1000) Console.WriteLine("Processing data change events for 20 seconds...") Threading.Thread.Sleep((20 * 1000)) Console.WriteLine("Unsubscribing...") client.UnsubscribeAllMonitoredItems() Console.WriteLine("Waiting for 5 seconds...") Threading.Thread.Sleep((5 * 1000)) ' Unhook the event handler. RemoveHandler client.DataChangeNotification, AddressOf client_DataChangeNotification ' Example output: ' 'Subscribing... 'Processing data change events for 20 seconds... '(ScalarValueDataType) structured '(ArrayValueDataType) structured '(ArrayValueDataType) structured '(ArrayValueDataType) structured '(ArrayValueDataType) structured '(ArrayValueDataType) structured '(ArrayValueDataType) structured '(ArrayValueDataType) structured '(ScalarValueDataType) structured '(ScalarValueDataType) structured '(ArrayValueDataType) structured '(ArrayValueDataType) structured '(ScalarValueDataType) structured '(ArrayValueDataType) structured '(ArrayValueDataType) structured '(ScalarValueDataType) structured '(ScalarValueDataType) structured '(ScalarValueDataType) structured 'Unsubscribing... 'Waiting for 5 seconds... End Sub Private Shared Sub client_DataChangeNotification(sender As Object, e As EasyUADataChangeNotificationEventArgs) ' Display value If e.Succeeded Then Console.WriteLine("Value: {0}", e.AttributeData.Value) Else Console.WriteLine("*** Failure: {0}", e.ErrorMessageBrief) End If ' For processing the internals of the data, refer to examples for GenericData and DataType classes. End Sub End Class End Namespace
// Shows how to subscribe to complex data with OPC UA Complex Data plug-in. // // 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 TClientEventHandlers33 = class procedure OnDataChangeNotification( ASender: TObject; sender: OleVariant; const eventArgs: _EasyUADataChangeNotificationEventArgs); end; procedure TClientEventHandlers33.OnDataChangeNotification( ASender: TObject; sender: OleVariant; const eventArgs: _EasyUADataChangeNotificationEventArgs); begin // Display value if eventArgs.Succeeded then WriteLn('Value: ', eventArgs.AttributeData.Value.ToString) else WriteLn('*** Failure: ', eventArgs.ErrorMessageBrief); // For processing the internals of the data, refer to examples for GenericData and DataType classes. end; class procedure SubscribeDataChange.Main; var Client: TEasyUAClient; ClientEventHandlers: TClientEventHandlers33; EndpointDescriptor: string; NodeDescriptor: string; begin // Define which server and node we will work with. EndpointDescriptor := //'http://opcua.demo-this.com:51211/UA/SampleServer'; //'https://opcua.demo-this.com:51212/UA/SampleServer/'; 'opc.tcp://opcua.demo-this.com:51210/UA/SampleServer'; NodeDescriptor := 'nsu=http://test.org/UA/Data/ ;i=10867'; // [ObjectsFolder]/Data.Dynamic.Scalar.StructureValue // Instantiate the client object and hook events Client := TEasyUAClient.Create(nil); ClientEventHandlers := TClientEventHandlers33.Create; Client.OnDataChangeNotification := ClientEventHandlers.OnDataChangeNotification; // Subscribe to a node which returns complex data. This is done in the same way as regular subscribes - just // the data returned is different. WriteLn('Subscribing...'); Client.SubscribeDataChange(EndpointDescriptor, NodeDescriptor, 1000); WriteLn('Processing data change events for 20 seconds...'); PumpSleep(20*1000); WriteLn('Unsubscribing...'); Client.UnsubscribeAllMonitoredItems; WriteLn('Waiting for 5 seconds...'); PumpSleep(5*1000); WriteLn('Finished.'); FreeAndNil(Client); FreeAndNil(ClientEventHandlers); // Example output: // //Subscribing... //Processing data change events for 20 seconds... //(ScalarValueDataType) structured //(ArrayValueDataType) structured //(ArrayValueDataType) structured //(ArrayValueDataType) structured //(ArrayValueDataType) structured //(ArrayValueDataType) structured //(ArrayValueDataType) structured //(ArrayValueDataType) structured //(ScalarValueDataType) structured //(ScalarValueDataType) structured //(ArrayValueDataType) structured //(ArrayValueDataType) structured //(ScalarValueDataType) structured //(ArrayValueDataType) structured //(ArrayValueDataType) structured //(ScalarValueDataType) structured //(ScalarValueDataType) structured //(ScalarValueDataType) structured //Unsubscribing... //Waiting for 5 seconds... end;
// Shows how to subscribe to complex data with OPC UA Complex Data plug-in. // // 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 ClientEvents { function DataChangeNotification($Sender, $E) { // Display value if ($E->Succeeded) printf("Value: %s\n", $E->AttributeData->Value); else printf("*** Failure : %s\n", $E->ErrorMessageBrief); // For processing the internals of the data, refer to examples for GenericData and DataType classes. } } // Define which server and node we will work with. $EndpointDescriptor = //"http://opcua.demo-this.com:51211/UA/SampleServer"; //"https://opcua.demo-this.com:51212/UA/SampleServer/"; "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer"; $NodeDescriptor = "nsu=http://test.org/UA/Data/ ;i=10867"; // [ObjectsFolder]/Data.Dynamic.Scalar.StructureValue // Instantiate the client object and hook events $Client = new COM("OpcLabs.EasyOpc.UA.EasyUAClient"); $ClientEvents = new ClientEvents(); com_event_sink($Client, $ClientEvents, "DEasyUAClientEvents"); // Subscribe to a node which returns complex data. This is done in the same way as regular subscribes - just // the data returned is different. printf("Subscribing...\n"); $Client->SubscribeDataChange($EndpointDescriptor, $NodeDescriptor, 1000); printf("Processing data change events for 20 seconds...\n"); $startTime = time(); do { com_message_pump(1000); } while (time() < $startTime + 20); printf("Unsubscribing...\n"); $Client->UnsubscribeAllMonitoredItems; printf("Waiting for 5 seconds...\n"); $startTime = time(); do { com_message_pump(1000); } while (time() < $startTime + 5);
// This example shows how to store current state of the subscribed monitored items in a dictionary. // each change. // // Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html . // OPC client and subscriber examples in C# on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-CSharp . // 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. using System; using System.Collections.Generic; using System.Threading; using OpcLabs.EasyOpc.UA; using OpcLabs.EasyOpc.UA.OperationModel; namespace UADocExamples._EasyUAClient { partial class SubscribeMultipleMonitoredItems { public static void StoreInDictionary() { UAEndpointDescriptor endpointDescriptor = "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer"; // or "http://opcua.demo-this.com:51211/UA/SampleServer" (currently not supported) // or "https://opcua.demo-this.com:51212/UA/SampleServer/" // Instantiate the client object and hook events. using (var client = new EasyUAClient()) { client.DataChangeNotification += client_DataChangeNotification_StoreInDictionary; Console.WriteLine("Subscribing..."); client.SubscribeMultipleMonitoredItems(new[] { new EasyUAMonitoredItemArguments(null, endpointDescriptor, "nsu=http://test.org/UA/Data/ ;i=10845", 1000), new EasyUAMonitoredItemArguments(null, endpointDescriptor, "nsu=http://test.org/UA/Data/ ;i=10853", 1000), new EasyUAMonitoredItemArguments(null, endpointDescriptor, "nsu=http://test.org/UA/Data/ ;i=10855", 1000) }); Console.WriteLine("Processing monitored item changed events for 1 minute..."); int startTickCount = Environment.TickCount; do { Thread.Sleep(5 * 1000); // Each 5 seconds, display the current state of the monitored items we have subscribed to. lock (_serialize) { Console.WriteLine(); foreach (KeyValuePair<UANodeDescriptor, UAAttributeDataResult> pair in _attributeDataResultDictionary) { UANodeDescriptor nodeDescriptor = pair.Key; UAAttributeDataResult attributeDataResult = pair.Value; Console.WriteLine($"{nodeDescriptor}: {attributeDataResult}"); } // The code above shows how you can process the complete contents of the dictionary. In other // scenarios, you may want to access just a specific entry in the dictionary. You can achieve that // by indexing the dictionary by the node descriptor of the monitored item you are interested in. } } while (Environment.TickCount < startTickCount + 60 * 1000); Console.WriteLine("Unsubscribing..."); } Console.WriteLine("Finished."); } static void client_DataChangeNotification_StoreInDictionary(object sender, EasyUADataChangeNotificationEventArgs e) { lock (_serialize) // Convert the event arguments to a UAAttributeData result object, and store it in the dictionary under the // key which is the node descriptor of the monitored item this data change notification is for. _attributeDataResultDictionary[e.Arguments.NodeDescriptor] = (UAAttributeDataResult)e; } // Holds last known state of each subscribed monitored item. private static readonly Dictionary<UANodeDescriptor, UAAttributeDataResult> _attributeDataResultDictionary = new Dictionary<UANodeDescriptor, UAAttributeDataResult>(); // Synchronization object used to prevent simultaneous access to the dictionary. private static readonly object _serialize = new object(); } }
' This example shows how to store current state of the subscribed monitored items in a dictionary. ' each change. ' ' Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html . ' OPC client and subscriber examples in VB.NET on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-VBNET . ' 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. Imports System.Threading Imports OpcLabs.EasyOpc.UA Imports OpcLabs.EasyOpc.UA.OperationModel Namespace _EasyUAClient Partial Friend Class SubscribeMultipleMonitoredItems Public Shared Sub StoreInDictionary() ' Define which server we will work with. Dim endpointDescriptor As UAEndpointDescriptor = "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer" ' or "http://opcua.demo-this.com:51211/UA/SampleServer" (currently not supported) ' or "https://opcua.demo-this.com:51212/UA/SampleServer/" ' Instantiate the client object. Using client = New EasyUAClient() AddHandler client.DataChangeNotification, AddressOf client_DataChangeNotification_StoreInDictionary Console.WriteLine("Subscribing...") client.SubscribeMultipleMonitoredItems(New EasyUAMonitoredItemArguments() { New EasyUAMonitoredItemArguments(Nothing, endpointDescriptor, "nsu=http://test.org/UA/Data/ ;i=10845", 1000), New EasyUAMonitoredItemArguments(Nothing, endpointDescriptor, "nsu=http://test.org/UA/Data/ ;i=10853", 1000), New EasyUAMonitoredItemArguments(Nothing, endpointDescriptor, "nsu=http://test.org/UA/Data/ ;i=10855", 1000) }) Console.WriteLine("Processing monitored item changed events for 1 minute...") Dim startTickCount As Integer = Environment.TickCount Do Thread.Sleep(5 * 1000) ' Each 5 seconds, display the current state of the monitored items we have subscribed to. SyncLock _serialize Console.WriteLine() For Each pair As KeyValuePair(Of UANodeDescriptor, UAAttributeDataResult) In _attributeDataResultDictionary Dim nodeDescriptor As UANodeDescriptor = pair.Key Dim attributeDataResult As UAAttributeDataResult = pair.Value Console.WriteLine($"{nodeDescriptor}: {attributeDataResult}") Next ' The code above shows how you can process the complete contents of the dictionary. In other ' scenarios, you may want to access just a specific entry in the dictionary. You can achieve that ' by indexing the dictionary by the node descriptor of the monitored item you are interested in. End SyncLock Loop While Environment.TickCount < startTickCount + 60 * 1000 Console.WriteLine("Unsubscribing...") End Using Console.WriteLine("Finished.") End Sub Private Shared Sub client_DataChangeNotification_StoreInDictionary(ByVal sender As Object, ByVal e As EasyUADataChangeNotificationEventArgs) SyncLock _serialize ' Convert the event arguments to a UAAttributeData result object, and store it in the dictionary under the ' key which is the node descriptor of the monitored item this data change notification is for. _attributeDataResultDictionary(e.Arguments.NodeDescriptor) = CType(e, UAAttributeDataResult) End SyncLock ' Display value If e.Succeeded Then Console.WriteLine("{0}: {1}", e.Arguments.NodeDescriptor, e.AttributeData.Value) Else Console.WriteLine("{0} *** Failure: {1}", e.Arguments.NodeDescriptor, e.ErrorMessageBrief) End If End Sub ' Holds last known state of each subscribed monitores item. Private Shared ReadOnly _attributeDataResultDictionary As New Dictionary(Of UANodeDescriptor, UAAttributeDataResult) ' Synchronization object used to prevent simultaneous access to the dictionary. Private Shared ReadOnly _serialize As New Object End Class End Namespace
# This example shows how to store current state of the subscribed monitored items in a dictionary. # each change. # # 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 . # 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. # The QuickOPC package is needed. Install it using "pip install opclabs_quickopc". import opclabs_quickopc import threading import time # Import .NET namespaces. from OpcLabs.EasyOpc.UA import * from OpcLabs.EasyOpc.UA.OperationModel import * lock = threading.Lock() attributeDataResultDictionary = {} # Data change notification event handler. def dataChangeNotification(sender, eventArgs): global lock global attributeDataResultDictionary with lock: # Convert the event arguments to a UAAttributeData result object, and store it in the dictionary under the # key which is the node descriptor of the monitored item this data change notification is for. attributeDataResultDictionary[eventArgs.Arguments.NodeDescriptor] = EasyUADataChangeNotificationEventArgs.ToUAAttributeDataResult(eventArgs) endpointDescriptor = UAEndpointDescriptor('opc.tcp://opcua.demo-this.com:51210/UA/SampleServer') # or 'http://opcua.demo-this.com:51211/UA/SampleServer' (currently not supported) # or 'https://opcua.demo-this.com:51212/UA/SampleServer/' # Instantiate the client object. client = EasyUAClient() # Hook events. client.DataChangeNotification += dataChangeNotification print('Subscribing...') client.SubscribeMultipleMonitoredItems([ EasyUAMonitoredItemArguments( None, endpointDescriptor, UANodeDescriptor('nsu=http://test.org/UA/Data/ ;i=10845'), UAMonitoringParameters(1000)), EasyUAMonitoredItemArguments( None, endpointDescriptor, UANodeDescriptor('nsu=http://test.org/UA/Data/ ;i=10853'), UAMonitoringParameters(1000)), EasyUAMonitoredItemArguments( None, endpointDescriptor, UANodeDescriptor('nsu=http://test.org/UA/Data/ ;i=10855'), UAMonitoringParameters(1000)), ]) print('Processing data change events for 1 minute...') endTime = time.time() + 60 while time.time() < endTime: time.sleep(5) # # Each 5 seconds, display the current state of the monitored items we have subscribed to. with lock: print() print('Current state of the monitored items:') for nodeDescriptor, attributeDataResult in attributeDataResultDictionary.items(): print(nodeDescriptor, ': ', attributeDataResult, sep='') # # The code above shows how you can process the complete contents of the dictionary. In other # scenarios, you may want to access just a specific entry in the dictionary. You can achieve that # by indexing the dictionary by the node descriptor of the monitored item you are interested in. print() print('Unsubscribing all monitored items...') client.UnsubscribeAllMonitoredItems() print('Waiting for 5 seconds...') time.sleep(5) print('Finished.')
Requirements