Skip to main content

Server Information

Overview​

OPC UA standard node i=2256 (Server.ServerStatus) exposes server-side runtime information. i=2256 is itself an ExtensionObject, and unpacking it directly would need a DataTypeDefinition, so the SDK takes the read 11 child nodes individually + fault-tolerant assembly route (see the structure notes below for the node number behind each field): a failed field read is filled with the default value, and a whole-call exception is caught with UA_SERVER_STATE_UNKNOWN instead of being thrown.

Corresponding section of the standard: Part 5 §6.3.

API​

FunctionCategoryReading and WritingNote
DarraUa_Session_ReadServerStatus(session, &out)DiagnosisReadRead the 11 child nodes separately and then perform fault-tolerant assembly (11 reads RPC)
DarraUa_Session_ReadServerState(session)DiagnosisReadRead only i=2259, single RPC, Returns Directly ServerState
DarraUa_Session_ReadCurrentTime(session)DiagnosisReadRead only i=2258, single RPC, Returns Directly DateTime
DarraUa_ServerStatus_Clear(&status)Release—Free the embedded string, but do not free the status itself
DarraUa_BuildInfo_Clear(&build)Release—Free the embedded string, but do not free the build itself
UA_SDK_API DarraUa_Status UA_SDK_CALL
DarraUa_Session_ReadServerStatus(DarraUa_SessionHandle session, DarraUa_ServerStatus* out);

UA_SDK_API DarraUa_ServerState UA_SDK_CALL
DarraUa_Session_ReadServerState(DarraUa_SessionHandle session);

UA_SDK_API DarraUa_DateTime UA_SDK_CALL
DarraUa_Session_ReadCurrentTime(DarraUa_SessionHandle session);

UA_SDK_API void UA_SDK_CALL DarraUa_ServerStatus_Clear(DarraUa_ServerStatus* s);
UA_SDK_API void UA_SDK_CALL DarraUa_BuildInfo_Clear(DarraUa_BuildInfo* b);

ReadServerState / ReadCurrentTime No out parameters, The return types are DarraUa_ServerState and DarraUa_DateTime — neither is DarraUa_Status, so they cannot be compared UA_STATUS_GOOD to. When a read fails, the former returns UA_SERVER_STATE_UNKNOWN, while the latter returns 0.

ReadServerStatus Always returns a value (UA_STATUS_GOOD fills in the default value if a single-field read fails); returns a value only if there is a parameter error UA_STATUS_INVALID_ARGUMENT. out PassStack Variables That's it—SDK just fill in the fields without assigning the structure itself; DarraUa_ServerStatus_Clear(out) release the embedded string after use.

Related Structures:

typedef struct {
DarraUa_DateTime start_time; // Start Time (i=2257)
DarraUa_DateTime current_time; // Current time (i=2258), a new read each time
DarraUa_ServerState state; // Running state (i=2259), read failure: UNKNOWN
DarraUa_BuildInfo build; // Nested structures, not pointers
uint32_t seconds_till_shutdown; // i=2992; only the state SHUTDOWN is meaningful
char* shutdown_reason; // i=2993, UTF-8 heap allocation
} DarraUa_ServerStatus;

typedef struct {
char* product_uri; // i=2262
char* manufacturer_name; // i=2263
char* product_name; // i=2261
char* software_version; // i=2264
char* build_number; // i=2265
DarraUa_DateTime build_date; // i=2266
} DarraUa_BuildInfo;

typedef enum {
UA_SERVER_STATE_RUNNING = 0, // Normal
UA_SERVER_STATE_FAILED = 1, // Fatal Failure
UA_SERVER_STATE_NO_CONFIGURATION = 2, // Missing configuration
UA_SERVER_STATE_SUSPENDED = 3, // Paused by Operations
UA_SERVER_STATE_SHUTDOWN = 4, // Shutting Down
UA_SERVER_STATE_TEST = 5, // Test Mode
UA_SERVER_STATE_COMMUNICATION_FAULT = 6, // Link Failure
UA_SERVER_STATE_UNKNOWN = 7 // Fallback SDK when a read fails
} DarraUa_ServerState;

All time fields are DarraUa_DateTime = UTC 100ns ticks since 1601-01-01 (OPC UA Part 6 §5.1.4), not milliseconds (epoch). The string fields build within and shutdown_reason are both allocated by the heap SDK and are DarraUa_ServerStatus_Clear released uniformly by (which clears build along with them internally).

Code Example​

#include <opcua/opcua.h>
#include <opcua_server_info.h>
#include <stdio.h>
#include <time.h>

/* DarraUa_DateTime = UTC 100ns since 1601-01-01 */
static DarraUa_DateTime utc_now_ft(void) {
return (DarraUa_DateTime)((int64_t)time(NULL) * 10000000LL + 116444736000000000LL);
}

int main(void)
{
DarraUa_Initialize();
/* ... DarraUa_Session_Create + (omitted DarraUa_Session_Connect ), obtain handle h ... */

/* 1) Read the entire dataset in one go */
DarraUa_ServerStatus status;
DarraUa_Status rc = DarraUa_Session_ReadServerStatus(h, &status);
if (UA_STATUS_IS_GOOD(rc)) {
printf("Start = %lld\n", (long long)status.start_time);
printf("State = %d\n", (int)status.state);
printf("Build = %s %s\n",
status.build.product_name ? status.build.product_name : "",
status.build.software_version ? status.build.software_version : "");

if (status.state == UA_SERVER_STATE_SHUTDOWN)
printf("倒计时 %u s\n", status.seconds_till_shutdown);

DarraUa_ServerStatus_Clear(&status); /* Unescaping Embedded Strings */
}

/* 2) Lightweight heartbeat — Returns an enumeration directly, not a Status */
if (DarraUa_Session_ReadServerState(h) == UA_SERVER_STATE_RUNNING)
printf("在线\n");

/* 3) Clock drift — Returns immediately DateTime; returns 0 if the read operation fails */
DarraUa_DateTime server_now = DarraUa_Session_ReadCurrentTime(h);
if (server_now != 0) {
DarraUa_DateTime local_now = utc_now_ft();
printf("时钟差 = %lld (100ns)\n", (long long)(local_now - server_now));
}

/* ... DarraUa_Session_Close(h) ... */
DarraUa_Shutdown();
return 0;
}

Cross-Language Comparison​

C#PythonJavaC++RustC
ReadServerStatusread_server_statusreadServerStatusReadServerStatusread_server_statusDarraUa_Session_ReadServerStatus
ReadServerStateread_server_statereadServerStateReadServerStateread_server_stateDarraUa_Session_ReadServerState
ReadCurrentTimeread_current_timereadCurrentTimeReadCurrentTimeread_current_timeDarraUa_Session_ReadCurrentTime

Next Step​