Avatar

Please consider registering
guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed Topic RSS sp_TopicIcon
How to modify node attributes
November 1, 2017
16:42, EET
Avatar
Thomas Reuther
Member
Members
Forum Posts: 33
Member Since:
September 18, 2017
sp_UserOfflineSmall Offline

Hi there,

I am using Java-SDK 2.3.2 EVAL. I want to modify node attributes other than value.

My node set file looks like this:

<UAVariable DataType="Boolean" NodeId="ns=1;i=6009" BrowseName="1:VariableAttributes" UserAccessLevel="3" AccessLevel="3" WriteMask="594551" UserWriteMask="594551">
<DisplayName>VariableAttributes</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">i=63</Reference>
<Reference ReferenceType="HasComponent" IsForward="false">ns=1;i=5004</Reference>
</References>
</UAVariable>

WriteMask/UserWriteMask are set to modify BrowseName, DisplayName, Description, DataType, ValueRank, ArrayDimensions, AccessLevel, UserAccessLevel, MinimumSamplingInterval and Historizing.
When I upload this node set then the nodes are there but WriteMask/UserWriteMask are set to ‘0’.

Then I implement IoManagerListener. First I implement onGetUserWriteMask():

@Override
public EnumSet<WriteAccess> onGetUserWriteMask(ServiceContext serviceContext, NodeId nodeId, UaNode node) {
String sNodeId = nodeId.toString();
switch(sNodeId) {
case "ns=2;i=6009": // VariableAttributes
return writableAttributes;
}
return EnumSet.noneOf(WriteAccess.class);
}

Where writableAttributes is defined as:

private final EnumSet<WriteAccess> writableAttributes = EnumSet.of(WriteAccess.BrowseName, WriteAccess.DisplayName, WriteAccess.Description, WriteAccess.DataType, WriteAccess.ValueRank, WriteAccess.ArrayDimensions, WriteAccess.AccessLevel, WriteAccess.UserAccessLevel, WriteAccess.MinimumSamplingInterval, WriteAccess.Historizing);

But the values of WriteMask/UserWriteMask are still ‘0’.
Then I implement onReadNonValue() as:

@Override
public boolean onReadNonValue(ServiceContext serviceContext, NodeId nodeId, UaNode node,
UnsignedInteger attributeId, DataValue dataValue) throws StatusException {
String sNodeId = nodeId.toString();
switch (sNodeId) {
case "ns=2;i=6009":
if (attributeId.intValue() == Attribute.WriteMask.toInt() ||
attributeId.intValue() == Attribute.UserWriteMask.toInt()) {
dataValue.setValue(new Variant(WriteAccess.getMask(writableAttributes)));
return true;
}
}
return false;
}

Now the values of WriteMask/UserWriteMask are ‘594551’.
With the debugger I can assure that my methods are executed.

When I use a client program (a user defined CTT script) to modify the attribute description of this node I get a BadNotWritable status code.
Then I implement the onWriteNonValue() method:

@Override
public boolean onWriteNonValue(ServiceContext serviceContext, NodeId nodeId, UaNode node,
UnsignedInteger attributeId, DataValue dataValue) throws StatusException {
String sNodeId = nodeId.toString();
switch(sNodeId) {
case "ns=2;i=6009":
// check if given attributeId is in list of allowed writable attributes
return writableAttributes.stream().filter(x -> (x.getAttributeId() == attributeId)).count() > 0L;
}
return false;
}

Using the debugger I recognize that this method is NOT called!!!
How can I implement to modify attributes?

The same script was formerly used to modify a node on the Softing Demo Server (“ns=2;s=/Trigger”) which also allows to modify node attributes. This script ran successfully all the time. Now I replaced server and node but all I get is a bad status.

Thomas

November 2, 2017
13:59, EET
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 983
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

Hi,

In the current release the WriteMask is not set correctly to the node, that is a bug, will be fixed for 3.0.

The UserWriteMask part is intentionally ignored when loading the model as that is per user setting and not a global, therefore it should not be defined in the model at all.

Normally you would set the WriteMask to the UaNode instance via UaNode.setWriteMask, then just override the UserWriteMask in the IoManagerListener as you have done (as the UserWriteMask must be subset of the WriteMask).

Note, the last code section contains an error, you compare the UnsignedIntegers via == operator which in java should be only used to compare primitives, you should use .equals instead.

The IoManagerListener allows you to modify the values that are sent to the client. Also you can override the UserAccessLevel/UserExecutable/UserWriteMask per user. However overriding the WriteMask Attribute does send that to the client, however the value for WriteMask comes from the UaNode when writing to Attributes. And due to the bug described above it is not read correctly from the model at the moment, which means it is WriteAccess.NONE. The IoManagerListener is not called if the WriteMask does not allow writing to that attribute.

Until the bug is fixed / 3.0 released, the following workarounds should work:

1. Call .setWriteMask for the UaNode in question

2. Create a subclass of IoManagerUaNode and override readNonValue and set that to the NodeManagerUaNode

– Bjarne

November 3, 2017
15:31, EET
Avatar
Thomas Reuther
Member
Members
Forum Posts: 33
Member Since:
September 18, 2017
sp_UserOfflineSmall Offline

Hi Bjarne,

thanks for information.

Now I set the WriteMask/UserWriteMask of these nodes after the call of loadModel().

InputStream istream = ResourceHandler.getInstance().getResourceAsStream("uatestserver.xml");
this.getAddressSpace().loadModel(istream);
UaNode variableAttributes = this.myNodeManager.getNode("ns=2;i=6009");
variableAttributes.setWriteMask(MyIoManagerListener.writableAttributes);
variableAttributes.setUserWriteMask(MyIoManagerListener.writableAttributes);

Now the IoManagerListener.onWriteNonValue() is being called!!! 🙂

But now I face another problem: I cannot change the value of Description. When I call UaNode.setDescription() with a non-null value, e.g.

UaNode variableAttributes = myNodeManager.getNode("ns=2;i=6009");
variableAttributes.setDescription(new LocalizedText("Test A"));

then Description contains an instance of LocalizedText where Locale is null and Text is null.
But setting other attributes does work:

variableAttributes.setDisplayName(new LocalizedText("Another display name"));
variableAttributes.setBrowseName(new QualifiedName("AnotherBrowseName"));

Thomas

November 3, 2017
16:40, EET
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 983
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

Hi,

The Description Attribute (or well anything with LocalizedText) is a known problem, should work after 3.0.

The only workaround at the moment is that the Attribute in question must not be Null in the model. Otherwise the attribute value is LocalizedText.NULL (null text, null locale), which due to a bug cannot be replaced at the moment (the attribute value is stored in a LocalizedTextMap which allows to have text per locale). Since the LocalizedText.NULL is the first value given to that map, it is used as a default value for all locales that do not have a specific text set for the locale.

– Bjarne

November 3, 2017
17:31, EET
Avatar
Thomas Reuther
Member
Members
Forum Posts: 33
Member Since:
September 18, 2017
sp_UserOfflineSmall Offline

Hi Bjarne,

thank you very much.

I can solve this by creating the node completely in code without using my node set file.

Thanks so much for your effort!!!

Thomas

Forum Timezone: Europe/Helsinki

Most Users Ever Online: 518

Currently Online:
21 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

hbrackel: 135

pramanj: 86

Francesco Zambon: 81

rocket science: 77

ibrahim: 76

Sabari: 62

kapsl: 57

gjevremovic: 49

Xavier: 43

fred: 41

Member Stats:

Guest Posters: 0

Members: 680

Moderators: 16

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1467

Posts: 6260

Newest Members:

sagarchau, elviralangwell4, Donnavek, Eddiefauth, DonaldPooma, fidelduke938316, Jan-Pfizer, DavidROunc, fen.pang@woodside.com, aytule

Moderators: Jouni Aro: 1009, Otso Palonen: 32, Tuomas Hiltunen: 5, Pyry: 1, Petri: 0, Bjarne Boström: 983, Heikki Tahvanainen: 402, Jukka Asikainen: 1, moldzh08: 0, Jimmy Ni: 26, Teppo Uimonen: 21, Markus Johansson: 42, Niklas Nurminen: 0, Matti Siponen: 321, Lusetti: 0, Ari-Pekka Soikkeli: 5

Administrators: admin: 1