Writing subarray (Based on example addMatrixVariable)

56 views
Skip to first unread message

Torben Blanken

unread,
Apr 20, 2020, 10:55:57 AM4/20/20
to open62541
Hello,

while testing some base-functionallity, I'm trying to write some values to a sub array, but allways get the error "BadIndexRangeNoData".


Serverside-Variable-Node exists (details see https://open62541.org/doc/current/tutorial_server_variable.html):

UA_UInt32 arrayDims[2] = {2,2};
UA_Double zero[4] = {0.0, 0.0, 0.0, 0.0};

Writing complete array using "UA_Client_Service_write" is correctly executed - no problem.


No I try just to write the seconde subarray (index 1):

UA_StatusCode retval;

UA_UInt32 nodeValueDimension[1] = {2};
UA_Double myValue[2] = {99.0, 100.0 };

UA_Variant myVariantValue;
UA_Variant_init(&myVariantValue);
retval = UA_Variant_setArrayCopy(&myVariantValue, &myValue, 2, &UA_TYPES[UA_TYPES_DOUBLE]);
UA_WriteValue wValue;
UA_WriteValue_init(&wValue);
wValue.nodeId = UA_NODEID_STRING(1, (char*)"the.matrix"); // node to write to
wValue.attributeId = UA_ATTRIBUTEID_VALUE;
wValue.value.value = myVariantValue;
wValue.value.hasValue = true;
wValue.indexRange = UA_STRING((char*)"1");
UA_WriteRequest wReq;
UA_WriteRequest_init(&wReq);
wReq.nodesToWrite = &wValue;
wReq.nodesToWriteSize = 1;

UA_WriteResponse wResponse = UA_Client_Service_write(client, wReq);
retval = *wResponse.results;


My expected result / my intention would be something like
{0.0, 0.0, 99.0, 100.0}


Does someone know or can give me a hint on my problem?


Best regards,
Torben

Julius Pfrommer

unread,
Apr 21, 2020, 5:15:25 PM4/21/20
to open62541
The IndexRange is just "1".
Probably you meant "1,0:1" to select a "block" within the 2x2 matrix.
Also, the dimension of the value you write needs to match the dimension of the selected "block".

See here for an example:

Regards,
Julius
Reply all
Reply to author
Forward
0 new messages