Extending model in other Namespace
Moderator: uamodeler
-
- Sr. Member
- Posts: 13
- Joined: 28 Jun 2016, 02:06
Extending model in other Namespace
Hello, I have created a model and imported it with a specific namespace.
Then I created a subtype in a new model (another namespace) for a type within the imported model.
When creating the Code it seems to miss the NodeId of the derived BaseType:
pTypeNodeConfig->addNodeAndReference(UaNodeId(, nsSuperTypeIdx), pObjectType, OpcUaId_HasSubtype);
Manually adding the ID in front of the comma fixes the compilation. Any clue if I'm working against best practices
or if that's an issue in the generator?
Then I created a subtype in a new model (another namespace) for a type within the imported model.
When creating the Code it seems to miss the NodeId of the derived BaseType:
pTypeNodeConfig->addNodeAndReference(UaNodeId(, nsSuperTypeIdx), pObjectType, OpcUaId_HasSubtype);
Manually adding the ID in front of the comma fixes the compilation. Any clue if I'm working against best practices
or if that's an issue in the generator?
- Support Team
- Hero Member
- Posts: 3072
- Joined: 18 Mar 2011, 15:09
Re: Extending model in other Namespace
You need to generate code for all of your models in one step. Please select your base model, too.
Please see the documentation.
Please see the documentation.
Best regards
Unified Automation Support Team
Unified Automation Support Team
-
- Sr. Member
- Posts: 13
- Joined: 28 Jun 2016, 02:06
Re: Extending model in other Namespace
Yeah I've done that ever since (I'm only using one project for all my models). I remodelled everything and now it's working, not sure what went wrong.
Now when I add a GenerateEvents reference with GeneralModelChangeEvent I getproto_opc_cppd: /home/impulze/proto_opc/project_cpp/src/models/opcuacnc_cncaxislisttypebase.cpp:98: void OpcUaCnc::CncAxisListTypeBase::initialize(): Assertion `addStatus.isGood()' failed.
during startup.
The status is BadNodeIdUnknown which is caused by the following method call:
addStatus = m_pNodeConfig->addUaReference(this->nodeId(), OpcUaId_GeneralModelChangeEventType, OpcUaId_GeneratesEvent);
Adding the GeneralModelChangeEvent to other types in the model seems to work. Any way to debug this?
Now when I add a GenerateEvents reference with GeneralModelChangeEvent I getproto_opc_cppd: /home/impulze/proto_opc/project_cpp/src/models/opcuacnc_cncaxislisttypebase.cpp:98: void OpcUaCnc::CncAxisListTypeBase::initialize(): Assertion `addStatus.isGood()' failed.
during startup.
The status is BadNodeIdUnknown which is caused by the following method call:
addStatus = m_pNodeConfig->addUaReference(this->nodeId(), OpcUaId_GeneralModelChangeEventType, OpcUaId_GeneratesEvent);
Adding the GeneralModelChangeEvent to other types in the model seems to work. Any way to debug this?
- Support Team
- Hero Member
- Posts: 3072
- Joined: 18 Mar 2011, 15:09
Re: Extending model in other Namespace
The GeneralModelChangeEventType nodes are not added by default. Please update your NodeManager implementation class:
Code: Select all
#include "opcua_basemodelchangeeventtypedata.h"
Code: Select all
UaStatus NodeManager<NamespaceName>::afterStartUp()
{
OpcUa::GeneralModelChangeEventTypeData::createTypes();
// The address space is created by the base class
UaStatus ret = NodeManager<NamespaceName>Base::afterStartUp();
// ...
Best regards
Unified Automation Support Team
Unified Automation Support Team
-
- Sr. Member
- Posts: 13
- Joined: 28 Jun 2016, 02:06
Re: Extending model in other Namespace
Sadly this doesn't solve the issue. I created a minimal test example that triggers the assertion:
1.) Create Test1ObjectType (derived from BaseObjectType) and add a GeneratesEvents reference to a GeneralModelChangeEvent Target
2.) Generate code, add NodeManager to server, runs fine
3.) Create a Test2ObjectType (derived from BaseObjectType) with a child (HasComponent) Test1Object with a Test1ObjectType TypeDefinition.
4.) Generate code, running fails with said assertion (even when adding the createTypes call in either NodeManager or NodeManagerBase)
1.) Create Test1ObjectType (derived from BaseObjectType) and add a GeneratesEvents reference to a GeneralModelChangeEvent Target
2.) Generate code, add NodeManager to server, runs fine
3.) Create a Test2ObjectType (derived from BaseObjectType) with a child (HasComponent) Test1Object with a Test1ObjectType TypeDefinition.
4.) Generate code, running fails with said assertion (even when adding the createTypes call in either NodeManager or NodeManagerBase)
- Support Team
- Hero Member
- Posts: 3072
- Joined: 18 Mar 2011, 15:09
Re: Extending model in other Namespace
Thank you for detailed description. We will fix the issue in the next version of the templates.
Best regards
Unified Automation Support Team
Unified Automation Support Team
-
- Sr. Member
- Posts: 13
- Joined: 28 Jun 2016, 02:06
Re: Extending model in other Namespace
You're welcome. Is there a current workaround that I could use?
- Support Team
- Hero Member
- Posts: 3072
- Joined: 18 Mar 2011, 15:09
Re: Extending model in other Namespace
Hello,
you can only delete the GeneratesEvent reference in the model and add the reference in code. Please add the reference in the implementation file of your type (i.e. in file <Type>.cpp and not <Type>Base.cpp). When generating code again the implementation files are not overwritten by default.
Best Regards
Support Team
you can only delete the GeneratesEvent reference in the model and add the reference in code. Please add the reference in the implementation file of your type (i.e. in file <Type>.cpp and not <Type>Base.cpp). When generating code again the implementation files are not overwritten by default.
Best Regards
Support Team
-
- Sr. Member
- Posts: 13
- Joined: 28 Jun 2016, 02:06
Re: Extending model in other Namespace
I doesn't seem to make a difference if I put it in the Base cpp or Implementation cpp file.
Is my assumption right, that I have to add a GeneratesEvent reference to the Type and to the instances?
The assertion doesn't fail when adding the reference to the type.
If I'm following the code right the assertion fails with this->nodeId() because the previous function is adding the nodeId to the manager and hence makes it visible (no more BadeNodeId).
Do I have to add the reference to the function call creating the instance instead of in the instance itself? Or is it sufficient to add the reference to the type?
Is my assumption right, that I have to add a GeneratesEvent reference to the Type and to the instances?
The assertion doesn't fail when adding the reference to the type.
If I'm following the code right the assertion fails with this->nodeId() because the previous function is adding the nodeId to the manager and hence makes it visible (no more BadeNodeId).
Do I have to add the reference to the function call creating the instance instead of in the instance itself? Or is it sufficient to add the reference to the type?