QuickOPC User's Guide and Reference
WriteValue(IEasyUAClient,UAEndpointDescriptor,UANodeDescriptor,Object,Type) Method
Example 



OpcLabs.EasyOpcUA Assembly > OpcLabs.EasyOpc.UA Namespace > IEasyUAClientExtension Class > WriteValue Method : WriteValue(IEasyUAClient,UAEndpointDescriptor,UANodeDescriptor,Object,Type) Method
The client object that will perform the operation.
Endpoint descriptor. Identifies the OPC-UA server.
Node descriptor. Identifies the node in OPC server's address space.
The value to be written.
Specifies the type that should be used when writing the value.
Writes a value into an attribute an OPC server. Only the item value is written (status code and timestamps are not written). Writes value into a Value attribute of a node, using an endpoint descriptor, node Id, and an attribute type.
Syntax
'Declaration
 
<ExtensionAttribute()>
Public Overloads Shared Function WriteValue( _
   ByVal client As IEasyUAClient, _
   ByVal endpointDescriptor As UAEndpointDescriptor, _
   ByVal nodeDescriptor As UANodeDescriptor, _
   ByVal value As Object, _
   ByVal valueType As Type _
) As ValueTuple(Of Boolean,Boolean)
'Usage
 
Dim client As IEasyUAClient
Dim endpointDescriptor As UAEndpointDescriptor
Dim nodeDescriptor As UANodeDescriptor
Dim value As Object
Dim valueType As Type
Dim value As ValueTuple(Of Boolean,Boolean)
 
value = IEasyUAClientExtension.WriteValue(client, endpointDescriptor, nodeDescriptor, value, valueType)

Parameters

client
The client object that will perform the operation.
endpointDescriptor
Endpoint descriptor. Identifies the OPC-UA server.
nodeDescriptor
Node descriptor. Identifies the node in OPC server's address space.
value
The value to be written.
valueType
Specifies the type that should be used when writing the value.
Exceptions
ExceptionDescription

A null reference (Nothing in Visual Basic) is passed to a method that does not accept it as a valid argument.

This is a usage error, i.e. it will never occur (the exception will not be thrown) in a correctly written program. Your code should not catch this exception.

The OPC UA operation has failed. This operation exception in uniformly used to allow common handling of various kinds of errors. The System.Exception.InnerException always contains information about the actual error cause.

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

Remarks

The method will attempt to convert the value to the type specified by valueType before writing. This may be needed because the OPC server will only accept values of proper type.

When the valueType is null, the component will determine the type of the Value attribute from the DataType and ValueRank attributes of the node first. This can have negative implication on the performance, and introduces a dependency of the value written on the behavior of the OPC server itself. Use a non-null valueType to prevent this.

You can obtain nodeDescriptor e.g. by calling one of the browsing methods on EasyUAClientCore object.

Example

.NET

// This example shows how to write a value into a single node, specifying a type explicitly.
//
// Reasons for specifying the type explicitly might be:
// - The data type in the server has subtypes, and the client therefore needs to pick the subtype to be written.
// - The data type that the server reports is incorrect.
// - Writing with an explicitly specified type is more efficient.
//
// For a selected subset of most common types, you can also use a different overload of the WriteValue method, and specify 
// a value from the TypeCode enumeration instead.

using System;
using OpcLabs.EasyOpc.UA;
using OpcLabs.EasyOpc.UA.OperationModel;

namespace UADocExamples._EasyUAClient
{
    partial class WriteValue
    {
        public static void Type()
        {
            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();

            // Modify value of a node
            try
            {
                client.WriteValue(
                    endpointDescriptor,
                    "nsu=http://test.org/UA/Data/ ;i=10221",
                    12345,
                    typeof(Int32));
            }
            catch (UAException uaException)
            {
                Console.WriteLine("*** Failure: {0}", uaException.GetBaseException().Message);
            }
        }
    }
}
' This example shows how to write a value into a single node, specifying a type explicitly.
'
' Reasons for specifying the type explicitly might be:
' - The data type in the server has subtypes, and the client therefore needs to pick the subtype to be written.
' - The data type that the server reports is incorrect.
' - Writing with an explicitly specified type is more efficient.
'
' For a selected subset of most common types, you can also use a different overload of the WriteValue method, and specify 
' a value from the TypeCode enumeration instead.

Imports System
Imports OpcLabs.EasyOpc.UA
Imports OpcLabs.EasyOpc.UA.OperationModel

Namespace _EasyUAClient
    Partial Friend Class WriteValue
        Public Shared Sub Type()

            ' 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()

            ' Modify value of a node
            Try
                client.WriteValue( _
                    endpointDescriptor, _
                    "nsu=http://test.org/UA/Data/ ;i=10221", _
                    12345, _
                    GetType(Int32))
            Catch uaException As UAException
                Console.WriteLine("*** Failure: {0}", uaException.GetBaseException.Message)
                Exit Sub
            End Try
        End Sub
    End Class
End Namespace
Requirements

Target Platforms: .NET Framework: Windows 10 (selected versions), Windows 11 (selected versions), Windows Server 2016, Windows Server 2022; .NET: Linux, macOS, Microsoft Windows

See Also