How to reset OPC UA Value to default value without changing it's TypeInfo?

Questions regarding the use of the UaExpert.

Moderator: uaexpert

Post Reply
Siggiii
Jr. Member
Jr. Member
Posts: 1
Joined: 28 Mar 2021, 19:12

How to reset OPC UA Value to default value without changing it's TypeInfo?

Post by Siggiii »

In my OPC UA client i want to have a function which sets the default value of a node. I am using the Opc.Ua.TypeInfo.GetDefaultValue() function for that. But after setting the value for a string, the value is null. When it's null I can't change it's value in UaExpert.

Reading the node after setting it, it has the typeInfo null even though the DataValue I wrote has the TypeInfo string. Is there a way to set the default value with the right typeInfo/beeing still able to change the node values in UA Expert.

This is the code I use:

Code: Select all

var nodeId = new NodeId(nodeIdString);
string value = null;

var variant = new Variant(value);
var dataValue = new DataValue(variant);

// Create value to write
var writeValue = new WriteValue()
{
    NodeId = nodeId,
    AttributeId = Attributes.Value,
    Value = dataValue
};
var request = WriteValue.Validate(writeValue);
var writeValueCollection = new WriteValueCollection(1);
writeValueCollection.Add(writeValue);

StatusCodeCollection statusCodes;
DiagnosticInfoCollection diagnosticInfos;
var responseHeader = _session.Write(null, writeValueCollection, out statusCodes, out diagnosticInfos);
var val = _session.ReadValue(nodeId);

User avatar
Support Team
Hero Member
Hero Member
Posts: 3064
Joined: 18 Mar 2011, 15:09

Re: How to reset OPC UA Value to default value without changing it's TypeInfo?

Post by Support Team »

Hello,

the UaExpert (likewise any other UA Client) must know the data type of the value before writing to it, which seems logical so some respect. It is the think first before you talk approach. However the way to obtain the type before writing might be different in different client side implementation. On a good day a client knows what value (and type) to write, because it is some process data representative.
The UaExpert (in contrast to other UA Clients) has a different approach, it is reading (and displaying) values of nodes only. And only for the (rare) cases where the UAExpert has received some value for a particular node already, the UaExpert may be able to write the value of this node.

In OPC UA there is a clear way to describe information, and a concrete node instance either has a value, or has "bad" quality status code. A good server should present it#s nodes with correct type information and all its instances with values (or bad status). If you come accross nodes that have no type information or have "null" values, you better not write to this values unless you are absolutely sure which type the value has. However, "null" is not a good default value.
Best regards
Unified Automation Support Team

Post Reply