#include <iostream>
template <typename T>
bool timestamp
) override {
std::cout << "Read value from data source: " << data << "\n";
if (timestamp) {
}
}
) override {
std::cout << "Write value to data source: " << data << "\n";
}
T data{};
};
int main() {
const auto id =
server,
opcua::ObjectId::ObjectsFolder,
{1, 1000},
"DataSource",
.setDataType<int>(),
opcua::VariableTypeId::BaseDataVariableType,
opcua::ReferenceTypeId::HasComponent
).value();
DataSource<int> dataSource;
}
Data source base class for variable nodes.
virtual StatusCode read(Session &session, const NodeId &id, const NumericRange *range, DataValue &value, bool timestamp)=0
Callback to set the read value, the result status and optionally a source timestamp.
virtual StatusCode write(Session &session, const NodeId &id, const NumericRange *range, const DataValue &value)=0
Callback to write the value into a data source.
UA_DataValue wrapper class.
void setSourceTimestamp(DateTime sourceTimestamp) noexcept
Set source timestamp for the value.
Variant & value() &noexcept
Get value.
void setValue(const Variant &value)
Set value (copy).
static DateTime now() noexcept
Get current DateTime.
UA_NumericRange wrapper class.
void setVariableNodeDataSource(const NodeId &id, DataSourceBase &source)
Set data source for variable node.
void run()
Run the server's main loop. This method will block until Server::stop is called.
High-level session class to manage client sessions.
UA_StatusCode wrapper class.
UA_Variant wrapper class.
T to() const
Converts the variant to the specified type T with automatic conversion if required.
UA_VariableAttributes wrapper class.
auto & setAccessLevel(Bitmask< AccessLevel > accessLevel) noexcept
Result< NodeId > addVariable(T &connection, const NodeId &parentId, const NodeId &id, std::string_view browseName, const VariableAttributes &attributes, const NodeId &variableType, const NodeId &referenceType) noexcept
Add variable.
#define UA_STATUSCODE_GOOD