UA Bundle SDK .NET  2.2.1.258
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Groups Pages
Lesson 4: Adding support for Methods

Define data class for method user data

Address is used to address the controller

Identifier for the function to execute

private class SystemAddress
{
public int Address;
public int Offset;
}
// New Code Begin
private class SystemFunction
{
public int Address;
public int Function;
}
// New Code End

Assign user data to Method nodes after object creation

// Create controllers from configuration
foreach (BlockConfiguration block in m_system.GetBlocks())
{
...
CreateObject(Server.DefaultRequestContext, settings);
// New Code Begin
// set addressing information for method nodes that allows them to be called.
SetComponentUserData(
new NodeId(block.Name, InstanceNamespaceIndex),
new QualifiedName(yourorganisation.BA.BrowseNames.Start, TypeNamespaceIndex),
new SystemFunction() { Address = block.Address, Function = 1 });
SetComponentUserData(
new NodeId(block.Name, InstanceNamespaceIndex),
new QualifiedName(yourorganisation.BA.BrowseNames.Stop, TypeNamespaceIndex),
new SystemFunction() { Address = block.Address, Function = 2 });
SetComponentUserData(
new NodeId(block.Name, InstanceNamespaceIndex),
new QualifiedName(yourorganisation.BA.BrowseNames.StartWithSetPoint, TypeNamespaceIndex),
new SystemFunction() { Address = block.Address, Function = 3 });
// New Code End
...

Forward method to right method handler

protected override CallMethodEventHandler GetMethodDispatcher(
RequestContext context,
MethodHandle methodHandle)
{
if (methodHandle.MethodData is SystemFunction)
{
return DispatchControllerMethod;
}
return null;
}

Implement Method

private StatusCode DispatchControllerMethod(
RequestContext context,
MethodHandle methodHandle,
IList<Variant> inputArguments,
List<StatusCode> inputArgumentResults,
List<Variant> outputArguments)
{
SystemFunction data = methodHandle.MethodData as SystemFunction;
if (data != null)
{
switch (data.Function)
{
case 1:
return m_system.Start(data.Address);
case 2:
return m_system.Stop(data.Address);
case 3:
return m_system.StartWithSetPoint(
data.Address, inputArguments[0].ToDouble(), inputArguments[1].ToDouble());
}
}
return StatusCodes.BadNotImplemented;
}

Calling Method from UaExpert

Figure 4.1:

Calling Stop changes State to 0 (OFF)

Calling Start changes State to 1 (ON)