Step 1: Open the Project and Compile the Server Application
Double-click on the file [ProjectNamespace].csproj (in this case ExampleProjectNs.csproj), compile and start the server.
When connecting to the server with UaExpert, you can find the nodes created in UaModeler in the server’s address space (see screenshot).
Step 2: Creating an Object Instance
As a next step, we are adding an instance of the newly created Object Type to the StartUp method in [ModelNamespace]NodeManager.cs (in our case ExampleModelNsNodeManager.cs).
public override void Startup()
{
try
{
Console.WriteLine("Starting ExampleModelNodeManager.");
DefaultNamespaceIndex = AddNamespaceUri("http://yourorganisation.org/ExampleModel/");
Console.WriteLine("Loading the ExampleModelNs Model.");
ImportUaNodeset(Assembly.GetEntryAssembly(), "examplemodel.xml");
CreateObjectSettings settings = new CreateObjectSettings()
{
ParentNodeId = UnifiedAutomation.UaBase.ObjectIds.ObjectsFolder,
ReferenceTypeId = UnifiedAutomation.UaBase.ReferenceTypeIds.Organizes,
RequestedNodeId = new NodeId("NewObject", DefaultNamespaceIndex),
BrowseName = new QualifiedName("NewObject", DefaultNamespaceIndex),
TypeDefinitionId = ObjectTypeIds.MyObjectType.ToNodeId(Server.NamespaceUris)
};
ObjectNode node = CreateObject(Server.DefaultRequestContext, settings);
...
Compile and run the server. When connecting with UaExpert, a new instance of the Object Type shows up in the Objects folder.
Step 3: Link Model to Node
Extend the StartUp method:
...
ObjectNode node = CreateObject(Server.DefaultRequestContext, settings);
MyObjectModel model = new MyObjectModel();
LinkModelToNode(node.NodeId, model, null, null, 500);
model.var1 = 123;
Compile, run and connect with UaExpert. You can see that the value of var1 is now 123.
Step 4: Implementing the Method
The last step in this HowTo is to implement the method fktSum in the file [ObjectType]Methods.cs (in our case MyObjectTypeMethods.cs).
public StatusCode fktSum(
RequestContext context,
MyObjectModel model,
uint in1,
uint in2,
out uint out1
)
{
out1 = in1 + in2;
return StatusCodes.Good;
}
Compile, run and connect with UaExpert. You should now be able to call the method (see screenshot).