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;
}
private class SystemFunction
{
public int Address;
public int Function;
}
Assign user data to Method nodes after object creation
foreach (BlockConfiguration block in m_system.GetBlocks())
{
...
CreateObject(
Server.DefaultRequestContext, settings);
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 });
...
Forward method to right method handler
RequestContext context,
MethodHandle methodHandle)
{
if (methodHandle.MethodData is SystemFunction)
{
return DispatchControllerMethod;
}
return null;
}
Implement Method
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)