// This example shows how to write a value into a single node, specifying a type code 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 reports is incorrect.
// - Writing with an explicitly specified type is more efficient.
//
// TypeCode is easy to use, but it does not cover all possible types. It is also possible to specify the .NET Type, using
// a different overload of the WriteValue method.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// OPC client and subscriber examples in C# on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-CSharp .
// 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.
using System;
using OpcLabs.EasyOpc.UA;
using OpcLabs.EasyOpc.UA.OperationModel;
namespace UADocExamples._EasyUAClient
{
partial class WriteValue
{
public static void TypeCode()
{
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();
Console.WriteLine("Modifying value of a node...");
try
{
client.WriteValue(
endpointDescriptor,
"nsu=http://test.org/UA/Data/ ;i=10221",
12345,
System.TypeCode.Int32);
}
catch (UAException uaException)
{
Console.WriteLine($"*** Failure: {uaException.GetBaseException().Message}");
return;
}
Console.WriteLine("Finished.");
}
}
}
# This example shows how to write a value into a single node, specifying a type code 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 reports is incorrect.
# - Writing with an explicitly specified type is more efficient.
#
# TypeCode is easy to use, but it does not cover all possible types. It is also possible to specify the .NET Type, using
# a different overload of the WriteValue method.
#
# Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
# OPC client and subscriber examples in PowerShell on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-PowerShell .
# 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.
#requires -Version 5.1
using namespace OpcLabs.EasyOpc.UA
using namespace OpcLabs.EasyOpc.UA.OperationModel
# The path below assumes that the current directory is [ProductDir]/Examples-NET/PowerShell/Windows .
Add-Type -Path "../../../Components/Opclabs.QuickOpc/net472/OpcLabs.EasyOpcUA.dll"
Add-Type -Path "../../../Components/Opclabs.QuickOpc/net472/OpcLabs.EasyOpcUAComponents.dll"
[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.
$client = New-Object EasyUAClient
Write-Host "Modifying value of a node..."
try {
[IEasyUAClientExtension]::WriteValue($client,
$endpointDescriptor,
"nsu=http://test.org/UA/Data/ ;i=10221",
12345,
[System.TypeCode]::Int32)
}
catch [UAException] {
Write-Host "*** Failure: $($PSItem.Exception.GetBaseException().Message)"
return
}
Write-Host "Finished."
' This example shows how to write a value into a single node, specifying a type code 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 reports is incorrect.
' - Writing with an explicitly specified type is more efficient.
'
' TypeCode is easy to use, but it does not cover all possible types. It is also possible to specify the .NET Type, using
' a different overload of the WriteValue method.
'
' Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
' OPC client and subscriber examples in VB.NET on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-VBNET .
' 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.
Imports OpcLabs.EasyOpc.UA
Imports OpcLabs.EasyOpc.UA.OperationModel
Namespace _EasyUAClient
Partial Friend Class WriteValue
Public Shared Sub TypeCode()
' 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, _
System.TypeCode.Int32)
Catch uaException As UAException
Console.WriteLine("*** Failure: {0}", uaException.GetBaseException.Message)
Exit Sub
End Try
End Sub
End Class
End Namespace
// This example shows how to write a value into a single node, specifying a type code 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 reports is incorrect.
// - Writing with an explicitly specified type is more efficient.
//
// TypeCode is easy to use, but it does not cover all possible types. It is also possible
// to specify the .NET Type, using a different overload of the WriteValue method.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// OPC client and subscriber examples in Object Pascal (Delphi) on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-OP .
// 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.
class procedure WriteValue.TypeCode;
var
Arguments: OleVariant;
Client: OpcLabs_EasyOpcUA_TLB._EasyUAClient;
EndpointDescriptorUrlString: string;
WriteResult: _UAWriteResult;
WriteValueArguments1: _UAWriteValueArguments;
Results: OleVariant;
begin
EndpointDescriptorUrlString :=
//'http://opcua.demo-this.com:51211/UA/SampleServer';
//'https://opcua.demo-this.com:51212/UA/SampleServer/';
'opc.tcp://opcua.demo-this.com:51210/UA/SampleServer';
// Prepare the arguments
WriteValueArguments1 := CoUAWriteValueArguments.Create;
WriteValueArguments1.EndpointDescriptor.UrlString := EndpointDescriptorUrlString;
WriteValueArguments1.NodeDescriptor.NodeId.ExpandedText := 'nsu=http://test.org/UA/Data/ ;i=10221';
WriteValueArguments1.Value := 12345;
WriteValueArguments1.ValueTypeCode := TypeCode_Int32; // here is the type explicitly specified
Arguments := VarArrayCreate([0, 0], varVariant);
Arguments[0] := WriteValueArguments1;
// Instantiate the client object
Client := CoEasyUAClient.Create;
// Modify value of node
TVarData(Results).VType := varArray or varVariant;
TVarData(Results).VArray := PVarArray(Client.WriteMultipleValues(Arguments));
WriteResult := IUnknown(Results[0]) as _UAWriteResult;
if not WriteResult.Succeeded then
WriteLn('*** Failure: ', WriteResult.Exception.GetBaseException.Message);
VarClear(Results);
VarClear(Arguments);
end;
// This example shows how to write a value into a single node, specifying a type code 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 reports is incorrect.
// - Writing with an explicitly specified type is more efficient.
//
// TypeCode is easy to use, but it does not cover all possible types. It is also possible
// to specify the .NET Type, using a different overload of the WriteValue method.
//
// 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.
const TypeCode_Int32 = 9;
$EndpointDescriptor =
//"http://opcua.demo-this.com:51211/UA/SampleServer";
//"https://opcua.demo-this.com:51212/UA/SampleServer/";
"opc.tcp://opcua.demo-this.com:51210/UA/SampleServer";
// Prepare the arguments
$WriteValueArguments1 = new COM("OpcLabs.EasyOpc.UA.OperationModel.UAWriteValueArguments");
$WriteValueArguments1->EndpointDescriptor->UrlString = $EndpointDescriptor;
$WriteValueArguments1->NodeDescriptor->NodeId->ExpandedText = "nsu=http://test.org/UA/Data/ ;i=10221";
$WriteValueArguments1->Value = 12345;
$WriteValueArguments1->ValueTypeCode = TypeCode_Int32; // here is the type explicitly specified
$arguments[0] = $WriteValueArguments1;
// Instantiate the client object
$Client = new COM("OpcLabs.EasyOpc.UA.EasyUAClient");
// Modify value of node
$results = $Client->WriteMultipleValues($arguments);
$WriteResult = $results[0];
if (!$WriteResult->Succeeded)
printf("*** Failure: %s\n", $WriteResult->Exception->GetBaseException()->Message);
Rem This example shows how to write a value into a single node, specifying a type code explicitly.
Rem
Rem Reasons for specifying the type explicitly might be:
Rem - The data type in the server has subtypes, and the client therefore needs to pick the subtype to be written.
Rem - The data type that the reports is incorrect.
Rem - Writing with an explicitly specified type is more efficient.
Rem
Rem TypeCode is easy to use, but it does not cover all possible types. It is also possible to specify the .NET Type, using
Rem a different overload of the WriteValue method.
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 TypeCode_Int32 = 9
Dim endpointDescriptor: endpointDescriptor = _
"opc.tcp://opcua.demo-this.com:51210/UA/SampleServer"
'"http://opcua.demo-this.com:51211/UA/SampleServer"
'"https://opcua.demo-this.com:51212/UA/SampleServer/"
' Instantiate the client object
Dim Client: Set Client = CreateObject("OpcLabs.EasyOpc.UA.EasyUAClient")
' Prepare the arguments
Dim WriteValueArguments1: Set WriteValueArguments1 = CreateObject("OpcLabs.EasyOpc.UA.OperationModel.UAWriteValueArguments")
WriteValueArguments1.EndpointDescriptor.UrlString = endpointDescriptor
WriteValueArguments1.NodeDescriptor.NodeId.ExpandedText = "nsu=http://test.org/UA/Data/ ;i=10221"
WriteValueArguments1.Value = 12345
WriteValueArguments1.ValueTypeCode = TypeCode_Int32
Dim arguments(0)
Set arguments(0) = WriteValueArguments1
' Modify value of a node
Dim results: results = Client.WriteMultipleValues(arguments)
Dim WriteResult: Set WriteResult = results(0)
If Not WriteResult.Succeeded Then
WScript.Echo "*** Failure: " & WriteResult.Exception.GetBaseException().Message
End If
REM This example shows how to write a value into a single node, specifying a type code explicitly.
REM
REM Reasons for specifying the type explicitly might be:
REM - The data type in the server has subtypes, and the client therefore needs to pick the subtype to be written.
REM - The data type that the reports is incorrect.
REM - Writing with an explicitly specified type is more efficient.
REM
REM TypeCode is easy to use, but it does not cover all possible types. It is also possible to specify the .NET Type, using
REM a different overload of the WriteValue method.
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 WriteValue_TypeCode_Command_Click()
OutputText = ""
Const TypeCode_Int32 = 9
Dim endpointDescriptor As String
'endpointDescriptor = "http://opcua.demo-this.com:51211/UA/SampleServer"
'endpointDescriptor = "https://opcua.demo-this.com:51212/UA/SampleServer/"
endpointDescriptor = "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer"
' Instantiate the client object
Dim Client As New EasyUAClient
' Prepare the arguments
Dim WriteValueArguments1 As New UAWriteValueArguments
WriteValueArguments1.endpointDescriptor.UrlString = endpointDescriptor
WriteValueArguments1.nodeDescriptor.NodeId.expandedText = "nsu=http://test.org/UA/Data/ ;i=10221"
WriteValueArguments1.SetValue 12345
WriteValueArguments1.ValueTypeCode = TypeCode_Int32
Dim arguments(0) As Variant
Set arguments(0) = WriteValueArguments1
' Modify value of node
Dim results As Variant
results = Client.WriteMultipleValues(arguments)
' Display results
Dim Result As UAWriteResult: Set Result = results(0)
If Not Result.Succeeded Then
OutputText = OutputText & "*** Failure: " & Result.Exception.GetBaseException().Message & vbCrLf
End If
End Sub
# This example shows how to write a value into a single node, specifying a type code 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 reports is incorrect.
# - Writing with an explicitly specified type is more efficient.
#
# TypeCode is easy to use, but it does not cover all possible types. It is also possible to specify the .NET Type, using
# a different overload of the WriteValue method.
#
# Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
# OPC client and subscriber examples in Python on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-Python .
# 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.
# The QuickOPC package is needed. Install it using "pip install opclabs_quickopc".
import opclabs_quickopc
# Import .NET namespaces.
from System import *
from OpcLabs.EasyOpc.UA import *
from OpcLabs.EasyOpc.UA.OperationModel import *
endpointDescriptor = 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.
client = EasyUAClient()
print('Modifying value of a node...')
try:
IEasyUAClientExtension.WriteValue(client,
endpointDescriptor,
UANodeDescriptor('nsu=http://test.org/UA/Data/ ;i=10221'),
12345,
TypeCode.Int32)
except UAException as uaException:
print('*** Failure: ' + uaException.GetBaseException().Message)
exit()
print('Finished.')