UaModeler  1.6.5.472
HowTo: Create a New UaModeler Project With a Method

This example decribes how to create a new project, generate source files which can be used with the Unified Automation .NET SDK version 2.5 and higher, and a Visual Studio project for building an example application.

Note
To generate a working Visual Studio project and compile the example application, the .NET based OPC UA SDK has to be installed.

Step 1: Creating a New Project

To create a new project, choose “File → New Project” from the menu bar. The “New Project” wizard will appear. Fill in a project name and a file name to your liking. For additional information on an input field, right click on its label and choose “What’s This?” from the context menu.

Project Name
This is the name of the project you will generate the source files for.
Location
This is the location where the project and project related files will be stored (IMPORTANT: These files are NOT the generated source files .cs)
File Name
This is the name of the project file.

By default, the project will be generated in the user’s home directory. Feel free to chose a different directory for which you have read and write access.

wizard_1.png

Step 2: Selecting a Template

After confirming the General Project Settings by pressing the button “Next”, the “Generate Code” dialog appears. Here you specify the Code Template Set and the Output Directory for the generated code. At “Template Set”, choose the kind of code to be generated, i.e. the SDK you intend to use the code with.

wizard_net_server_2.png

Step 3: Enter Project Settings

Now you’ll be prompted to decide if a Visual Studio Project for building an example application should be generated. This will be done when checking the box in front of GenerateDefaultApplication.

wizard_net_server_1.png
Note
The following field only need to be filled out for this example application. You can leave all fields empty otherwise.
Generate a default application
Generate a Visual Studio project with a server application.
Generate packages.config
Generate packages.config referenzing the UnifiedAutomation NuGet packages for the Visual Studio project. If not selected, the generated Visual Studio project file will contain PackageReferences to the UnifiedAutomation NuGet packages. Is only evaluated if a server application is created and a .NET Framework is selected.
Project Organization
First level of the namespace. It has to start with an upper or lowercase letter. Allowed characters are upper and lower case letters, numerals and the underscore character. This is only evaluated if a server application is created.
Project Namespace
Second level of the namespace; specifies the namespace of the current project It has to start with an upper or lowercase letter. Allowed characters are upper and lower case letters, numerals and the underscore character. This is only evaluated if a server application is created.
.Net Framework
The .NET framework the application should be built against. If “standard” is selected, a VS project for .NET Core 2.1 will be generated. This is only evaluated if a server application is created.

Step 4: Selecting the Base Models

After confirming the “Generate Code” dialog with Next the “Choose Base Model” dialog appears. Here you specify the different Base Models. The first NodeSet is the mandatory root namespace of the server. All other suggested models are optional. You can add your own model by clicking the button “Find another model”.

wizard_3.png

Step 5: Completing the Wizard With “New Model”

The last step of the wizard guides you to the “New Model” page. Here you have to specify some information for your new model. Please fill out all fields as shown below.

Model Name
This is the name of your new model.
File Name
This is the name of the ua file of your new model.
Location:
This is the location where the model and its ua files will be stored.
Namespace URI:
This is used to differ the node’s namespaces.
Organization
First level of the namespace. It has to start with an upper or lowercase letter. Allowed characters are upper and lower case letters, numerals and the underscore character.
Namespace
Second level of the namespace; specifies the namespace of the current model. It has to start with an upper or lowercase letter. Allowed characters are upper and lower case letters, numerals and the underscore character.
wizard_net_server_4.png

Step 6: Adding a New Object Type

In the Information Model Window on the left pane of the UaModeler browse down to Types → ObjectTypes → BaseObjectType. The new object will be derived from BaseObjectType. Right click on BaseObjectTypes and select “Add New Type”.

new_type.png

The type definition document will show up in the middle of the UaModeler window. Expand the input fields at “Type” and fill in a name for the new object (here “MyObjectType”). All other information can be added later. Confirm by clicking on the “OK” button.

new_type_2.png

You can see the newly created node (MyObjectType) in the Information Model Window below “BaseObjectType”. Select it to display its content in the main window.

In this example, we will add three components to the Object Type, two variables of data type Int32 (var1 and var2) and one method (fktSum).

Click on “Select NodeClass” to add a new node and fill in the required information as shown in the screenshot below. To add a TypeDefinition or a DataType which is not already listed in the respective drop-down menu, choose “<Add another node …>” to open a browse window. Confirm your changes by clicking on the “OK” button.

new_type_3.png

With the toolbar buttons you can switch between the model view and the type declaration view.

new_type_4.png

Step 7: Adding Method Arguments

After having created a method, you can add input and output arguments. To switch back to the type definition view

By pressing the triangle next to “Children”, an input field shows up for adding node declarations. You can add input and output arguments, give them a name, and select the data type of each argument. Add two input arguments and one output argument as shown in the screenshot below and confirm with “OK”.

new_type_6.png

Step 8: Select the Model for Generating Code

When the design is completed you can generate the code for your model. It is possible to design multiple models in a project (each stored in a different file), but code generation is only performed for those that are marked as “Generate Namespace”, indicated by a blue gear-wheel symbol. The new model is pre-selected. You can select or deselect “Generate Namespace” by right clicking on the model node.

Note
It is not possible to generate code for the base UA Model (stored in Opc.Ua.NodeSet.ua) since it is already included in the server SDKs.
new_type_8.png

Step 9: Generating Code

For generating the source files, press the “Compile” button (the blue gear-wheel) in the menu bar. When the compilation is finished, you will find the generated files in the output folder (see screenshot).

Note
If you can’t find the generated files in the output directory you specified in Step 2: Selecting a Template, check if UaModeler has the appropriate access permissions.
new_type_net_10.png
Note
If you change the model and generate code again, you have to repeat this step to update the information model of the resulting NodeManager.

Congratulations—your design was turned into source code. Now you just have to add some code to the generated source files before you can build your server application. This is described in HowTo: Finish and Compile the Example Server Application.