OPC Studio User's Guide and Reference
WriteValue Method (_EasyUAClient)
Example 



View with Navigation Tools
OpcLabs.EasyOpcUA Assembly > OpcLabs.EasyOpc.UA.ComTypes Namespace > _EasyUAClient Interface : WriteValue Method
Endpoint descriptor. Identifies the OPC-UA server.

The value represents an OPC UA endpoint descriptor string. Any string can be passed to this parameter (i.e. will not cause System.ArgumentException), but not all values make sense and will work when an operation using them is attempted. The OPC UA endpoint descriptor string is typically the URL of the server endpoint.

The value of this parameter can be null (Nothing in Visual Basic).

Node descriptor. Identifies the node in OPC server's address space.

The value of this parameter can be null (Nothing in Visual Basic).

The value to be written.

The value of this parameter can be null (Nothing in Visual Basic).

Writes value into a Value attribute of a node, using an endpoint descriptor and a node Id.
Syntax
'Declaration
 
Sub WriteValue( _
   ByVal endpointDescriptorString As String, _
   ByVal nodeDescriptorString As String, _
   ByVal value As Object _
) 
 
'Usage
 
Dim instance As _EasyUAClient
Dim endpointDescriptorString As String
Dim nodeDescriptorString As String
Dim value As Object
 
instance.WriteValue(endpointDescriptorString, nodeDescriptorString, value)

Parameters

endpointDescriptorString
Endpoint descriptor. Identifies the OPC-UA server.

The value represents an OPC UA endpoint descriptor string. Any string can be passed to this parameter (i.e. will not cause System.ArgumentException), but not all values make sense and will work when an operation using them is attempted. The OPC UA endpoint descriptor string is typically the URL of the server endpoint.

The value of this parameter can be null (Nothing in Visual Basic).

nodeDescriptorString
Node descriptor. Identifies the node in OPC server's address space.

The value of this parameter can be null (Nothing in Visual Basic).

value
The value to be written.

The value of this parameter can be null (Nothing in Visual Basic).

Remarks

You can obtain nodeDescriptorString e.g. by calling one of the browsing methods on OpcLabs.EasyOpc.UA.EasyUAClientCore object.

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 method overload that allows to specify the attribute type or type code to prevent this.

This member or type is for use from COM. It is not meant to be used from .NET or Python. Refer to the corresponding .NET member or type instead, if you are developing in .NET or Python.

Example

COM

COM

// This example shows how to write a value into a single node.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// 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.

#include "stdafx.h"    // Includes "QuickOpc.h", and other commonly used files
#include "WriteValue.h"

namespace _EasyUAClient
{
    void WriteValue::Main()
    {
        // Initialize the COM library
        CoInitializeEx(NULL, COINIT_MULTITHREADED);
        {
            // Instantiate the client object
            _EasyUAClientPtr ClientPtr(__uuidof(EasyUAClient));

            // Perform the operation
            ClientPtr->WriteValue(
                //L"http://opcua.demo-this.com:51211/UA/SampleServer", 
                L"opc.tcp://opcua.demo-this.com:51210/UA/SampleServer",
                L"nsu=http://test.org/UA/Data/ ;i=10221",
                12345);
        }
         // Release all interface pointers BEFORE calling CoUninitialize()
        CoUninitialize();
    }
}
// This example shows how to write a value into a single node that is of type ByteString.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// 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.

#include "stdafx.h"    // Includes "QuickOpc.h", and other commonly used files
#include <atlcom.h>
#include <atlsafe.h>
#include "WriteValue.h"

namespace _EasyUAClient
{
    void WriteValue::ByteString()
    {
        // Initialize the COM library
        CoInitializeEx(NULL, COINIT_MULTITHREADED);
        {
            // Instantiate the client object
            _EasyUAClientPtr ClientPtr(__uuidof(EasyUAClient));

            // Prepare the value to be written
            CComSafeArray<BYTE> array(5);
            array.SetAt(0, 11);
            array.SetAt(1, 22);
            array.SetAt(2, 33);
            array.SetAt(3, 44);
            array.SetAt(4, 55);

            const CComVariant value(array);
            
            // Perform the operation
            ClientPtr->WriteValue(
                //L"http://opcua.demo-this.com:51211/UA/SampleServer", 
                L"opc.tcp://opcua.demo-this.com:51210/UA/SampleServer",
                L"nsu=http://test.org/UA/Data/ ;i=10230",
                value);
        }
        // Release all interface pointers BEFORE calling CoUninitialize()
        CoUninitialize();
    }
}
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