UaModeler  1.3.4.293
 All Pages
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), 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).

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.

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.

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).

Call Method