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



OpcLabs.EasyOpcUA Assembly > OpcLabs.EasyOpc.UA.ComTypes Namespace > _EasyUAClient Interface : Write 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).

OpcLabs.EasyOpc.UA.UAAttributeData. Value of an attribute, together with status code and timestamps, to be written.

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

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

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).

attributeData
OpcLabs.EasyOpc.UA.UAAttributeData. Value of an attribute, together with status code and timestamps, to be written.

The value of this parameter cannot 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.

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

// This example shows how to write data (a value, timestamps and status code) into a single attribute of a node.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// OPC client and subscriber examples in PHP on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-PHP .
// 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.

$GoodOrSuccess = 0;

// Instantiate the client object
$Client = new COM("OpcLabs.EasyOpc.UA.EasyUAClient");

// Modify data of a node's attribute
$StatusCode = new COM("OpcLabs.EasyOpc.UA.UAStatusCode");
$StatusCode->Severity = $GoodOrSuccess;
$AttributeData = new COM("OpcLabs.EasyOpc.UA.UAAttributeData");
$AttributeData->Value = 12345;
$AttributeData->StatusCode = $StatusCode;
$AttributeData->SourceTimestamp = (time() - 25569)/86400.0;

// Perform the operation
try
{
    $Client->Write(
        //"http://opcua.demo-this.com:51211/UA/SampleServer", 
        "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer", 
        "nsu=http://test.org/UA/Data/ ;i=10221", 
        $AttributeData);
    // The target server may not support this, and in such case a failure will occur.
}
catch (com_exception $e)
{
    printf("*** Failure: %s\n", $e->getMessage());
}
REM This example shows how to write data (a value, timestamps and status code)
REM into a single attribute of a node.
REM
REM Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
REM OPC client and subscriber examples in Visual Basic on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-VB .
REM Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
REM a commercial license in order to use Online Forums, and we reply to every post.

Public Sub Write_Main_Command_Click()
    OutputText = ""

    Const GoodOrSuccess = 0

    ' Instantiate the client object
    Dim Client As New EasyUAClient

    ' Modify data of a node's attribute
    Dim StatusCode As New UAStatusCode
    StatusCode.Severity = GoodOrSuccess
    Dim AttributeData As New UAAttributeData
    AttributeData.SetValue 12345
    Set AttributeData.StatusCode = StatusCode
    AttributeData.SourceTimestamp = Now()
    
    ' Perform the operation
    On Error Resume Next
    Call Client.Write("opc.tcp://opcua.demo-this.com:51210/UA/SampleServer", "nsu=http://test.org/UA/Data/ ;i=10221", AttributeData)
    If Err.Number <> 0 Then
        OutputText = OutputText & "*** Failure: " & Err.Source & ": " & Err.Description & vbCrLf
        Exit Sub
    End If
    On Error GoTo 0
End Sub
Rem This example shows how to write data (a value, timestamps and status code) into a single attribute of a node.
Rem
Rem Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
Rem OPC client and subscriber examples in VBScript on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-VBScript .
Rem Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
Rem a commercial license in order to use Online Forums, and we reply to every post.

Option Explicit

Const GoodOrSuccess = 0

' Instantiate the client object
Dim Client: Set Client = CreateObject("OpcLabs.EasyOpc.UA.EasyUAClient")

' Modify data of a node's attribute
Dim StatusCode: Set StatusCode = CreateObject("OpcLabs.EasyOpc.UA.UAStatusCode")
StatusCode.Severity = GoodOrSuccess
Dim AttributeData: Set AttributeData = CreateObject("OpcLabs.EasyOpc.UA.UAAttributeData")
AttributeData.Value = 12345
AttributeData.StatusCode = StatusCode
AttributeData.SourceTimestamp = Now

' Perform the operation
On Error Resume Next
Client.Write "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer", "nsu=http://test.org/UA/Data/ ;i=10221", _
             AttributeData
' The target server may not support this, and in such case a failure will occur.
If Err.Number <> 0 Then
    WScript.Echo "*** Failure: " & Err.Source & ": " & Err.Description
    WScript.Quit
End If
On Error Goto 0
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