Server Information
Overview
OPC UA standard node i=2256 (Server.ServerStatus) exposes server-side runtime information. The SDK does not parse the ServerStatusDataType ExtensionObject as a single unit; it reads the 11 standard subnodes separately and returns the strongly typed ServerStatus (11 Read RPCs in total: i=2257 / i=2258 / i=2259 / i=2261..i=2266 / i=2992 / i=2993).
Corresponding section of the standard: Part 5 §6.3 (ServerStatusDataType).
API
| Methods | Category | Reading and Writing | Note |
|---|---|---|---|
| ua.read_server_status() | Diagnosis | Read | Returns ServerStatus (11 views RPC) |
| ua.read_server_state() | Diagnosis | Read | Returns ServerState Enumeration (Single RPC) |
| ua.read_current_time() | Diagnosis | Read | Returns Optional[datetime] (UTC, single RPC; None if the read operation fails) |
Authentic signature:
def read_server_status(self) -> ServerStatus: ...
def read_server_state(self) -> ServerState: ...
def read_current_time(self) -> Optional[datetime]: ...
@dataclass(frozen=True)
class BuildInfo:
product_uri: Optional[str] = None
manufacturer_name: Optional[str] = None
product_name: Optional[str] = None
software_version: Optional[str] = None
build_number: Optional[str] = None
build_date: Optional[datetime] = None
@dataclass(frozen=True)
class ServerStatus:
start_time: Optional[datetime] = None # i=2257
current_time: Optional[datetime] = None # i=2258
state: ServerState = ServerState.UNKNOWN # i=2259
build: Optional[BuildInfo] = None # i=2261..i=2266 Assembly
seconds_till_shutdown: int = 0 # i=2992
shutdown_reason: Optional[str] = None # i=2993
class ServerState(IntEnum):
RUNNING = 0 # Normal
FAILED = 1 # Fatal Failure
NO_CONFIGURATION = 2 # Missing configuration
SUSPENDED = 3 # Paused by Operations
SHUTDOWN = 4 # Shutting Down
TEST = 5 # Test Mode
COMMUNICATION_FAULT = 6 # Link Failure
UNKNOWN = 7 # SDK Fallback (Handles failure / value not in the range 0–6)
If any subfield fails to read, the default value (None / 0 / UNKNOWN) is used, and no exception is thrown.
Code Example
from darra_opcua import DarraOpcUa, ServerState # Module Name darra_opcua
with DarraOpcUa("opc.tcp://localhost:4840") as ua:
ua.connect()
# 1) Disposable
status = ua.read_server_status()
print(f"Start = {status.start_time}")
print(f"Now = {status.current_time}")
print(f"State = {status.state.name}")
if status.build is not None:
print(f"Build = {status.build.product_name} {status.build.software_version}")
if status.state != ServerState.RUNNING:
print(f"服务端非 Running, 距关停 {status.seconds_till_shutdown}s")
# 2) Lightweight state checking
if ua.read_server_state() == ServerState.RUNNING:
print("在线")
# 3) Clock drift
server_now = ua.read_current_time()
if server_now is not None:
from datetime import datetime, timezone
drift = (datetime.now(timezone.utc) - server_now).total_seconds() * 1000
print(f"时钟差 = {drift:.1f} ms")
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 |