QuickOPC User's Guide and Reference
ValueType Property (UAWriteArgumentsBase)
Example 



OpcLabs.EasyOpcUA Assembly > OpcLabs.EasyOpc.UA.OperationModel Namespace > UAWriteArgumentsBase Class : ValueType Property
Specifies the type that should be used when writing the Value attribute.
Syntax
'Declaration
 
<DefaultValueAttribute(Mono.Cecil.CustomAttributeArgument)>
<IgnoreDataMemberAttribute()>
<XmlIgnoreAttribute()>
Public Property ValueType As Type
'Usage
 
Dim instance As UAWriteArgumentsBase
Dim value As Type
 
instance.ValueType = value
 
value = instance.ValueType
[DefaultValue(Mono.Cecil.CustomAttributeArgument)]
[IgnoreDataMember()]
[XmlIgnore()]
public Type ValueType {get; set;}
[DefaultValue(Mono.Cecil.CustomAttributeArgument)]
[IgnoreDataMember()]
[XmlIgnore()]
public:
property Type^ ValueType {
   Type^ get();
   void set (    Type^ value);
}

Property Value

The type that should be used when writing the Value attribute.
Remarks

The value of this property is not used when the UAAttributeArguments.AttributeId is other than OpcLabs.EasyOpc.UA.UAAttributeId.Value.

A null value in this property means that 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.

This method or property does not throw any exceptions, aside from execution exceptions such as System.Threading.ThreadAbortException or System.OutOfMemoryException.

Example

.NET

// This example shows how to write values into 3 nodes at once, specifying a type explicitly. It tests for success of each 
// write and displays the exception message in case of failure.
//
// 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 reports is incorrect.
// - Writing with an explicitly specified type is more efficient.
//
// Alternative ways of specifying the type are using the ValueTypeCode or ValueTypeFullName properties.

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

namespace UADocExamples._EasyUAClient
{
    partial class WriteMultipleValues
    {
        public static void ValueType()
        {
            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
            OperationResult[] operationResultArray = client.WriteMultipleValues(new[]
                {
                    new UAWriteValueArguments(endpointDescriptor, 
                        "nsu=http://test.org/UA/Data/ ;i=10221", 23456) 
                        {ValueType = typeof(Int32)},    // here is the type explicitly specified
                    new UAWriteValueArguments(endpointDescriptor,
                        "nsu=http://test.org/UA/Data/ ;i=10226", "This string cannot be converted to Double")
                        {ValueType = typeof(Double)},    // here is the type explicitly specified
                    new UAWriteValueArguments(endpointDescriptor,
                        "nsu=http://test.org/UA/Data/ ;s=UnknownNode", "ABC")
                        {ValueType = typeof(string)}    // here is the type explicitly specified
                });

            for (int i = 0; i < operationResultArray.Length; i++)
                if (operationResultArray[i].Succeeded)
                    Console.WriteLine("Result {0}: success", i);
                else
                    Console.WriteLine("Result {0}: {1}", i, operationResultArray[i].Exception.GetBaseException().Message);
        }
    }
}
' This example shows how to write values into 3 nodes at once, specifying a type explicitly. It tests for success of each 
' write and displays the exception message in case of failure.
'
' 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 reports is incorrect.
' - Writing with an explicitly specified type is more efficient.
'
' Alternative ways of specifying the type are using the ValueTypeCode or ValueTypeFullName properties.

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

Namespace _EasyUAClient
    Partial Friend Class WriteMultipleValues
        Public Shared Sub ValueType()

            ' 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
            Dim operationResultArray() As OperationResult = client.WriteMultipleValues(New UAWriteValueArguments() _
                { _
                    New UAWriteValueArguments(endpointDescriptor, _
                        "nsu=http://test.org/UA/Data/ ;i=10221", 23456) _
                        With {.ValueType = GetType(Int32)}, _
                    New UAWriteValueArguments(endpointDescriptor, _
                        "nsu=http://test.org/UA/Data/ ;i=10226", "This string cannot be converted to Double") _
                        With {.ValueType = GetType(Double)}, _
                    New UAWriteValueArguments(endpointDescriptor, _
                        "nsu=http://test.org/UA/Data/ ;s=UnknownNode", "ABC") _
                        With {.ValueType = GetType(String)} _
                } _
             )

            For i As Integer = 0 To operationResultArray.Length - 1
                If operationResultArray(i).Succeeded Then
                    Console.WriteLine("Result {0}: success", i)
                Else
                    Console.WriteLine("Result {0}: {1}", i, operationResultArray(i).Exception.GetBaseException().Message)
                End If
            Next i
        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