Hi Unified Automation Team,
I'd like to iterate through the references of an UaNode on serverside. I use following method:
const UaReference * UaReferenceLists:: pTargetNodes () const [virtual]
Here is an excerpt of the documentation of this method:
"Use UaReference:: pNextForwardReference to iterate through the list of forward references."
This method is declared in the following way:
UaReference* UaReference:: pNextForwardReference () [inline]
The problem is that the first method returns a "const UaReference *". The second one is not declared as const. So there is a compiler error.
I think that either the first method should must not return a const pointer (a) or the second one shoud be declared as const (b) or both:
(a) UaReference * UaReferenceLists:: pTargetNodes () const [virtual]
(b) UaReference* UaReference:: pNextForwardReference () const [inline]
Can you please give me a feedback.
Thanks in advance.
Best regards
Thomas
Iterate through the references of an UaNode
Moderator: uasdkcpp
-
- Jr. Member
- Posts: 3
- Joined: 11 Jan 2012, 11:24
- Support Team
- Hero Member
- Posts: 3068
- Joined: 18 Mar 2011, 15:09
Re:Iterate through the references of an UaNode
Hi,
It is strongly recommended to use ServerManager::browse() for access to references of a node. The ServerManager provides an internal client like interface where you can browse, read, write and create monitored items internally in the server. The references stored in the nodes have several different special cases where you would need to write your own handling code. These different cases are all handled by the browse method provided by the ServerManager.
Here you can find an example for the use of the internal client API
http://www.unified-automation.com/forum ... he-sdk.htm
We will check in addition if or how we can modify the API.
Best Regards,
Unified Automation Support Team
It is strongly recommended to use ServerManager::browse() for access to references of a node. The ServerManager provides an internal client like interface where you can browse, read, write and create monitored items internally in the server. The references stored in the nodes have several different special cases where you would need to write your own handling code. These different cases are all handled by the browse method provided by the ServerManager.
Here you can find an example for the use of the internal client API
http://www.unified-automation.com/forum ... he-sdk.htm
We will check in addition if or how we can modify the API.
Best Regards,
Unified Automation Support Team
Best regards
Unified Automation Support Team
Unified Automation Support Team
-
- Hero Member
- Posts: 24
- Joined: 12 Jan 2018, 13:22
Re: Iterate through the references of an UaNode
Very old topic but hasn't changed in the sdk since.
Here is a solution which is working for me.
just create a "reference_helper.h" with the following content:
Just added the "const" to the function definition, which is IMHO missing in the SDK's version.
And you can use it like, the following to iterate the children of UaNode* parent:
Here is a solution which is working for me.
just create a "reference_helper.h" with the following content:
Code: Select all
#ifndef __MY_REFERENCE_HELPER_H__
#define __MY_REFERENCE_HELPER_H__
#include <uabasereferences.h>
namespace my {
class UaReference : public ::UaReference
{
public:
inline UaReference* pNextForwardReference() const { return (my::UaReference*)m_pNextForwardReference; }
inline UaReference* pNextInverseReference() const { return (my::UaReference*)m_pNextInverseReference; }
};
}
#endif
And you can use it like, the following to iterate the children of UaNode* parent:
Code: Select all
#include "reference_helper.h"
...
UaNode *node;
UaReferenceLists* refs = parent->getUaReferenceLists();
if(refs) {
const my::UaReference* target = (const my::UaReference*)refs->pTargetNodes();
while(target != NULL) {
node = target->pTargetNode();
if(node) {
// do something with the node .....
}
target = target->pNextForwardReference();
}
}
....