How to reset OPC UA Value to default value without changing it's TypeInfo?
Posted: 28 Mar 2021, 19:15
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:
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);