How to query the access rights of a node correctly

Questions regarding the use of the .NET SDK 2.0 for Server or Client development or integration into customer products ...

Moderator: uasdknet

Post Reply
stefan.roth
Jr. Member
Jr. Member
Posts: 3
Joined: 06 Jun 2014, 09:31

How to query the access rights of a node correctly

Post by stefan.roth »

I have a question concerning the query of the AccessLevel of a node. While dealing with a VariableNode I can query it's access level using the AccessLevel-property. Anyway I want to ask a node whether it is writable, e.g. whether some flag "writable" is set. I would have expexted an enum type and querying it with the Enum.HasFlags(AccessLevels.CurrentWrite) function, but all I find is a dumb byte. That's probably nailed down by the OPC UA spec. I wonder whether there's some convenient method for me to ask a node whether it's writable or not. Otherwise my code looks like the following mess:

Code: Select all

VariableNode dataVarNode;

if ((dataVarNode.AccessLevel == AccessLevels.CurrentWrite) ||
    (dataVarNode.AccessLevel == AccessLevels.CurrentReadOrWrite) ||
    (dataVarNode.AccessLevel == AccessLevels.HistoryWrite) ||
    (dataVarNode.AccessLevel == AccessLevels.HistoryReadOrWrite))
{
...
}
Thanks for any advice on how to solve this in a more clever way!

User avatar
Support Team
Hero Member
Hero Member
Posts: 3072
Joined: 18 Mar 2011, 15:09

Re: How to query the access rights of a node correctly

Post by Support Team »

Hello,

You can use a "bitwise and".

Code: Select all

            // check general access.
            if ((dataVarNode.AccessLevel & AccessLevels.CurrentWrite) == 0)
            {
                return StatusCodes.BadNotWritable;
            }
Best regards
Support Team

stefan.roth
Jr. Member
Jr. Member
Posts: 3
Joined: 06 Jun 2014, 09:31

Re: How to query the access rights of a node correctly

Post by stefan.roth »

Thanks for the quick reply. I therefore assume that a node which is marked as HistoryWrite isn't meant to be writable for the current value on the fly? That's odd, but perhaps desired behavior. I'm ok with that.

I have a feature request though: Could you please skip the annoying byte definition of the access level in some upcoming version and exchange this with an enum type marked with the flags attribute? Like this it's quite easy to ask the type with the HasFlags method thus avoiding error prone bitwise comparison.

Thanks and reagards,

Stefan

Post Reply