.NET Based OPC UA Client/Server SDK
Using UaModeler for Model Design and Code Generation

This section contains information on how to use UaModeler for generating the information model used in the Getting Started lessons. Please refer to the documentation of UaModeler for more detailed information on using this tool.

Generating a New Project in UaModeler

First, we have to create the model shown in the Introduction in UaModeler.

Select File → New Project from the menu bar to start the New Project Wizard.

At “General Project Settings” enter the Project Name as shown in the screenshot below. At “Location” choose a directory for storing the project files. Confirm with “Next”.

Figure 2.4: General Project Settings Dialog

The “Generate Code” dialog will appear. At “Template Set”, select the .NET Server Templates. In addition, you have to specify an output directory for the generated code.

Figure 2.5: Generate Code Dialog

At the “Choose Base Models“ dialog, continue with default settings.

The new “New Model” dialog window will appear. Fill out the input fields as shown in the screenshot and finish the wizard.

Figure 2.6: New Model Dialog

Adding ControllerType

Browse to Types → ObjectTypes → BaseObjectType and add a subtype to BaseObjectType by pressing the button “AddSubtype” or by choosing “Add New Type” from the context menu. Enter the name “ControllerType” at “Type” and confirm with OK. The newly created Type should now show up in the Information Model window beneath BaseObjectType.

Figure 2.7: Adding ControllerType

Expand the input field at “Children” and add the Variables and Methods shown in Figure 2.2.

Figure 2.8: Adding Variables and Methods

Adding Controller Subtypes

As a next step, add AirConditionerControllerType and FurnaceControllerType as Subtypes of ControllerType as shown in Figure 2.3, including Variables and Methods. To add input arguments, expand the method in the input field “Children” as shown in the following figure.

Figure 2.9: Adding Subtypes of ControllerType

Finally, add ControllerEventType as Subtype of BaseEventType, containing the children Temperature and State.

The complete infomation model is shown in Figure 2.10.

Figure 2.10: Types and Components

Export Model as XML File and Generate Code

To export the previously created model, select “Export XML” from the model’s context menu in the Project Window as shown in the following screenshot.

Figure 2.11: Export model as XML

Finally, we generate source files by pressing the “Compile” button (the blue gear-wheel) in the menu bar. The model XML file (buildingautomation.xml) can be found in the project folder, the generated source code file (BAIdentifiers.cs) is located in the output directory specified above.

Integrating the Model into an Empty Server

We are using the basic OPC UA server from Lesson 1 as a starting point. The prepared sample code can be found in the Lesson 2 project of the UA Server Getting Started solution.

At first, we have to add the file containing the model (buildingautomation.xml) to the Visual Studio project (Add → Existing Item). Choose “Properties” from the context menu and set “Build Action” to “Embedded Resource” as shown in the following screenshot.

Figure 2.12: Add buildingautomation.xml as Embedded Resource

Then, we have to load the model in Lesson02Nodemanager.cs

using System.Reflection;

public override void Startup()

Console.WriteLine("Loading the Controller Model.");
ImportUaNodeset(Assembly.GetEntryAssembly(), "buildingautomation.xml");

Now we are ready to compile and start-up the server.

When connecting to the server with an OPC UA client, e.g. UaExpert, we will notice that the type nodes are already visible in the server’s address space (see Figure 2.13).

Figure 2.13: Type nodes in the server’s address space

Next step: Preparing Instance Creation