서버 정보
개요
OPC UA 표준 노드 i=2256 (Server.ServerStatus)는 서버 런타임 정보를 노출합니다.SDK 그대로 해석하지 않고 ExtensionObject, i=2257 / i=2258 / i=2259 / i=2261..i=2266 / i=2992 / i=2993 등 총 11개의 하위 노드를 각각 읽은 후, 오류 허용 방식으로 강타입으로 조립합니다 ServerStatus.
해당 규격 조항: 제5부 §6.3.
API
세 개의 엔트리는 모두 darra::opcua 네임스페이스 아래에 있는 자유 함수(server_info.hpp)로, 첫 번째 매개변수로 Session&을 전달하며, Session의 멤버 메서드가 아닙니다.
| 함수 | 분류 | 읽기 및 쓰기 | 설명 |
|---|---|---|---|
| ReadServerStatus | 진단 | 읽기 | 한 번에 모두 조립 ServerStatus(총 11회 조회 RPC) |
| ReadServerState | 진단 | 읽기 | 읽기 전용 i=2259, 단일 RPC |
| ReadCurrentTimeFileTime | 진단 | 읽기 | 읽기 전용 i=2258, 단일 RPC, 반환 int64_t FileTime |
namespace darra::opcua {
// 11회 읽기 RPC 조립; 어떤 필드에서든 읽기 실패 시 기본값을 사용하며, state는 Unknown으로 처리됩니다. 예외는 발생하지 않습니다.
ServerStatus ReadServerStatus(Session& s);
// 읽기 전용 i=2259. 실패 시 반환 ServerState::Unknown, 예외 발생 없음.
ServerState ReadServerState(Session& s);
// 읽기 전용 i=2258. 실패 시 0을 반환합니다. 소요 시간은 FileTime (UTC 1601년 이후 100ns ), 아닙니다. time_point.
int64_t ReadCurrentTimeFileTime(Session& s);
}
관련 구조 (ServerStatus 필드):
- start_time_filetime (int64_t) — 시작 시간, FileTime (UTC 100ns 1601년부터)
- current_time_filetime (int64_t) — 현재 시간, FileTime
- state (ServerState) — 현재 상태
- build (BuildInfo) — 제품/버전
- seconds_till_shutdown (uint32_t) — 종료까지 남은 시간(초)
- shutdown_reason (std::string) — 종료 사유
- ToString() — 조합하여
State=..., Start=..., Now=..., Build=[...]
관련 구조 (BuildInfo 필드):
- product_uri / manufacturer_name / product_name / software_version / build_number (std::string)
- build_date_filetime (int64_t) — 빌드 날짜, FileTime, 0 = 알 수 없음
- ToString() — 조합
产品名 版本 (build 编号)
관련 구조체 (ServerState 열거형):
- 실행 중 (0) — 정상
- 실패 (1) — 치명적인 오류
- NoConfiguration (2) — 구성 없음
- Suspended (3) — 운영팀에 의해 일시 정지됨
- Shutdown (4) — 종료 중
- Test (5) — 테스트 모드
- CommunicationFault (6) — 링크 오류
- Unknown (7) — SDK 보장
코드 예시
#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) 일회성 조립 (총 11회 조회 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) 경량 하트비트 (단일 RPC)
if (ReadServerState(s) == ServerState::Running)
std::cout << "在线\n";
// 3) 클럭 드리프트 — 서버에서 반환된 FileTime값을 먼저 환산한 후 비교
constexpr int64_t WIN_EPOCH_OFFSET = 116444736000000000LL;
int64_t server_ft = ReadCurrentTimeFileTime(s); // 0 = 읽기 실패
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 모두 FileTime(UTC 100ns since 1601-01-01)이며, Windows와 일치하고 DateTime.ToFileTimeUtc , 는 아닙니다 system_clock::time_point.
다국어 대조
| 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 |
C++에서 이 세 가지는 자유 함수이며, 첫 번째 인자는 입니다 Session&. C# / Python / Java / Rust에서는 세션 객체의 메서드입니다.