01/07/2022
Hi,
I have developed OPC UA SERVER application using CSharp(C#) language.
I want to update variable values in OPC UA address space after loading.
How to implement it?
I am trying following method but it is not working
internal static void writeNode(string identifier, string nodevalue, DateTime cTsDateTime)
{
try
{
// Write the configured nodes
WriteValueCollection nodesToWrite = new WriteValueCollection();
WriteValue intWriteVal = new WriteValue();
uint identifiernumber = 0;
if (uint.TryParse(identifier, out identifiernumber))
{
intWriteVal.NodeId = new NodeId(Convert.ToUInt32(identifier), 2);
}
else
{
intWriteVal.NodeId = new NodeId("ns=2;s=" + identifier);
}
intWriteVal.AttributeId = Opc.Ua.Attributes.Value;
intWriteVal.Value = new DataValue();
if (ParseString(nodevalue) == dataType.System_Boolean)
{
intWriteVal.Value.Value = Convert.ToBoolean(nodevalue);
}
else if (ParseString(nodevalue) == dataType.System_Int32)
{
intWriteVal.Value.Value = Convert.ToInt32(nodevalue);
}
else if (ParseString(nodevalue) == dataType.System_Int64)
{
intWriteVal.Value.Value = Convert.ToInt64(nodevalue);
}
else if (ParseString(nodevalue) == dataType.System_Double)
{
intWriteVal.Value.Value = Convert.ToDouble(nodevalue);
}
else if (ParseString(nodevalue) == dataType.System_String)
{
intWriteVal.Value.Value = nodevalue;
}
intWriteVal.Value.SourceTimestamp = cTsDateTime;
nodesToWrite.Add(intWriteVal);
//// Write the node attributes
StatusCodeCollection results = new StatusCodeCollection();
DiagnosticInfoCollection diagnosticInfos = new DiagnosticInfoCollection();
RequestHeader requestheader = new RequestHeader();
requestheader.AuthenticationToken = new NodeId(Convert.ToUInt32(identifier), 2);
Server.Write(requestheader, nodesToWrite, out results, out diagnosticInfos);
}
1 Guest(s)