我正在使用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
希望你们能给我提示如何解决这个问题。
提前感谢!
由于您正在使用他们的产品,我认为您将来应该考虑在统一自动化论坛上发布您的问题。
我也认为这应该起作用:
UaString volt("DISPLAY_VOLTAGE");
nodeToRead[0].NodeId.Identifier.String = volt;
AttributeId,是一个代表您要读取的节点的属性的值。在您的情况下为Value,因此您应该使用OpcUa_Attributes_Value。
您还可以使用OpcUa_Attributes_DisplayName,OpcUa_Attributes_NodeClass,...,取决于要读取的节点的OPC UA属性。您可以找到属性列表here
我找到了一种可行的方法:
nodeToRead[0].AttributeId = OpcUa_Attributes_Value;
UaNodeId volt(UaString("DISPLAY_VOLTAGE"), 1); //("Identifierstring", Namespace)
volt.copyTo(&nodeToRead[0].NodeId);