Server Information (ReadServerStatus / BuildInfo / ServerState)
Overview
OPC UA standard node i=2256 (Server.ServerStatus) exposes server runtime information: start time, current time, state, build info, shutdown countdown and shutdown reason. The SDK assembles these 11 child nodes (i=2257 through i=2266, plus i=2992 / i=2993) into a strongly typed ServerStatus object.
Corresponding section of the standard: Part 5 §6.3 (ServerStatusDataType).
API
| Methods / Properties | Category | Reading and Writing | Note |
|---|---|---|---|
| ua.ReadServerStatus() | Diagnosis | Read | Returns the Full List ( ServerStatus 11 nodes at a time RPC) |
| ua.ReadServerState() | Diagnosis | Read | Read only i=2259, return ServerState enumeration |
| ua.ReadCurrentTime() | Diagnosis | Read | Read only i=2258, return DateTime (UTC, or default(DateTime) if the operation fails) |
All three are extension methods DarraOpcUa of, defined in DarraOpcUa_Client.ServerInfoExtensions.
Related Structures:
public sealed class ServerStatus
{
public DateTime StartTime { get; init; } // Starting the Server UTC
public DateTime CurrentTime { get; init; } // Server Status UTC
public ServerState State { get; init; } // Current Status
public BuildInfo Build { get; init; } // Product/Manufacturer/Version/Build Number/Build Date
public uint SecondsTillShutdown { get; init; } // Seconds remaining until shutdown (usually 0 when "Running")
public string ShutdownReason { get; init; } // Reason for Shutdown (LocalizedText.Text)
}
public sealed class BuildInfo
{
public string ProductUri { get; init; } // i=2262 Unique Product Identifier URI
public string ManufacturerName { get; init; } // i=2263 Manufacturer
public string ProductName { get; init; } // i=2261 Product Name
public string SoftwareVersion { get; init; } // i=2264 Version string
public string BuildNumber { get; init; } // i=2265 Build Number
public DateTime BuildDate { get; init; } // i=2266 Build Date (UTC)
}
public enum ServerState
{
Running = 0, // Normal
Failed = 1, // Fatal Failure
NoConfiguration = 2, // Missing configuration
Suspended = 3, // Paused by Operations
Shutdown = 4, // Shutting Down
Test = 5, // Test Mode
CommunicationFault = 6, // Communication Link Failure
Unknown = 7 // SDK Fallback (Read Failed)
}
Code Example
using System;
using DarraOpcUa_Client;
using var ua = new DarraOpcUa("opc.tcp://localhost:4840");
ua.Connect();
// 1) Pull them all at once
var status = ua.ReadServerStatus();
Console.WriteLine($"Start = {status.StartTime}");
Console.WriteLine($"Now = {status.CurrentTime}");
Console.WriteLine($"State = {status.State}");
Console.WriteLine($"Build = {status.Build}");
// → "DarraPLC 1.2.3.4 (build 20260420 @ 2026-04-20)"
if (status.State != ServerState.Running)
Console.WriteLine($"服务端非 Running, 倒计时 {status.SecondsTillShutdown}s, 原因: {status.ShutdownReason}");
// 2) Lightweight Heartbeat (Saving RPC)
var st = ua.ReadServerState();
Console.WriteLine(st == ServerState.Running ? "在线" : st.ToString());
// 3) Clock Drift Check — ReadCurrentTime Returns a non-empty value DateTime; if the read fails, it returns `default(DateTime)`
var serverNow = ua.ReadCurrentTime();
if (serverNow != default)
{
var drift = (DateTime.UtcNow - serverNow).TotalMilliseconds;
Console.WriteLine($"客户端 - 服务端时钟差 = {drift:F1} ms");
}
Error Handling
- Never returns null — An object
ServerStatusReadServerStatusmust be constructed; fields that cannot be read will default to their default values (string= null,DateTime=default(DateTime),uint= 0; the corresponding fieldsBuildof will also be null or their default values). - A failure in a single field does not affect the other fields. — Each child node is read individually. Only The "State" field itself A read failure (or a global exception)
Stateoccurs only whenServerState.Unknown; for example, even if only fails to readBuildNumber, may stillStatebeRunning. - Do not throw exceptions (Except for
ua == nullthrowArgumentNullException) — A network disconnection or session expiration will not result in an exception; instead, it will be represented asState == Unknown+ the default values for each field.ReadServerStateSimilarly, a failure returnsUnknown, and aReadCurrentTimefailure returnsdefault(DateTime). - Used for business-side interpretation
if (status.State == ServerState.Unknown), Do not writestatus == null— That’s the Eternal Branch. Unknown"Could not read this time" does not mean "the server is in a failed state" — a true server failure isServerState.Failed.
Best Practices
- Diagnostic Panel — One-time
ReadServerStatus, Show 6 fields - Status Bar — Use
ReadServerState(to save bandwidth) - Shutdown Alert — Listening
SecondsTillShutdown > 0→ Displays a message saying "The server will shut down in N seconds" - Do not call it in the subscription callback — Avoid having the callback thread perform RPC
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 | ReadCurrentTime | read_current_time | DarraUa_Session_ReadCurrentTime |