Closed romatthe closed 5 years ago
Hello @romatthe ,
You can have a look at the example from DiagnosticsNodeManager.AddBehaviourToPredefinedNode() where it uses the OnCall handler.
protected override NodeState AddBehaviourToPredefinedNode(ISystemContext context, NodeState predefinedNode)
{
BaseObjectState passiveNode = predefinedNode as BaseObjectState;
if (passiveNode == null)
{
MethodState passiveMethod = predefinedNode as MethodState;
if (passiveMethod == null)
{
return predefinedNode;
}
if (passiveMethod.NodeId == MethodIds.ConditionType_ConditionRefresh)
{
ConditionRefreshMethodState activeNode = new ConditionRefreshMethodState(passiveMethod.Parent);
activeNode.Create(context, passiveMethod);
// replace the node in the parent.
if (passiveMethod.Parent != null)
{
passiveMethod.Parent.ReplaceChild(context, activeNode);
}
activeNode.OnCall = OnConditionRefresh;
return activeNode;
}
return predefinedNode;
}
Hi all,
We've been playing around with this library to see what it takes to get a basic PoC going. Right now we're trying out the code generation abilities of the SDK, but I've come up with a couple of issues.
Our generated model contains a predefined node
PhysicalGroupSet
, which has a method attached to it calledAddElement
. BothPhysicalGroupSet
and its method appear at server startup.I've been trying to attach a method implementation to
AddElement
. At first, doing so seemed simple enough.Where AddElement simply refers to:
This works! Unfortunately, this involves dealing with a
List<object>
as input args and output, which is a bit cumbersome and generates a lot of type checking noise to a method implementation. However, as part of the code generation process, a classAddElementMethodState
gets generated.A first glance, I thought this allowed us to attach methods with the proper type signature. Indeed, I can now write the following code:
Where
AddPhysicalHierarchyElement
has a more sensible type signature that matches the definition in our model.However, performing the cast to
AddElementMethodState
at runtime throws amInvalidCastException
, which surprised me. Indeed, the runtime type ofstate
isMethodState
and notAddElementMethodState
.This confuses me. What exactly then is the point of the generated
AddElementMethodState
class? Is it possible to wire up a method with a more specific signature?Thanks!
(I apologise if my question is a little unclear, I'm new to both this SDK and OPC UA)