我正在使用 open62541 库 [1.1.2-216-g50933d8]。告诉我如何将工程单元添加到我的节点?Му 节点创建:
bool isOk = true;
UA_VariableAttributes valueAttr = UA_VariableAttributes_default;
UA_Variant_init(&valueAttr.value);
UA_Float valueVal = 0;
UA_Variant_setScalar(&valueAttr.value, &valueVal, &UA_TYPES[UA_TYPES_FLOAT]);
std::string description = "Value Params";
valueAttr.description = UA_LOCALIZEDTEXT(const_cast<char*>(lt), const_cast<char*>(description.c_str()));
valueAttr.displayName = UA_LOCALIZEDTEXT(const_cast<char*>(lt), const_cast<char*>("Value"));
if(UA_Server_addVariableNode(server, UA_NODEID_NULL,
getNodeId(),
UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT),
UA_QUALIFIEDNAME(nsIndexBrowser, const_cast<char*>("Value")),
UA_NODEID_NUMERIC(0, UA_NS0ID_BASEDATAVARIABLETYPE),
valueAttr, nullptr, &value_) != UA_STATUSCODE_GOOD)
{
return isOk;
}
我试图这样做:
UA_EUInformation eu;
eu.namespaceUri = UA_STRING("somecompany.com");
eu.unitId = -1;
eu.displayName = UA_LOCALIZEDTEXT(const_cast<char*>(lt), const_cast<char*>(typeSigne_->getEUid().c_str()));
eu.description = UA_LOCALIZEDTEXT(const_cast<char*>(lt), const_cast<char*>(typeSigne_->getEUid().c_str()));
UA_StatusCode status = UA_Server_writeObjectProperty_scalar(server,
value_,
UA_QUALIFIEDNAME(nsIndexBrowser, "EngineeringUnits"),
&eu,
&UA_TYPES[UA_TYPES_EUINFORMATION]);
if(status != UA_STATUSCODE_GOOD)
{
return isOk;
}
但我得到了错误代码 UA_STATUSCODE_BADNOMATCH
我试图这样做:
UA_EUInformation eu;
eu.namespaceUri = UA_STRING("somecompany.com");
eu.unitId = -1;
eu.displayName = UA_LOCALIZEDTEXT(const_cast<char*>(lt), const_cast<char*>(typeSigne_->getEUid().c_str()));
eu.description = UA_LOCALIZEDTEXT(const_cast<char*>(lt), const_cast<char*>(typeSigne_->getEUid().c_str()));
UA_VariableAttributes enAttr = UA_VariableAttributes_default;
UA_VariableAttributes_init(&enAttr);
enAttr.dataType = UA_TYPES[UA_TYPES_EUINFORMATION].typeId;
enAttr.userWriteMask = UA_ACCESSLEVELMASK_READ;
UA_Variant_setScalarCopy(&enAttr.value, &eu, &UA_TYPES[UA_TYPES_EUINFORMATION]);
UA_StatusCode status = UA_Server_addVariableNode(server, UA_NODEID_NULL,
value_,
UA_NODEID_NUMERIC(0, UA_NS0ID_HASPROPERTY),
UA_QUALIFIEDNAME(nsIndexBrowser, "EngineeringUnits"),
UA_NODEID_NUMERIC(0, UA_NS0ID_PROPERTYTYPE),
enAttr,
nullptr, &enUnitNodeUnits_);
if(status != UA_STATUSCODE_GOOD)
{
return isOk;
}
但我得到了错误代码 UA_STATUSCODE_BADTYPEMISMATCH
我还尝试了这些示例https://groups.google.com/g/open62541/c/90dpSO2Wu7E/m/mNUknnRSCAAJ。他们不工作。
通常,我尝试向我的对象添加任何属性,但也没有成功(UA_STATUSCODE_BADTYPEMISMATCH)。
我不明白为什么我做不到?