Skip to content

Commit

Permalink
feat(client): Implement the highlevel method UA_Client_write
Browse files Browse the repository at this point in the history
  • Loading branch information
jpfr committed Nov 13, 2024
1 parent ccf4240 commit 3e48801
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/open62541/client_highlevel.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,9 @@ UA_Client_HistoryUpdate_deleteRaw(
* The following functions can be use to write a single node attribute at a
* time. Use the regular write service to write several attributes at once. */

UA_StatusCode UA_EXPORT UA_THREADSAFE
UA_Client_write(UA_Client *client, const UA_WriteValue *wv);

/* Don't call this function, use the typed versions */
UA_StatusCode UA_EXPORT UA_THREADSAFE
__UA_Client_writeAttribute(UA_Client *client, const UA_NodeId *nodeId,
Expand Down
28 changes: 28 additions & 0 deletions src/client/ua_client_highlevel.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,34 @@ UA_Client_translateBrowsePathToNodeIds(UA_Client *client,
/* Write Attributes */
/********************/

UA_StatusCode UA_EXPORT UA_THREADSAFE
UA_Client_write(UA_Client *client, const UA_WriteValue *wv) {
if(!wv)
return UA_STATUSCODE_BADINTERNALERROR;

/* Set up the request */
UA_WriteRequest request;
UA_WriteRequest_init(&request);
request.nodesToWrite = (UA_WriteValue*)(uintptr_t)wv;
request.nodesToWriteSize = 1;

/* Call the service */
UA_StatusCode retval = UA_STATUSCODE_GOOD;
UA_WriteResponse response = UA_Client_Service_write(client, request);
retval = response.responseHeader.serviceResult;
if(retval == UA_STATUSCODE_GOOD && response.resultsSize != 1)
retval = UA_STATUSCODE_BADUNEXPECTEDERROR;
if(UA_StatusCode_isBad(retval)) {
UA_WriteResponse_clear(&response);
return retval;
}

/* Return the result */
retval = response.results[0];
UA_WriteResponse_clear(&response);
return retval;
}

UA_StatusCode
__UA_Client_writeAttribute(UA_Client *client, const UA_NodeId *nodeId,
UA_AttributeId attributeId, const void *in,
Expand Down

0 comments on commit 3e48801

Please sign in to comment.