AnalogItemType containing a Method

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

Moderator: uasdkcpp

Post Reply
fpethig
Hero Member
Hero Member
Posts: 37
Joined: 30 Sep 2013, 08:19

AnalogItemType containing a Method

Post by fpethig »

Hello,
I am trying to have Variables of the type AnalogItemType which contain a Method. This Method should be able to delete the selected node from the adress space. Right now I'm struggling with the Error OpcUa_BadNodeIdUnknown when trying to call the Method. So when calling the underlying method of a variable I guess the Server does not find the corresponding NodeId of the Method (the variable itself works). Is it even possible to do what I'm trying to do?

I tried by having my own AnalogItemClasses, a base class inheriting from AnalogItemType and MethodManager:

Code: Select all

#include "opcua_analogitemtype.h"
#include "my_nodemanager.h"
#include "methodmanager.h"

class NmMy;
class UaMethodGeneric;

namespace OpcUa {

class SERVER_CORE_EXPORT my_analogitemtypebase
	: public AnalogItemType, public MethodManager
{
	UA_DISABLE_COPY(my_analogitemtypebase);
public:
   my_analogitemtypebase(
			UaNode*            pParentNode,
	        UaVariable*        pInstanceDeclarationVariable,
	        NodeManagerConfig* pNodeConfig,
	        UaMutexRefCounted* pSharedMutex = NULL);
   my_analogitemtypebase(
			const UaNodeId&    nodeId,
	        const UaString&    name,
	        OpcUa_UInt16       browseNameNameSpaceIndex,
	        const UaVariant&   initialValue,
	        OpcUa_Byte         accessLevel,
	        NodeManagerConfig* pNodeConfig,
	        UaMutexRefCounted* pSharedMutex = NULL,
	        NmMy* pNodeManager = NULL);
   virtual ~my_analogitemtypebase();

   MethodManager* getMethodManager(UaMethod* pMethod) const;

   virtual UaStatus beginCall(
		   MethodManagerCallback* pCallback,
		   const ServiceContext&  serviceContext,
		   OpcUa_UInt32           callbackHandle,
		   MethodHandle*          pMethodHandle,
		   const UaVariantArray&  inputArguments);

	// Own synchronous call implementation the can be overridden in subclasses
	virtual UaStatus call(
		UaMethod*             /*pMethod*/,
		const UaVariantArray& /*inputArguments*/,
		UaVariantArray&       /*outputArguments*/,
		UaStatusCodeArray&    /*inputArgumentResults*/,
		UaDiagnosticInfos&    /*inputArgumentDiag*/) { return OpcUa_BadMethodInvalid; }

	virtual int deleteVariable(UaNodeId nodeID);

protected:

private:
	UaMethodGeneric* m_pMethodDelete;
};

}
#endif /* MYANALOGITEMTYPE_H_ */
and my AnalogItem Class:

Code: Select all

#ifndef MYANALOGITEM_H_
#define MYANALOGITEM_H_

#include "myanalogitemtypebase.h"

class NmMy;
class UaMethodGeneric;

namespace OpcUa {

class myanalogitem
		: public my_analogitemtypebase
{
public:
	myanalogitem(
				UaNode*            pParentNode,
		        UaVariable*        pInstanceDeclarationVariable,
		        NodeManagerConfig* pNodeConfig,
		        UaMutexRefCounted* pSharedMutex = NULL);
	myanalogitem(
				const UaNodeId&    nodeId,
		        const UaString&    name,
		        OpcUa_UInt16       browseNameNameSpaceIndex,
		        const UaVariant&   initialValue,
		        OpcUa_Byte         accessLevel,
		        NodeManagerConfig* pNodeConfig,
		        UaMutexRefCounted* pSharedMutex = NULL,
		        NmMy* pNodeManager = NULL);
	virtual ~myanalogitem();

 //override Controller::call()
	virtual UaStatus call(
	UaMethod*             pMethod,
	const UaVariantArray& inputArguments,
	UaVariantArray&       /*outputArguments*/,
	UaStatusCodeArray&    inputArgumentResults,
	UaDiagnosticInfos&    /*inputArgumentDiag*/);

private:
	UaMethodGeneric* m_pMethodDelete;
};

}

#endif /* MYANALOGITEM_H_ */
Any hint would be highly appreciated!

Cheers and regards,
Florian

fpethig
Hero Member
Hero Member
Posts: 37
Joined: 30 Sep 2013, 08:19

Re: AnalogItemType containing a Method

Post by fpethig »

Hello,
it would be great if you could leave a small note if you are going to reply to this post or not.

Thanks in advance,
Florian

trevor.kavanaugh
Full Member
Full Member
Posts: 7
Joined: 11 Aug 2014, 21:55

Re: AnalogItemType containing a Method

Post by trevor.kavanaugh »

I have not had any luck getting any support from unified automation lately, maybe no one is home anymore... certainly seems like the lights are out, unless you want to talk to sales.

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

Re: AnalogItemType containing a Method

Post by Support Team »

Hello Florian,

our customers get a high priority support with a very quick response time. The forum has a low level of priority so it may take up to a few days to get an answer here.

What you try to do is not allowed. In OPC UA methods are bound to an owning object - similar to methods of a class in object oriented programming. Only objects can have methods. Variables can't have methods.

So you could create an object with a CreateNode() and DeleteNode() method and dynamically add and delete the variables to that object.
There's an example for that in the C++ Demoserver (search for NodeManagerDemo::Demo_DynamicNodes_CreateDynamicNode to get a good starting point).


Best Regards,

Unified Automation Support Team

Post Reply