Login  •  Register


Converting UaDataValue to string

Questions regarding the use of the C++ SDK for Server or Client development or integration into customer products ...

Converting UaDataValue to string

Postby RafaelCrespi » 09 Aug 2017, 14:23

Hi,

I want to printf the value of a BaseDataVariableType node so I am implementing the next code on the Server's side:

Code: Select all
...
UaDataValue dataValue = p_BaseDataVariable->value(NULL);
printf("\nNode content: %s \n",UaVariant(dataValue.value(),OpcUa_False).toString().toUtf8()));
...


I get an error because it expects UaVariant(OpcUa_Variant*) and dataValue.value() returns 'const OpcUa_Variant*'

I am shure it has a very simply solution but I don't see it.

Thank you in advance,

Rafa CrespĂ­
RafaelCrespi
Hero Member
Hero Member
 
Posts: 26
Joined: 22 Jun 2017, 09:41

Re: Converting UaDataValue to string

Postby mantela » 10 Aug 2017, 08:42

Hi,

I think you need the same function as it is used in the read method which is implemented in the Client tutorial. This is the code I use for converting UaDataValue to String (the variable values is from type UaDataValues, that's why i use values[i]):

qDebug("Read succeeded for node %s with value %s", UaNodeId(readValues[i].NodeId).toXmlString().toUtf8(),
UaVariant(values[i].Value).toString().toUtf8());

Andre
mantela
Hero Member
Hero Member
 
Posts: 21
Joined: 28 Mar 2017, 07:20

Re: Converting UaDataValue to string

Postby RafaelCrespi » 10 Aug 2017, 14:39

Hi Andre,

I have tried that and it doesn't work. The difference is that values[i].Value returns OpcUa_Variant type, while dataValue.value() returns const OpcUa_Variant* type, so I think that's the main problem.

Thank you for reply

Rafa
RafaelCrespi
Hero Member
Hero Member
 
Posts: 26
Joined: 22 Jun 2017, 09:41

Re: Converting UaDataValue to string

Postby RafaelCrespi » 10 Aug 2017, 15:06

Hi everyone,

I have fixed it converting the 'const OpcUa_Variant* ' to ' OpcUa_Variant* ' with the next code:

Code: Select all
printf("\nNode content: %s \n",UaVariant(const_cast<OpcUa_Variant*>(dataValue.value())).toString().toUtf8());


I don't know if it is the smartest solution, but it works.

Rafa CrespĂ­
RafaelCrespi
Hero Member
Hero Member
 
Posts: 26
Joined: 22 Jun 2017, 09:41

Re: Converting UaDataValue to string

Postby Support Team » 11 Aug 2017, 06:42

You find the sample code in the client tutorial e.g. client_cpp_sdk.cpp method read()

Code: Select all
    UaNodeId node
    UaDataValues values;
...
    UaVariant tempValue = values[i].Value;
    if (tempValue.type() == OpcUaType_ExtensionObject)
    {
        printExtensionObjects(tempValue, UaString("Variable %1").arg(node.toString()));
    }
    else
    {
        printf("  Variable %s value = %s\n", node.toString().toUtf8(), tempValue.toString().toUtf8());
    }
Best regards
Unified Automation Support Team
User avatar
Support Team
Hero Member
Hero Member
 
Posts: 2422
Joined: 18 Mar 2011, 15:09

Re: Converting UaDataValue to string

Postby RafaelCrespi » 21 Aug 2017, 07:59

Hi,

I have tried that way but it doesn't works. The difference is that you are using UaDataValues, and values[i].Value() returns an OpcUa_Variant. In my case, I am using UaDataValue, and value.value() returns OpcUa_Variant*.


Thanks,


Rafa
RafaelCrespi
Hero Member
Hero Member
 
Posts: 26
Joined: 22 Jun 2017, 09:41

Re: Converting UaDataValue to string

Postby pycipyna » 07 Oct 2019, 07:57

thank you
Forum unified-automation is the forum which is provide the information of the user control panel and also provide the information of the service which is https://www.a-writer.com/professional-college-essay-writers/ provided through the website to the consumer and also give the new all information to the audience.
pycipyna
Jr. Member
Jr. Member
 
Posts: 1
Joined: 07 Oct 2019, 07:56


Return to C++ based OPC UA SDK

Who is online

Users browsing this forum: No registered users and 0 guests