open62541pp 0.15.0
C++ wrapper of open62541
Loading...
Searching...
No Matches
server.cpp
#include <iostream>
int main() {
opcua::Server server(4840 /* port */);
server.setApplicationName("open62541pp server example");
server.setApplicationUri("urn:open62541pp.server.application");
server.setProductUri("https://open62541pp.github.io");
// Add a variable node to the Objects node
opcua::Node myIntegerNode = parentNode.addVariable(
{1, "TheAnswer"},
"The Answer",
.setDisplayName({"en-US", "The Answer"})
.setDescription({"en-US", "Answer to the Ultimate Question of Life"})
.setDataType<int>()
);
// Write a value (attribute) to the node
myIntegerNode.writeValueScalar(42);
// Read the value (attribute) from the node
std::cout << "The answer is: " << myIntegerNode.readValueScalar<int>() << std::endl;
server.run();
}
High-level node class to access node attribute, browse and populate address space.
Definition server.hpp:27
Node & writeValueScalar(const T &value)
Write scalar to variable node.
Definition node.hpp:537
T readValueScalar()
Read scalar value from variable node.
Definition node.hpp:403
Node addVariable(const NodeId &id, std::string_view browseName, const VariableAttributes &attributes={}, const NodeId &variableType=VariableTypeId::BaseDataVariableType, const NodeId &referenceType=ReferenceTypeId::HasComponent)
Add variable.
Definition node.hpp:102
High-level server class.
Definition server.hpp:63
void setApplicationName(std::string_view name)
Set application name, default: open62541-based OPC UA Application.
void setProductUri(std::string_view uri)
Set product URI, default: http://open62541.org.
void run()
Run the server's main loop. This method will block until Server::stop is called.
void setApplicationUri(std::string_view uri)
Set application URI, default: urn:open62541.server.application.
UA_VariableAttributes wrapper class.
auto & setDisplayName(const LocalizedText &displayName)