01/07/2022
Hi,
I have developed OPC UA SERVER application using CSharp(C#) language.
I am using Nodeset2 XML file for loading address space.
I am trying to write variable value after creation of address space. I am getting error in application.
Error: BadNotWritable
NodeSet XML:
<UAVariable NodeId="ns=1;i=1952" BrowseName="1:number" ParentNodeId="ns=1;i=1567" DataType="String">
Code:
public static void WriteNode(string identifier, string nodevalue, DateTime cTsDateTime)
{
WriteValue valueToWrite = new WriteValue();
uint identifiernumber = 0;
if (uint.TryParse(identifier, out identifiernumber))
{
valueToWrite.NodeId = new NodeId(Convert.ToUInt32(identifier), 2);
}
else
{
valueToWrite.NodeId = new NodeId("ns=2;s=" + identifier);
}
valueToWrite.AttributeId = Opc.Ua.Attributes.Value;
if (ParseString(nodevalue) == dataType.System_Boolean)
{
valueToWrite.Value.Value = Convert.ToBoolean(nodevalue);
}
else if (ParseString(nodevalue) == dataType.System_Int32)
{
valueToWrite.Value.Value = Convert.ToInt32(nodevalue);
}
else if (ParseString(nodevalue) == dataType.System_Int64)
{
valueToWrite.Value.Value = Convert.ToInt64(nodevalue);
}
else if (ParseString(nodevalue) == dataType.System_Double)
{
valueToWrite.Value.Value = Convert.ToDouble(nodevalue);
}
else if (ParseString(nodevalue) == dataType.System_String)
{
valueToWrite.Value.Value = nodevalue;
}
valueToWrite.Value.StatusCode = StatusCodes.Good;
valueToWrite.Value.SourceTimestamp = cTsDateTime;
var nodesToWrite = new WriteValueCollection();
nodesToWrite.Add(valueToWrite);
StatusCodeCollection results = null;
DiagnosticInfoCollection diagnosticInfos = null;
var operationContext = new Opc.Ua.Server.OperationContext(new RequestHeader(), Opc.Ua.Server.RequestType.Write);
Server.masterNodeManager.Write(operationContext, nodesToWrite, out results, out diagnosticInfos);
if (results[0].ToString().ToUpper() == "GOOD")
{
Logger._log4net.Info("Writing completed for " + identifier);
}
else
{
Logger._log4net.Error("Writing failure for " + identifier + " -" + results[0].ToString().ToUpper());
}
}
Please help me
05/30/2017
See https://reference.opcfoundatio.....s/5.10.4.4
For error codes.
1 Guest(s)