メインコンテンツまでスキップ

サーバー情報

概要​

OPC UA 標準ノード i=2256 (Server.ServerStatus) は、サーバー側のランタイム情報を公開します。SDK 11個のリーフノード (i=2257 / i=2258 / i=2259 / i=2261..i=2266 / i=2992 / i=2993、オブジェクト i=2260 BuildInfo ノード自体はスキップ) をフィールドごとに読み取り、一度に強型として組み立てます ServerStatus。

該当する規格の節:第5部 §6.3。

個々のフィールドの読み取りに失敗した場合はデフォルト値を使用(Instant = null / String = null / secondsTillShutdown = 0)。全体で例外が発生した場合は state に設定 ServerState.Unknown; readServerState() / readCurrentTime() 失敗した場合はそれぞれ ServerState.Unknown / を返す null。いずれの場合も例外はスローされない。

API​

方法カテゴリ読み書き説明
ua.readServerStatus()診断読み取り可完全な ServerStatus を返します
ua.readServerState()診断読み取り可ServerState 列挙を返します
ua.readCurrentTime()診断読み取り可Instant (UTC) を返します

関連する構造:

// ServerStatus / BuildInfo すべて record — 公開フィールドはなく、すべてアクセサ(括弧付き)を使用する
public final record ServerStatus(Instant startTime, Instant currentTime, ServerState state,
BuildInfo build, long secondsTillShutdown, String shutdownReason) { }

public final record BuildInfo(String productUri, String manufacturerName, String productName,
String softwareVersion, String buildNumber, Instant buildDate) { }

// 「build」というフィールド名は「build」(ではない buildInfo)であり、データ型は「long」(「int」ではない)である secondsTillShutdown ことに注意してください。
public enum ServerState {
Running, // 正常
Failed, // 致命的な不具合
NoConfiguration, // 設定が不足しています
Suspended, // 運用チームによって一時停止された
Shutdown, // 停止中
Test, // テストモード
CommunicationFault, // 回線障害
Unknown // SDK 最終的な保証
}

ServerState トップレベルの列挙型( Enums 内に含まれない)であり、定数名はPascalCaseです。

コード例​

import com.darra.opcua.*;
import java.time.Duration;
import java.time.Instant;

try (OpcUaSession ua = new OpcUaSession("opc.tcp://localhost:4840")) {
ua.connect();

// 1) 使い捨て
ServerStatus status = ua.readServerStatus();
System.out.println("Start = " + status.startTime());
System.out.println("Now = " + status.currentTime());
System.out.println("State = " + status.state());
System.out.println("Build = " + status.build());

if (status.state() != ServerState.Running)
System.out.println("⚠ 服务端非 Running, 倒计时 " + status.secondsTillShutdown() + "s");

// 2) 軽量ハートビート
if (ua.readServerState() == ServerState.Running)
statusLabel.setText("在线");

// 3) クロックのドリフト
Instant serverNow = ua.readCurrentTime();
if (serverNow != null) {
long driftMs = Duration.between(serverNow, Instant.now()).toMillis();
System.out.printf("时钟差 = %d ms%n", driftMs);
}
}

多言語対照​

C#PythonJavaC++RustC
ReadServerStatusread_server_statusreadServerStatusReadServerStatusread_server_statusDarraUa_Session_ReadServerStatus
ReadServerStateread_server_statereadServerStateReadServerStateread_server_stateDarraUa_Session_ReadServerState

次のステップ​