Server Information
Overview
OPC UA standard node i=2256 (Server.ServerStatus) exposes server-side runtime information. Instead of parsing it as a single ExtensionObject, the SDK reads the 11 child nodes separately — i=2257 / i=2258 / i=2259 / i=2261..i=2266 / i=2992 / i=2993 — and assembles them fault-tolerantly into the strongly typed ServerStatus.
Corresponding section of the standard: Part 5 §6.3.
API
All three entries are under the namespace darra::opcuaFree Functions(server_info.hpp), the first parameter is passed to Session&, which is not a member method of Session.
| Function | Category | Reading and Writing | Note |
|---|---|---|---|
| ReadServerStatus | Diagnosis | Read | Assembled in one go ServerStatus(11 reads total RPC) |
| ReadServerState | Diagnosis | Read | Read-only i=2259, single RPC |
| ReadCurrentTimeFileTime | Diagnosis | Read | Read-only i=2258, Single RPC, Returns int64_t FileTime |
namespace darra::opcua {
// 11 reads RPC Assembly; if any field fails to read, use the default value; the `state` falls back to `Unknown`. No exception is thrown.
ServerStatus ReadServerStatus(Session& s);
// Read only: i=2259. Returns on failure ServerState::Unknown; does not throw an exception.
ServerState ReadServerState(Session& s);
// Read-only: i=2258. Returns 0 on failure. Time elapsed: ( FileTime UTC since 100ns 1601), not time_point.
int64_t ReadCurrentTimeFileTime(Session& s);
}
Related Structures (ServerStatus Fields):
- start_time_filetime (int64_t) — Start time, FileTime (UTC 100ns since 1601)
- current_time_filetime (int64_t) — Current time, FileTime
- state (ServerState) — Current state
- build (BuildInfo) — Product/Version
- seconds_till_shutdown (uint32_t) — Seconds until shutdown
- shutdown_reason (std::string) — Shutdown reason
- ToString() — Spelled out
State=..., Start=..., Now=..., Build=[...]
Related Structures (BuildInfo Fields):
- product_uri / manufacturer_name / product_name / software_version / build_number (std::string)
- build_date_filetime (int64_t) — Build date, FileTime, 0 = Unknown
- ToString() — Spelled out
产品名 版本 (build 编号)
Related Structures (ServerState Enumerations):
- Running (0) — Normal
- Failed (1) — Fatal error
- NoConfiguration (2) — No configuration
- Suspended (3) — Suspended by Operations
- Shutdown (4) — Shutting down
- Test (5) — Test Mode
- CommunicationFault (6) — Link Failure
- Unknown (7) — SDK Fallback
Code Example
#include <darra/opcua/client.hpp>
#include <darra/opcua/server_info.hpp>
#include <chrono>
#include <iostream>
using namespace darra::opcua;
Session s("opc.tcp://localhost:4840");
s.Connect();
// 1) One-time assembly (11 reads total RPC)
ServerStatus status = ReadServerStatus(s);
std::cout << status.ToString() << "\n";
std::cout << "Build = " << status.build.product_name << " "
<< status.build.software_version << "\n";
if (status.state != ServerState::Running)
std::cout << "非 Running, 倒计时 " << status.seconds_till_shutdown << "s\n";
// 2) Lightweight Heartbeat (Single RPC)
if (ReadServerState(s) == ServerState::Running)
std::cout << "在线\n";
// 3) Clock drift — The server returns the result FileTime; convert it first, then compare it
constexpr int64_t WIN_EPOCH_OFFSET = 116444736000000000LL;
int64_t server_ft = ReadCurrentTimeFileTime(s); // 0 = Read failed
if (server_ft != 0) {
auto now_ns = std::chrono::duration_cast<std::chrono::nanoseconds>(
std::chrono::system_clock::now().time_since_epoch()).count();
int64_t local_ft = WIN_EPOCH_OFFSET + now_ns / 100;
std::cout << "时钟差 = " << (local_ft - server_ft) / 10000 << " ms\n";
}
ServerStatus::start_time_filetime / current_time_filetime / build.build_date_filetime All FileTime(UTC since 100ns 1601-01-01), consistent DateTime.ToFileTimeUtc with Windows, not system_clock::time_point.
Cross-Language Comparison
| C# | Python | Java | C++ | Rust | C |
|---|---|---|---|---|---|
| ReadServerStatus | read_server_status | readServerStatus | ReadServerStatus | read_server_status | DarraUa_Session_ReadServerStatus |
| ReadServerState | read_server_state | readServerState | ReadServerState | read_server_state | DarraUa_Session_ReadServerState |
| ReadCurrentTime | read_current_time | readCurrentTime | ReadCurrentTimeFileTime | read_current_time | DarraUa_Session_ReadCurrentTime |
In C++, these three are free functions, with the first parameter being; Session& in C#, Python, Java, and Rust, they are methods on session objects.