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

BrowseWithPaging

Browse References リストのみを返し、残りは破棄します ContinuationPoint。「既知の子ノードが少ない」というシナリオに適しています。子ノード数が一ページあたりの上限(クライアントからのリクエストで固定 requestedMaxReferencesPerNode の1000)を超える可能性がある場合は、明示 BrowseWithPaging 的に取得して BrowsePage、ページ送りを行う必要があります。

事前学習

署名​

BrowseWithPaging これは Session のメンバーメソッドです。

namespace darra::opcua {

class Session {
public:
BrowsePage BrowseWithPaging(
std::string const& node_id,
NodeClass filter = NodeClass::Unspecified);
};

}

使用方法​

#include <darra/opcua/client.hpp>
#include <iostream>

using namespace darra::opcua;

Session s("opc.tcp://localhost:4840");
s.Connect();

auto page = s.BrowseWithPaging("ns=2;s=BigFolder");
std::cout << "Got " << page.references.size()
<< " children, more = " << !page.continuation_point.empty() << "\n";

if (!page.continuation_point.empty()) {
auto next = s.BrowseNext(page.continuation_point);
std::cout << "Next page: " << next.references.size() << " more children\n";
}

いつ使うか Browse vs BrowseWithPaging​

シナリオAPI
子ノードの数は一ページあたりの上限内に収まるように設定されており、ページ分割は考慮しないBrowse(...)
子ノードの数が不明BrowseWithPaging(...) + ループ BrowseNext
子ノードは数千に及ぶ可能性があるBrowseWithPaging(...) 必須(指定しない場合、一ページ目だけが静かに取得されます)
一度に複数のノードを閲覧するBrowseMany(...) (注意:現在は BrowseMany 返されません ContinuationPoint)

完全なテンプレート​

これはあなたが自分で書いた補助関数

SDK です ないBrowseAll これ API ―― 以下の部分は BrowseWithPaging + BrowseNext をつなぎ合わせたものですユーザー側のテンプレート, 自分のプロジェクトにコピーして使用してください。外部 #include から呼び出さないでください。

// ユーザー側の補助機能(非 SDK API):すべてのページを自動的にめくる
std::vector<darra::opcua::Reference> BrowseAll(
darra::opcua::Session& s,
std::string const& node_id,
darra::opcua::NodeClass filter = darra::opcua::NodeClass::Unspecified)
{
std::vector<darra::opcua::Reference> all;
auto page = s.BrowseWithPaging(node_id, filter);
all.insert(all.end(), page.references.begin(), page.references.end());

while (!page.continuation_point.empty()) {
page = s.BrowseNext(page.continuation_point);
all.insert(all.end(), page.references.begin(), page.references.end());
}
return all;
}

次のステップ​