我正在使用OPC UAs C++ SDK并尝试读取自定义节点。
在执行提供的示例脚本时,可以很好地读取服务器时间戳(遵循第1课:https://documentation.unified-automation.com/uasdkcpp/1.5.5/html/L3GettingStartedClientLesson01.html)
现在,我试图读取一个自定义节点,其中节点标识符是一个字符串-UaExpert的屏幕截图:
但是我在实现它时遇到了问题:
UaStatus SampleClient::read()
{
UaStatus result;
ServiceSettings serviceSettings;
UaReadValueIds nodeToRead;
UaDataValues values;
UaDiagnosticInfos diagnosticInfos;
// Configure one node to read
// We read the value of the ServerStatus -> CurrentTime
nodeToRead.create(1);
//nodeToRead[0].AttributeId = OpcUa_Attributes_Value;
//nodeToRead[0].NodeId.Identifier.Numeric = OpcUaId_Server_ServerStatus_CurrentTime;
nodeToRead[0].AttributeId = 1;
nodeToRead[0].NodeId.Identifier.String = "DISPLAY_VOLTAGE"; //"cant find operator which supports
//type const char[16]"
...
我也不确定AttributeIde是否为NodeID的命名空间-但我没有找到其他名为“AttributeId”的东西。
可能我需要在这里实现自己的属性-但我不知道如何:
typedef struct _OpcUa_String
{
OpcUa_UInt uReserved1; /* Content is private to String Implementation */
#if OPCUA_STRING_SHORT
OpcUa_UInt16 uReserved2; /* Content is private to String Implementation */
#else /* OPCUA_STRING_SHORT */
OpcUa_UInt32 uReserved2; /* Content is private to String Implementation */
#endif /* OPCUA_STRING_SHORT */
OpcUa_Void* uReserved4; /* Content is private to String Implementation */
} OpcUa_String, *OpcUa_pString;
#endif
希望你们能给我提示如何解决这个问题。
提前致谢!
最佳答案
我找到了一种可行的方法:
nodeToRead[0].AttributeId = OpcUa_Attributes_Value;
UaNodeId volt(UaString("DISPLAY_VOLTAGE"), 1); //("Identifierstring", Namespace)
volt.copyTo(&nodeToRead[0].NodeId);
关于c++ - 使用C++ SDK从OPCUA读取自定义节点-字符串作为节点标识符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61610391/