Default value of structured datatype

Questions regarding the use of UaModeler

Moderator: uamodeler

Post Reply
Maarten_BE
Sr. Member
Sr. Member
Posts: 18
Joined: 25 Feb 2015, 15:58

Default value of structured datatype

Post by Maarten_BE »

Hi support team,

I am doing an evaluation of the latest C++ SDK/UaModeler and I am running into the following issue:

I created a subclass from AnalogItemType called MyCoolTemperatureType and overridden the EngineeringUnits property. I entered the "degrees celcius" engineering unit as value of the overriden EngineeringUnits property.

The goal is to already provide the degrees C value in the Type so that it is pre-filled when instantiating a MyCoolTemperatureType variable.

However the codegen C++ template 1.7 does not seem to take the default value into account. The resulting code just enters an emtpy default value:

Code: Select all

...
UaVariant     defaultValue;
...
 // Mandatory variable EngineeringUnits
        UaEUInformation valEngineeringUnits;
        valEngineeringUnits.toVariant(defaultValue);
        s_pEngineeringUnits = new OpcUa::PropertyType(UaNodeId(msgcatalogId_MyCoolTemperatureType_EngineeringUnits, nsTypeIdx), "EngineeringUnits", NodeManagerRoot::getTypeNamespace(), defaultValue, 1, pTypeNodeConfig);
        s_pEngineeringUnits->setDataType(UaNodeId(OpcUaId_EUInformation));
        s_pEngineeringUnits->setModellingRuleId(OpcUaId_ModellingRule_Mandatory);
        s_pEngineeringUnits->setValueRank(-1);
        addStatus = pTypeNodeConfig->addNodeAndReference(pVariableType, s_pEngineeringUnits, OpcUaId_HasProperty);
        UA_ASSERT(addStatus.isGood());
I would expect that the default value would be entered like this:

Code: Select all

    ...
    pEngineeringUnits->setDataTypeId(OpcUaId_EUInformation);
    {
        UaEUInformation valEngineeringUnits = UaEUInformation(
            "http://www.opcfoundation.org/UA/units/un/cefact",
            4408652,
            UaLocalizedText("", "\302\260C"),
            UaLocalizedText("", "degree Celsius"));
        valEngineeringUnits.toVariant(defaultValue);
    }
    pEngineeringUnits->setValue(defaultValue);
   ...
For simple datatypes like Doubles it does work as expected, only for structured datatypes the default value seems not to be set.

Is there a explanation/workaround for this?

Best regards,

Maarten

User avatar
Support Team
Hero Member
Hero Member
Posts: 3064
Joined: 18 Mar 2011, 15:09

Re: Default value of structured datatype

Post by Support Team »

Hello Maarten,

As a workaround you can set the value in the afterStartUp method of the generated NodeManager.
Best regards
Unified Automation Support Team

Post Reply