Discovery 发现
darra::opcua::Discovery 是静态类, 不需要 Session 即可调用. 用于"连接前先探测":
子页跳转
- 列出某 Server 全部 Endpoint 请参考 GetEndpoints.
- 通过 LDS 列出域内全部 Server 请参考 FindServers.
头文件
#include <darra/opcua/discovery.hpp>
using namespace darra::opcua;
用法模式
Stack::Init();
// 1. 先 GetEndpoints 看服务端支持哪些组合
auto endpoints = Discovery::GetEndpoints("opc.tcp://server:4840");
// 2. 挑一个匹配的 (例如 SignAndEncrypt + Username)
EndpointDescription const* picked = nullptr;
for (auto const& ep : endpoints) {
if (ep.security_mode == MessageSecurityMode::SignAndEncrypt) {
for (auto const& t : ep.user_identity_tokens) {
if (t.token_type == UserTokenType::Username) {
picked = &ep;
break;
}
}
if (picked) break;
}
}
// 3. 用挑出来的 Endpoint 真正连接
ConnectionConfig cfg;
cfg.endpoint_url = picked->endpoint_url;
cfg.security_mode = picked->security_mode;
cfg.security_policy_uri = picked->security_policy_uri;
cfg.username = "operator";
cfg.password = "secret";
cfg.client_cert_path = "client.pfx";
cfg.client_key_path = "123456";
Session s(cfg);
s.Connect();