Updating Server Object Property values|OPC UA Implementation: Stacks, Tools, and Samples|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
Updating Server Object Property values
Avatar
Ray Verhoeff
Suffern, New York
New Member
Members
Forum Posts: 2
Member Since:
11/21/2017
sp_UserOfflineSmall Offline
1
04/07/2020 - 18:48
sp_Permalink sp_Print

In building an OPC UA Server, what technique should be used to update properties under the Server Object? There are properties which are probably static but are never set (such as LocalTime) and others which should be updated occasionally by the running OPC UA Server (such as ServiceLevel). I tried using WriteAttribute on the properties but this fails with a write access error. This stands to reason because the Server Object properties are in UA's "0" namespace. I have figured out how to create and populate my own properties under VendorServerInfo but these properties are in my namespace.

Avatar
Randy Armstrong
Admin
Forum Posts: 1445
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
2
04/09/2020 - 05:42
sp_Permalink sp_Print

The answer depends on the SDK you are using.

If you are using the .NET codebase you lookup the Node object in memory and update that object directly.

Avatar
Ray Verhoeff
Suffern, New York
New Member
Members
Forum Posts: 2
Member Since:
11/21/2017
sp_UserOfflineSmall Offline
3
04/12/2020 - 17:21
sp_Permalink sp_Print

I am using the .NET SDK. You're right! I was able to look up a Node and then set its value directly. I had already tried this before posting my question but it turns out I was experimenting with a complex data type and setting its value the wrong way. I will elaborate in case others run into this problem. I should have started with simpler stuff. For example, this works:

BaseVariableState bvs = (BaseVariableState)Server.DiagnosticsNodeManager.FindPredefinedNode(VariableIds.Server_ServiceLevel, typeof(BaseVariableState));
bvs.Value = 200;

Server.ServiceLevel is a simple data type (a byte) so setting its value is straightforward. What I had attempted first was to set Server.ServerStatus.State to something other than the default (Running). I noticed that the ServerObjectState type has a ServerStatus member, so I tried:

ServerObjectState serverState = (ServerObjectState)Server.DiagnosticsNodeManager.FindPredefinedNode(ObjectIds.Server, typeof(ServerObjectState));
serverState.ServerStatus.State.Value = ServerState.Suspended;

This doesn't work. It appears that something in the SDK overwrites this value because the client never sees the change. I then tried accessing the State member directly:

BaseVariableState bvs = (BaseVariableState)Server.DiagnosticsNodeManager.FindPredefinedNode(VariableIds.Server_ServerStatus_State, typeof(BaseVariableState));
bvs.Value = ServerState.Suspended;

This doesn't work either. Finally, I tried accessing the Server.ServerStatus structure:

BaseVariableState bvs = (BaseVariableState)Server.DiagnosticsNodeManager.FindPredefinedNode(VariableIds.Server_ServerStatus, typeof(BaseVariableState));
ServerStatusDataType stat = bvs.Value as ServerStatusDataType;
stat.State = ServerState.Suspended;

This does work! Armed with this know-now, I tackled my other interest: Server.LocalTime. Here's what I did:

BaseVariableState bvs= (BaseVariableState)server.DiagnosticsNodeManager.FindPredefinedNode(VariableIds.Server_LocalTime, typeof(BaseVariableState));
bvs.Value = Utils.GetTimeZoneInfo(); // returns TimeZoneDataType

This works too. Thank you for your help!

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