OPC Studio User's Guide and Reference
ValueType Property (_UAWriteArguments)
Example 



OpcLabs.EasyOpcUA Assembly > OpcLabs.EasyOpc.UA.OperationModel.ComTypes Namespace > _UAWriteArguments Interface : ValueType Property
Specifies the type that should be used when writing the Value attribute.
Syntax
'Declaration
 
<CanBeNullAttribute()>
Property ValueType As Type
'Usage
 
Dim instance As _UAWriteArguments
Dim value As Type
 
instance.ValueType = value
 
value = instance.ValueType
[CanBeNull()]
Type ValueType {get; set;}
[CanBeNull()]
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 OpcLabs.EasyOpc.UA.OperationModel.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.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .

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.
'
' Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .

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