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
Read and write data to Byte Matrix[][]
March 20, 2019
11:13, EET
Avatar
marttin
Member
Members
Forum Posts: 10
Member Since:
March 20, 2019
sp_UserOfflineSmall Offline

Hello,

How can I write data to the Byte Matrix in Java Client [8] [28].
I try to write by method:

write(final NodeId nodeId, final String value)
example:

NodeId nodeId = NodeId.parseNodeId(“ns=6;s=::AsGlobalPV:gCtrl.aws.SetCompartMap[0][0]”);
write(nodeId, “22”);

the result is :

com.prosysopc.ua.ServiceException: Chyba zapisu hodnoty AddressSpaceException, com.prosysopc.ua.client.AddressSpaceException: Cannot determine NodeClass for NodeId: ns=6;s=::AsGlobalPV:gCtrl.aws.SetCompartMap[0][0] because the value is not good: DataValue(value=(null), statusCode=Bad_NodeIdUnknown (0x80340000) “The node id refers to a node that does not exist in the server address space.”, sourceTimestamp=null, sourcePicoseconds=0, serverTimestamp=03/20/19 09:01:37.2200000 GMT, serverPicoseconds=0) Diagnostics=Diagnostic Info:
Chyba zapisu hodnoty AddressSpaceException, com.prosysopc.ua.client.AddressSpaceException: Cannot determine NodeClass for NodeId: ns=6;s=::AsGlobalPV:gCtrl.aws.SetCompartMap[0][0] because the value is not good: DataValue(value=(null), statusCode=Bad_NodeIdUnknown (0x80340000) “The node id refers to a node that does not exist in the server address space.”, sourceTimestamp=null, sourcePicoseconds=0, serverTimestamp=03/20/19 09:01:37.2200000 GMT, serverPicoseconds=0)

March 20, 2019
13:05, EET
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 1027
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

Hi,

OPC UA does not work like that. NodeId just defines the node, there is no such array syntax (at least defined in the specification, a Server could theoretically make array-element nodes with those names, but that would be entirely server-specific-functionality).

Instead you will need to pass an IndexRange in the Write calls. With the UaClient this would be done via:

UaClient.writeValue(NodeId nodeId, Object value, NumericRange indexRange)

method. Note that the Server must also support writing to specific indexies, not all servers support that.

As your range appears to be a single element in multidimensional array, you must use the:

new NumericRange(int[]… indexes)

constructor, passing 2 int[] arrays with a single element having value 0.

March 20, 2019
17:48, EET
Avatar
marttin
Member
Members
Forum Posts: 10
Member Since:
March 20, 2019
sp_UserOfflineSmall Offline

Thank you for your response.

Read data from node:
Node: ns=6;s=::AsGlobalPV:gCtrl.aws.SetCompartMap.Value ,| Status: GOOD (0x00000000) “” ,| Value: [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0][0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0][0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0][0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0][0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0][0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0][0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0][0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]] ,| ServerTimestamp: 2019 mar 20 (CET) 17:36:54.487 ,| SourceTimestamp: 2019 mar 20 (CET) 17:36:54.487

I need to overwrite the values in the field, but I still can’t do it.
This is how the structure node on the server looks

View post on imgur.com

I used the new NumericRange (1,1) to write the value in position 1 1

Code:

int[][] selfLayoutArray = selfLayout.getDoorLayout(); //get data from client int[8][28]
NodeId nodeId2 = NodeId.parseNodeId("ns=6;s=::AsGlobalPV:gCtrl.aws.SetCompartMap"); //node OPC

for (int r = 0; r < 8; r++) {
for (int s = 0; s < 28; s++) {

NumericRange indexRange = new NumericRange(selfLayoutArray [1][1]);
byte data =(byte) selfLayoutArray[i][j];
client.writeValue(nodeId2, data, indexRange);
}
}

Result:

com.prosysopc.ua.StatusException: Bad_IndexRangeNoData (0x80370000) “No data exists within the range of indexes specified.” StatusCode=Bad_IndexRangeNoData (0x80370000) “No data exists within the range of indexes specified.”

March 21, 2019
9:43, EET
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 1027
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

Hi,

In this particular case it probably would be just easier to write the entire array back in whole than once per index.

But anyway, as mentioned above, you will need to use the NumericRange constructor taking int arrays, not ints. The IndexRange defines start and end indexies and the constructor taking 2 ints defines IndexRange for 1-dimensional array. The one taking int[]s will take the first value per given array as the start and second as the end (but you can also give one per array if you are writing a single element, in that case only start needs to be defined) per dimension.

If you change that part to:

NumericRange indexRange = new NumericRange(new int[] {i}, new int[] {j});

it should work. Additionally note if your UA DataType is the Byte type, you will need to use UnsignedByte on the java side, as UA Byte is unsigned, and Java Byte is signed. If your data is Java bytes as unsigned values in binary representation, you would use:

UnsignedByte value = UnsignedByte.getFromBits(byte);
June 4, 2020
15:28, EEST
Avatar
marttin
Member
Members
Forum Posts: 10
Member Since:
March 20, 2019
sp_UserOfflineSmall Offline

how I solved the problem
Read:

private int[][] readData(String node){
NodeId nodeId = NodeId.parseNodeId(node);
final UnsignedInteger attributeId = UnsignedInteger.parseUnsignedInteger("13");
DataValue data = client.readAttribute(nodeId, attributeId);

Object v1 = data.getValue().getValue();
UnsignedByte[][] dataArray = (UnsignedByte[][]) v1;

int[][] dataInt = new int[10][28];
for (int r = 0; r < 10; r++) {
for (int s = 0; s < 28; s++) {
dataInt[r][s] =(dataArray[r][s]).intValue();
}
}
return dataInt;
}

Writing solution

private void writeData(String node,int[][] dataForWrite){
NodeId nodeId = NodeId.parseNodeId(node);

UnsignedByte[][] opcData = new UnsignedByte[10][28];

for (int r = 0; r < 10; r++) {
for (int s = 0; s < 28; s++) {
opcData[r][s] = UnsignedByte.valueOf(dataForWrite[r][s]);
}
}

client.writeValue(nodeId, opcData);

}

There may also be a better way to convert an UnsignedByte array to int array.

Forum Timezone: Europe/Helsinki

Most Users Ever Online: 1919

Currently Online:
83 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

Heikki Tahvanainen: 402

hbrackel: 144

rocket science: 88

pramanj: 86

Francesco Zambon: 83

Ibrahim: 78

Sabari: 62

kapsl: 57

gjevremovic: 49

Xavier: 43

Member Stats:

Guest Posters: 0

Members: 739

Moderators: 7

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1524

Posts: 6453

Newest Members:

shaylamaggard4, rickyjuarez140, jonathonmcintyre, fannielima, kristiewinkle8, rust, christamcdowall, redaahern07571, nigelbdhmp, travistimmons

Moderators: Jouni Aro: 1026, Pyry: 1, Petri: 0, Bjarne Boström: 1027, Jimmy Ni: 26, Matti Siponen: 346, Lusetti: 0

Administrators: admin: 1