Hello !
I'm tying to create a OPC UA Client using open62541 implementation of OPC UA with Qt5.
As I am a beginner I have trouble to read simple String on the server and cast it to QString so i can display it ...
I have created a custom function 'readStringValue()' :
UA_StatusCode MyUaClient::readStringValue(UA_UInt16 nsIndex, QString nodeId)
{
UA_StatusCode retval;
UA_NodeId node = UA_NODEID_STRING_ALLOC(nsIndex, nodeId.toLatin1().data());
UA_Variant value;
// UA_Variant_init(&value);
UA_Variant *val = UA_Variant_new();
UA_StatusCode retval;
retval = UA_Client_readValueAttribute(client,node, val);
if(retval == UA_STATUSCODE_GOOD &&
val->type == &UA_TYPES[UA_TYPES_STRING]) {
value = *(UA_Variant*)val->data;
printf("the new value is: %i\n", value);
}
UA_Variant_delete(val);
return retval;
}
On the server my "PLC_IO_String_1" value is 'test' and type is String
But when i call my function 'readStringValue' : readStringValue(1,"PLC_IO_String_1");
it returns : the new value is : 4
So i think i have data type conversion probleme.
Does anyone know where the problem comes from and how to fix this please ?
Thank you in advance
LA