onRead and onWrite callbacks

38 views
Skip to first unread message

Игорь

unread,
Apr 29, 2022, 3:54:33 AM4/29/22
to open62541
Hi, dear community.

I have problem whith getting date about node in callbacks function.

addValueCallbak - the function for adding callbacks on variable nodes.
Here currentNodeId is  ns=1;i=Name
 
  static void addValueCallback(UA_Server *server, char* variableNodeName) {
    UA_NodeId currentNodeId = UA_NODEID_STRING(1, variableNodeName);
    UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND,
                "The CALLBACK add on VARIABLE: %s",variableNodeName);
   
    UA_ValueCallback callback;
    callback.onRead = beforeRead;
    callback.onWrite = afterWrite;
    UA_Server_setVariableNode_valueCallback(server, currentNodeId, callback);
}

afterWrite
 will be called when the client chenges the value of variable.
In this function after call nodeId is ns=864;i=0.

static void afterWrite(UA_Server *server,
                       const UA_NodeId *sessionId, void *sessionContext,
                       const UA_NodeId *nodeId, void *nodeContext,
                       const UA_NumericRange *range, const UA_DataValue *data) {

 UA_String out = UA_STRING_NULL;
 UA_print(&nodeId, &UA_TYPES[UA_TYPES_NODEID], &out);
 printf("%.*s\n", (int)out.length, out.data);
 UA_String_clear(&out);
}

Please help me understand: where i do something wrong?
How can i get the right nodeId and new value of varibale in function afterWrite?

br
----
Igor

Julius Pfrommer

unread,
Apr 29, 2022, 4:27:26 AM4/29/22
to open62541
The code looks good.

Do you have a debugger?
It would be useful to add a breakpoint within afterWrite and then see upwards in the call stack where the wrong NodeId appears.

Which version of the SDK do you use?
I do not recall other reports of this bug.

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