How to write value for OPC UA Address Space in OPC UA Server?|OPC UA Standard|Forum|OPC Foundation

Avatar
Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
Lost password?
sp_Feed sp_PrintTopic sp_TopicIcon
How to write value for OPC UA Address Space in OPC UA Server?
Avatar
OPCUA USER
Member
Members
Forum Posts: 53
Member Since:
01/07/2022
sp_UserOfflineSmall Offline
1
05/12/2024 - 22:29
sp_Permalink sp_Print

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);

}

Avatar
Randy Armstrong
Admin
Forum Posts: 1578
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
2
05/14/2024 - 19:16
sp_Permalink sp_Print

You should be reading the NodeId from the Server along with the DataType and ValueRank.

This tells you what you are allowed to Write.

If you get an error you need to say what the error is.

Forum Timezone: America/Phoenix
Most Users Ever Online: 510
Currently Online:
Guest(s) 47
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Forum Stats:
Groups: 2
Forums: 10
Topics: 1444
Posts: 4887