CVB++ 14.0
OpcUa/BareboneClient
1// ----------------------------------------------------------------------------
16// ----------------------------------------------------------------------------
17
18#include <iostream>
19#include <cvb/opcua/client.hpp>
20
21int main(int, char*[])
22{
23 try
24 {
25 // start client
26 auto client = Cvb::OpcUa::Client::Create(CVB_LIT("opc.tcp://127.0.0.1:4840"));
27
28 // get "central" root folder node as the startpoint
29 auto root = client->RootNode();
30
31 {
32 // ...and appling the browsefilter (this will find all "children" of the rootfolder node)
33 auto result = root->Browse(*Cvb::OpcUa::BrowseFilter::Create());
34
35 // print the display name of all results.
36 std::cout << "------------------------------------" << std::endl;
37 for (auto & res : result)
38 {
39 // print the displayname
40 std::cout << "found node: " << client->Node<Cvb::OpcUa::BaseNode>(*res)->DisplayName() << std::endl;
41 }
42 std::cout << "------------------------------------" << std::endl;
43 }
44
45 {
46 // get object folder node as the startpoint
47 auto obj = client->Node(*Cvb::OpcUa::NodeID::Create(Cvb::OpcUa::Namespace0NodeID::OBJECTSFOLDER));
48
49 // ...and appling the browsefilter (this will find all "children" of the objectfolder node)
50 auto result2 = obj->Browse(*Cvb::OpcUa::BrowseFilter::Create());
51
52 // print the display name of all results.
53 std::cout << "------------------------------------" << std::endl;
54 for (auto & res : result2)
55 {
56 // print the displayname
57 std::cout << "found node: " << client->Node<Cvb::OpcUa::BaseNode>(*res)->DisplayName() << std::endl;
58 }
59 std::cout << "------------------------------------" << std::endl;
60 }
61 }
63 {
64 std::cout << e1.what() << std::endl;
65 return e1.ErrorCode();
66 }
67 catch (const std::exception & ex)
68 {
69 std::cout << ex.what() << std::endl;
70 return -1;
71 }
72 return 0;
73}
An OPCUA BaseNode. This is the base for all other node classes. For instantiation of a specific node ...
Definition: decl_base_node.hpp:35
String DisplayName() const
Returns the humanreadable name of a node.
Definition: decl_base_node.hpp:91
static BrowseFilterPtr Create()
Creates an even simpler BrowseFilter for browsing the OPCUA client.
Definition: browse_filter.hpp:76
static OpcUa::ClientPtr Create(const Cvb::String &Url)
Creates an OPCUA Client object. And connect it to a given server. There is no disconnect/connect func...
Definition: detail_client.hpp:24
static NodeIDPtr Create(Namespace0NodeID id)
Creates an id based on a predefined Namespace0 node id.
Definition: node_id.hpp:48
Special runtime exception to carry a native error code.
Definition: exception.hpp:25
int ErrorCode()
Retuns the error code. See Cvb::ErrorCodes.
Definition: exception.hpp:50