Learn open62541 --- [30] Easy to view StatusCode

OPC UA provides many services. When using these services, there will usually be a return value indicating whether an error occurred during use. This return value is StatusCode, and its type in open62541 is UA_StatusCode

typedef uint32_t UA_StatusCode;

It can be seen from the definition that its actual type is a 32-bit unsigned integer, and each StatusCode has a specific value.

Let's take a look at how it is actually defined and viewed in open62541.


The situation in open62541

When compiling open62541, the statuscodes.h and statuscodes.c will be generated through tools\schema\StatusCode.csv.
The first column of this csv file is the StatusCode name, the second column is the uint32_t value corresponding to StatusCode, and the third column is StatusCode. The description is as follows. After the
Insert picture description here
compilation is successful, you can go to build\src_generated\open62541\ to view these 2 files.

An array statusCodeDescriptions is defined in statuscodes.c, as follows, there are a total of 237 statuses,

static const size_t statusCodeDescriptionsSize = 237;
static const UA_StatusCodeName statusCodeDescriptions[237] = {
    
    
    {
    
    UA_STATUSCODE_GOOD, "Good"},
    {
    
    UA_STATUSCODE_BADUNEXPECTEDERROR, "BadUnexpectedError"},
    {
    
    UA_STATUSCODE_BADINTERNALERROR, "BadInternalError"},
    {
    
    UA_STATUSCODE_BADOUTOFMEMORY, "BadOutOfMemory"},
    {
    
    UA_STATUSCODE_BADRESOURCEUNAVAILABLE, "BadResourceUnavailable"},
    {
    
    UA_STATUSCODE_BADCOMMUNICATIONERROR, "BadCommunicationError"},
    {
    
    UA_STATUSCODE_BADENCODINGERROR, "BadEncodingError"},
	... ...,
    {
    
    UA_STATUSCODE_BADMAXCONNECTIONSREACHED, "BadMaxConnectionsReached"},
    {
    
    0xffffffff, "Unknown StatusCode"}
};

Through statusCodeDescriptions, you can get the string corresponding to each StatusCode. Open62541 also provides a function to convert UA_StatusCode to the corresponding string (statusCodeDescriptions is used internally), as follows,

const char * UA_StatusCode_name(UA_StatusCode code);

This is very convenient when debugging.


summary

Through the function UA_StatusCode_name(), we can get the string corresponding to the StatusCode, which is convenient for debugging

Guess you like

Origin blog.csdn.net/whahu1989/article/details/106389647