![](dotnetdiagramimages/OpcLabs_EasyOpcUAComponents_OpcLabs_EasyOpc_UA_EasyUAClient.png)
The EasyUAClient object is the main object that allows simple access to OPC Unified Architecture servers.
The principal members of this object are implementations of the IEasyUAClient interface.
'Declaration
<ComDefaultInterfaceAttribute(OpcLabs.EasyOpc.UA.ComTypes._EasyUAClient)> <ComSourceInterfacesAttribute(OpcLabs.EasyOpc.UA.ComTypes.DEasyUAClientEvents)> <ComVisibleAttribute(True)> <GuidAttribute("54AFB0EA-9809-4D1D-AFBE-0EC164C59A45")> <TypeConverterAttribute(System.ComponentModel.ExpandableObjectConverter)> <CLSCompliantAttribute(True)> <DesignerCategoryAttribute("Component")> <SerializableAttribute()> Public NotInheritable Class EasyUAClient Inherits EasyUAClientCore Implements OpcLabs.BaseLib.ComponentModel.Internal.IComponentCallback, OpcLabs.BaseLib.ComponentModel.Internal.IComponentNotify, OpcLabs.BaseLib.ILicenseInfoProvider, OpcLabs.BaseLib.IValueEquatable, OpcLabs.BaseLib.Licensing.ILicensingContextHolder, OpcLabs.BaseLib.Widgets.ComTypes._NotifyingWidget, OpcLabs.BaseLib.Widgets.ComTypes._Widget, OpcLabs.BaseLib.Widgets.IWidget, OpcLabs.EasyOpc.UA.ComTypes._EasyUAClient, IEasyUAClient, IEasyUAClientSettings, System.ComponentModel.IComponent, System.ICloneable, System.IDisposable, System.IServiceProvider, System.Runtime.Serialization.ISerializable, System.Xml.Serialization.IXmlSerializable
'Usage
Dim instance As EasyUAClient
[ComDefaultInterface(OpcLabs.EasyOpc.UA.ComTypes._EasyUAClient)] [ComSourceInterfaces(OpcLabs.EasyOpc.UA.ComTypes.DEasyUAClientEvents)] [ComVisible(true)] [Guid("54AFB0EA-9809-4D1D-AFBE-0EC164C59A45")] [TypeConverter(System.ComponentModel.ExpandableObjectConverter)] [CLSCompliant(true)] [DesignerCategory("Component")] [Serializable()] public sealed class EasyUAClient : EasyUAClientCore, OpcLabs.BaseLib.ComponentModel.Internal.IComponentCallback, OpcLabs.BaseLib.ComponentModel.Internal.IComponentNotify, OpcLabs.BaseLib.ILicenseInfoProvider, OpcLabs.BaseLib.IValueEquatable, OpcLabs.BaseLib.Licensing.ILicensingContextHolder, OpcLabs.BaseLib.Widgets.ComTypes._NotifyingWidget, OpcLabs.BaseLib.Widgets.ComTypes._Widget, OpcLabs.BaseLib.Widgets.IWidget, OpcLabs.EasyOpc.UA.ComTypes._EasyUAClient, IEasyUAClient, IEasyUAClientSettings, System.ComponentModel.IComponent, System.ICloneable, System.IDisposable, System.IServiceProvider, System.Runtime.Serialization.ISerializable, System.Xml.Serialization.IXmlSerializable
[ComDefaultInterface(OpcLabs.EasyOpc.UA.ComTypes._EasyUAClient)] [ComSourceInterfaces(OpcLabs.EasyOpc.UA.ComTypes.DEasyUAClientEvents)] [ComVisible(true)] [Guid("54AFB0EA-9809-4D1D-AFBE-0EC164C59A45")] [TypeConverter(System.ComponentModel.ExpandableObjectConverter)] [CLSCompliant(true)] [DesignerCategory("Component")] [Serializable()] public ref class EasyUAClient sealed : public EasyUAClientCore, OpcLabs.BaseLib.ComponentModel.Internal.IComponentCallback, OpcLabs.BaseLib.ComponentModel.Internal.IComponentNotify, OpcLabs.BaseLib.ILicenseInfoProvider, OpcLabs.BaseLib.IValueEquatable, OpcLabs.BaseLib.Licensing.ILicensingContextHolder, OpcLabs.BaseLib.Widgets.ComTypes._NotifyingWidget, OpcLabs.BaseLib.Widgets.ComTypes._Widget, OpcLabs.BaseLib.Widgets.IWidget, OpcLabs.EasyOpc.UA.ComTypes._EasyUAClient, IEasyUAClient, IEasyUAClientSettings, System.ComponentModel.IComponent, System.ICloneable, System.IDisposable, System.IServiceProvider, System.Runtime.Serialization.ISerializable, System.Xml.Serialization.IXmlSerializable
This object derives from EasyUAClientCore, and many members are defined there.
// This example shows how to read value of a single node, and display it. // // 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 ReadValue { 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. var client = new EasyUAClient(); Console.WriteLine("Obtaining value of a node..."); object value; try { value = client.ReadValue(endpointDescriptor, "nsu=http://test.org/UA/Data/ ;i=10853"); } catch (UAException uaException) { Console.WriteLine($"*** Failure: {uaException.GetBaseException().Message}"); return; } // Display results Console.WriteLine($"value: {value}"); } } }
# This example shows how to read value of a single node, and display it. # # 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 Write-Host "Obtaining value of a node..." try { $value = $client.ReadValue($endpointDescriptor, "nsu=http://test.org/UA/Data/ ;i=10853") } catch [UAException] { Write-Host "*** Failure: $($PSItem.Exception.GetBaseException().Message)" return } # Display results Write-Host "value: $($value)"
' This example shows how to read value of a single node, and display it. ' ' 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 ReadValue 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 Dim client = New EasyUAClient() ' Obtain value of a node Dim value As Object Try value = client.ReadValue(endpointDescriptor, "nsu=http://test.org/UA/Data/ ;i=10853") Catch uaException As UAException Console.WriteLine("*** Failure: {0}", uaException.GetBaseException.Message) Exit Sub End Try ' Display results Console.WriteLine("value: {0}", value) End Sub End Class End Namespace
# This example shows how to read value of a single node, and display it. # # 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 .NET namespaces. from OpcLabs.EasyOpc.UA import * from OpcLabs.EasyOpc.UA.OperationModel import * 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() # Perform the operation. try: value = IEasyUAClientExtension.ReadValue(client, endpointDescriptor, UANodeDescriptor('nsu=http://test.org/UA/Data/ ;i=10853')) except UAException as uaException: print('*** Failure: ' + uaException.GetBaseException().Message) exit() # Display results. print('value: ', value, sep='') print('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 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 that either a single client object, or multiple client objects can be used to read values from two // servers. // // 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 ReadValue { public static void MultipleServers() { // Define which servers we will work with. UAEndpointDescriptor endpointDescriptor1 = "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/" UAEndpointDescriptor endpointDescriptor2 = "opc.tcp://opcua.demo-this.com:62544/Quickstarts/AlarmConditionServer"; // Part 1: Use a single client object. // This demonstrates the fact that the client objects do *not* represent connections to individual servers. // Instead, they are able to maintain connections to multiple servers internally. API method calls on the client // object include the server's endpoint descriptor in their arguments, so you can specify a different endpoint // with each operation. Console.WriteLine(); // Instantiate the client object var client = new EasyUAClient(); Console.WriteLine("Obtaining values of nodes using a single client object..."); object value1, value2; try { // The node Id we are reading returns the product name of the server. value1 = client.ReadValue(endpointDescriptor1, "nsu=http://opcfoundation.org/UA/ ;i=2261"); value2 = client.ReadValue(endpointDescriptor2, "nsu=http://opcfoundation.org/UA/ ;i=2261"); // Note: For efficiency (reading from the two servers in parallel), it would be better to use the // ReadMultipleValues method here, but this example is made for code clarity. } catch (UAException uaException) { Console.WriteLine("*** Failure: {0}", uaException.GetBaseException().Message); return; } // Display results Console.WriteLine("value1: {0}", value1); Console.WriteLine("value2: {0}", value2); // Part 2: Use multiple client objects. // This demonstrates the fact that it is also possible to use multiple client objects, and on the OPC side, the // behavior will be the same as if you had used a single client object. Multiple client objects consume somewhat // more resources on the client side, but they come handy if, for example, // - you cannot easily pass around the single pre-created client object to various parts in your code, or // - you are using subscriptions, and you want to hook separate event handlers for different purposes, or // - you need to set something in the instance parameters of the client object differently for different // connections. Console.WriteLine(); // Instantiate the client objects. var client1 = new EasyUAClient(); var client2 = new EasyUAClient(); Console.WriteLine("Obtaining values of nodes using multiple client objects..."); try { // The node Id we are reading returns the product name of the server. value1 = client1.ReadValue(endpointDescriptor1, "nsu=http://opcfoundation.org/UA/ ;i=2261"); value2 = client2.ReadValue(endpointDescriptor2, "nsu=http://opcfoundation.org/UA/ ;i=2261"); } catch (UAException uaException) { Console.WriteLine("*** Failure: {0}", uaException.GetBaseException().Message); return; } // Display results Console.WriteLine("value1: {0}", value1); Console.WriteLine("value2: {0}", value2); // Example output: // //Obtaining values of nodes using a single client object... //value1: OPC UA SDK Samples //value2: OPC UA Workshop Samples // //Obtaining values of nodes using multiple client objects... //value1: OPC UA SDK Samples //value2: OPC UA Workshop Samples } } }
' This example shows that either a single client object, or multiple client objects can be used to read values from two ' servers. ' ' 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 Newtonsoft.Json.Linq Imports OpcLabs.EasyOpc.UA Imports OpcLabs.EasyOpc.UA.OperationModel Namespace _EasyUAClient Partial Friend Class ReadValue Public Shared Sub MultipleServers() ' Define which server we will work with. Dim endpointDescriptor1 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/" Dim endpointDescriptor2 As UAEndpointDescriptor = "opc.tcp://opcua.demo-this.com:62544/Quickstarts/AlarmConditionServer" ' Part 1: Use a single client object. ' This demonstrates the fact that the client objects do *not* represent connections to individual servers. ' Instead, they are able to maintain connections to multiple servers internally. API method calls on the client ' object include the server's endpoint descriptor in their arguments, so you can specify a different endpoint ' with each operation. Console.WriteLine() ' Instantiate the client object Dim client = New EasyUAClient() Console.WriteLine("Obtaining values of nodes using a single client object...") ' Obtain value of a node Dim value1 As Object Dim value2 As Object Try ' The node Id we are reading returns the product name of the server. value1 = client.ReadValue(endpointDescriptor1, "nsu=http://opcfoundation.org/UA/ ;i=2261") value2 = client.ReadValue(endpointDescriptor2, "nsu=http://opcfoundation.org/UA/ ;i=2261") ' Note: For efficiency(reading from the two servers in parallel), it would be better to use the ' ReadMultipleValues method here, but this example is made for code clarity. Catch uaException As UAException Console.WriteLine("*** Failure: {0}", uaException.GetBaseException.Message) Exit Sub End Try ' Display results Console.WriteLine("value1: {0}", value1) Console.WriteLine("value2: {0}", value2) ' Part 2: Use multiple client objects. ' This demonstrates the fact that it is also possible to use multiple client objects, and on the OPC side, the ' behavior will be the same as if you had used a single client object. Multiple client objects consume somewhat ' more resources on the client side, but they come handy if, for example, ' - you cannot easily pass around the single pre-created client object to various parts in your code, or ' - you are using subscriptions, and you want to hook separate event handlers for different purposes, or ' - you need to set something in the instance parameters of the client object differently for different ' connections. Console.WriteLine() ' Instantiate the client objects. Dim client1 = New EasyUAClient() Dim client2 = New EasyUAClient() Console.WriteLine("Obtaining values of nodes using multiple client objects...") Try ' The node Id we are reading returns the product name of the server. value1 = client1.ReadValue(endpointDescriptor1, "nsu=http://opcfoundation.org/UA/ ;i=2261") value2 = client2.ReadValue(endpointDescriptor2, "nsu=http://opcfoundation.org/UA/ ;i=2261") Catch uaException As UAException Console.WriteLine("*** Failure: {0}", uaException.GetBaseException.Message) Exit Sub End Try ' Display results Console.WriteLine("value1: {0}", value1) Console.WriteLine("value2: {0}", value2) ' Example output ' 'Obtaining values of nodes using a single client object... 'value1: Opc UA SDK Samples 'value2: Opc UA Workshop Samples ' 'Obtaining values of nodes using multiple client objects... 'value1: Opc UA SDK Samples 'value2: Opc UA Workshop Samples End Sub End Class End Namespace
# This example shows that either a single client object, or multiple client objects can be used to read values from two # servers. # # 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 .NET namespaces. from OpcLabs.EasyOpc.UA import * from OpcLabs.EasyOpc.UA.OperationModel import * # Define which servers we will work with. endpointDescriptor1 = 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/' endpointDescriptor2 = UAEndpointDescriptor('opc.tcp://opcua.demo-this.com:62544/Quickstarts/AlarmConditionServer') # Part 1: Use a single client object. # This demonstrates the fact that the client objects do *not* represent connections to individual servers. # Instead, they are able to maintain connections to multiple servers internally. API method calls on the client # object include the server's endpoint descriptor in their arguments, so you can specify a different endpoint # with each operation. print() # Instantiate the client object. client = EasyUAClient() print('Obtaining values of nodes using a single client object...') try: # The node Id we are reading returns the product name of the server. value1 = IEasyUAClientExtension.ReadValue(client, endpointDescriptor1, UANodeDescriptor('nsu=http://opcfoundation.org/UA/ ;i=2261')) value2 = IEasyUAClientExtension.ReadValue(client, endpointDescriptor2, UANodeDescriptor('nsu=http://opcfoundation.org/UA/ ;i=2261')) except UAException as uaException: print('*** Failure: ' + uaException.GetBaseException().Message) exit() # Display results. print('value1: ', value1, sep='') print('value2: ', value2, sep='') # Part 2: Use multiple client objects. # This demonstrates the fact that it is also possible to use multiple client objects, and on the OPC side, the # behavior will be the same as if you had used a single client object. Multiple client objects consume somewhat # more resources on the client side, but they come handy if, for example, # - you cannot easily pass around the single pre-created client object to various parts in your code, or # - you are using subscriptions, and you want to hook separate event handlers for different purposes, or # - you need to set something in the instance parameters of the client object differently for different # connections. print() # Instantiate the client objects. client1 = EasyUAClient() client2 = EasyUAClient() print('Obtaining values of nodes using multiple client objects...') try: # The node Id we are reading returns the product name of the server. value1 = IEasyUAClientExtension.ReadValue(client1, endpointDescriptor1, UANodeDescriptor('nsu=http://opcfoundation.org/UA/ ;i=2261')) value2 = IEasyUAClientExtension.ReadValue(client2, endpointDescriptor2, UANodeDescriptor('nsu=http://opcfoundation.org/UA/ ;i=2261')) except UAException as uaException: print('*** Failure: ' + uaException.GetBaseException().Message) exit() # Display results. print('value1: ', value1, sep='') print('value2: ', value2, sep='') print() print('Finished.')
System.Object
System.MarshalByRefObject
System.ComponentModel.Component
OpcLabs.BaseLib.Widgets.Widget
OpcLabs.BaseLib.Widgets.NotifyingWidget
OpcLabs.EasyOpc.UA.EasyUAClientCore
OpcLabs.EasyOpc.UA.EasyUAClient