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
Using Arrays
February 7, 2014
23:33, EET
Avatar
Steve
Member
Members
Forum Posts: 6
Member Since:
February 8, 2014
sp_UserOfflineSmall Offline

Hi,
I’m using the server SDK and trying to create a UaVariableNode that will contain an array of floating point values. Can you provide some sample code that shows how to create and update the object? Thanks.

February 10, 2014
8:25, EET
Avatar
Jouni Aro
Moderator
Moderators
Forum Posts: 1010
Member Since:
December 21, 2011
sp_UserOfflineSmall Offline

This sample is available in SampleConsoleServer.createStaticArrayVariable:

private void createStaticArrayVariable(String dataTypeName,
NodeId dataType, Object initialValue) throws StatusException {
final NodeId nodeId = new NodeId(complianceNamespaceIndex, dataTypeName);
UaType type = server.getNodeManagerRoot().getType(dataType);
UaVariableNode node = new CacheVariable(complianceNodeManager, nodeId,
dataTypeName, Locale.ENGLISH);
node.setDataType(type);
node.setTypeDefinition(type);
node.setValueRank(ValueRanks.OneDimension);
node.setArrayDimensions(new UnsignedInteger[] { UnsignedInteger
.valueOf(Array.getLength(initialValue)) });

node.setValue(new DataValue(new Variant(initialValue), StatusCode.GOOD,
new DateTime(), new DateTime()));
staticArrayVariableFolder.addReference(node, Identifiers.HasComponent,
false);
}

and it is called from createComplianceNodes, e.g.

createStaticArrayVariable("BooleanArray", Identifiers.Boolean,
new Boolean[] { true, false, true, false, false });
createStaticArrayVariable(
"ByteArray",
Identifiers.Byte,
new UnsignedByte[] { UnsignedByte.valueOf(1),
UnsignedByte.valueOf(2), UnsignedByte.valueOf(3),
UnsignedByte.valueOf(4), UnsignedByte.valueOf(5) });
September 25, 2018
18:24, EEST
Avatar
sergejm
New Member
Members
Forum Posts: 2
Member Since:
June 29, 2017
sp_UserOfflineSmall Offline

Hello,
I am using the code above ( createStaticArrayVariable ) to generate a UaVariableNode but as an Identifiers.Int16 data type. When updating the value I can see that the value was changed, but subscribing (via UaExpert) doesn’t work (i.e. the initial value is shown but is not updated). Is this a general issue with array types or am I missing something? I tried UaVariableNode.setValue as well as UaVariableNode.updateValue.

September 26, 2018
16:03, EEST
Avatar
Heikki Tahvanainen
Moderator
Members

Moderators
Forum Posts: 402
Member Since:
April 17, 2013
sp_UserOfflineSmall Offline

Hello Sergej,

The above code should still work despite being 4 years old. And UaExpert should be able to create subscriptions to Array variables without issues.

How have you confirmed that the value was updated correctly on the server side?

Do you think you could compose an example project showing the issue so that we could reproduce this? I tested the above code snippets and UaExpert and I cannot find anything going wrong.

September 26, 2018
18:45, EEST
Avatar
sergejm
New Member
Members
Forum Posts: 2
Member Since:
June 29, 2017
sp_UserOfflineSmall Offline

Hello Heikki,
I just sent an example of my use case and also detected the issue: the issue occurs if I don’t create a new instance of the new value but just update the value object by modifying the index based values. If I create a new object however (new operator) the value is updated.

September 27, 2018
8:57, EEST
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 983
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

Hi,

Answered via mail, but for others reading this, arrays are not defensively copied when passed, so you will need to use new array for each write, otherwise you are modifying the value within the node and that causes problems internally.

Forum Timezone: Europe/Helsinki

Most Users Ever Online: 518

Currently Online:
27 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: 681

Moderators: 16

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1467

Posts: 6261

Newest Members:

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

Moderators: Jouni Aro: 1010, 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