UaModeler  1.6.3.454
HowTo: Finish and Compile the Example Server Application

Step 1: Open the Project and Compile the Server Application

Double-click on the file [ProjectNamespace].csproj (in this case ExampleProjectNs.csproj), save the solution, compile and start the server.

Note
Sometimes the assemblies UnifiedAutomation.UaBase and UnifiedAutomation.UaServer cannot be found (indicated by exclamation marks in the solution explorer, see screenshot). The main reason for that is a missing or wrong configuration of the location of the sdk. Then you will have to add these assemblies manually.
First you have to remove the existing assemblies by choosing “Remove” from the context menu of the assembly. For .NET SDK 2.x you have to right-click on “References” in the solution explorer and choose “Add Reference”. Click on “Browse” to browse for the assemblies. The SDK installation directory contains a folder named “assemblies”, which itself contains several folders named “NET_[version]”. Add the assemblies located in the folder corresponding to the .NET framework you are using.
For .NET SDK 3.x you need to add the NuGet packages again. Make sure that the path specified in the generated NuGet.Config is correct.
net_assemblies_not_found.png

When connecting to the server with UaExpert, you can find the nodes created in UaModeler in the server’s address space (see screenshot).

compile_net_server_1.png
Nodes in UaExpert

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");
// New code begins
// Create the instance
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);
... // New code ends

Compile and run the server. When connecting with UaExpert, a new instance of the Object Type shows up in the Objects folder.

compile_net_server_2.png
Instance in UaExpert

Step 3: Link Model to Node

Extend the StartUp method:

...
ObjectNode node = CreateObject(Server.DefaultRequestContext, settings);
// New code begins
// Link model to node
MyObjectModel model = new MyObjectModel();
LinkModelToNode(node.NodeId, model, null, null, 500);
// Set variable
model.var1 = 123;
// New code ends

Compile, run and connect with UaExpert. You can see that the value of var1 is now 123.

compile_net_server_3.png
Value of var1

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; // Change this line
return StatusCodes.Good; // Change this line
}

Compile, run and connect with UaExpert. You should now be able to call the method (see screenshot).

compile_net_server_4.png
Call Method