Initializing Variables within Generated UA Modeler Code

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

Moderator: uasdkcpp

Post Reply
spn825
Full Member
Full Member
Posts: 5
Joined: 16 Jul 2018, 17:36

Initializing Variables within Generated UA Modeler Code

Post by spn825 »

Hello,

Using the UA modeler, I have created a small test model to experiment with. The model contains an object that I created called TestNumbers which contains two double variables called num1 and num2. I used the demo server to read the XML representation of this model, which then could easily connect to a client. When the client reads the values for num1 and num2, the values are defaulted to 0.0. I initially wanted to test if I could modify these default values, so I went into tnns_testnumbersbase.cpp ( the abbreviation for the namespace was chosen to be tnns) and changed the following code:

Code: Select all

  // Mandatory variable num1
        defaultValue.setDouble(4.0); //initially contained 0.0, changed to 4.0
        s_pnum1 = new OpcUa::BaseDataVariableType(UaNodeId(tnnsId_TestNumbers_num1, nsTypeIdx), "num1", tnns::NodeManagerTestNumberNameSpace::getTypeNamespace(), defaultValue, 3, pTypeNodeConfig);
        s_pnum1->setModellingRuleId(OpcUaId_ModellingRule_Mandatory);
        s_pnum1->setValueRank(-1);
        addStatus = pTypeNodeConfig->addNodeAndReference(pObjectType, s_pnum1, OpcUaId_HasComponent);
        UA_ASSERT(addStatus.isGood());
When I saved this and ran the server again, the client still read the value for num1 as 0.0. Am I going about this the wrong way? How should I modify these values? Additionally, I ultimately intend to modify these values to be read by the client as randomly changing numbers. Do you have a recommendation for accomplishing this?

Thank you.

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

Re: Initializing Variables within Generated UA Modeler Code

Post by Support Team »

Hello spn825,

I don't understand exactly how you import the model. There are 2 ways:

1) Import from XML:
You just use the generated XML file to load the model
see DemoServer example (http://documentation.unified-automation ... moServer_3)

2) Use the generated code:
You add the generated nodemanagers to your server (you do not use the XML file).
see Tutorial Lesson 2 (http://documentation.unified-automation ... son02.html)


So if you do any changes in the code they of course only apply if you use option 2) from above.
Note that the code you modified just affects the type not the instance of that object.
Best regards
Unified Automation Support Team

spn825
Full Member
Full Member
Posts: 5
Joined: 16 Jul 2018, 17:36

Re: Initializing Variables within Generated UA Modeler Code

Post by spn825 »

Hello,

Is there documentation available that walks through how to instantiate the object and modify its values?

Thanks.

Post Reply