UaModeler  1.4.2.342
 All Pages
HowTo (Windows): Create a New Project With a Method

This example decribes how to create a new project and generate source files which can be used with the Unified Automation C++ SDK version 1.3.1 and newer in eight simple steps.

Note
For this example, the Template Set C++ 1.4.0 is used, but the HowTo works with the Template Set 1.3.1 as well. Be sure to choose the Template Set matching your SDK.

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 .cpp and *.h)
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 choose 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.

In this example, we pick [C++ SDK Installation Directory]/examples/server_hello_world as output directory, because we will integrate the generated code into the Hello World Server example delivered with the Unified Automation C++ Server SDK in HowTo (Windows): Compile the Generated Method Project Files. When choosing a different directory, be sure to pick one for which you have read and write access.

wizard_2.png

Step 3: 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 4: 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.
Namespace Prefix
This string will be used as a file name prefix and as C++ namespace.
Namespace Name
This string will be used as suffix for the NodeManager name.
Dll Export Prefix:
This is an export prefix if you want to generate code which also will be build in dll mode.
wizard_4.png

Step 5: 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 6: Adding Method Arguments

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

  • right click on the created object (here: MyObjectType) in the Information Model tree and select “Modify Type”.
  • or use the toolbar buttons to switch between the Graphics View and the Types 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 7: 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 8: 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 your generated *.h and *.cpp files located in the output folder (as set in Step 2: Selecting a Template).

Note
The screenshot shows the files which are generated when the Template Set for the C++ SDK 1.4 is chosen. When using a different template set, the number and names of the files may differ.
new_type_10.png

Congratulations—your design was turned into source code. Now you are able to integrate your created code into your server application. Just follow the steps in the section HowTo (Windows): Compile the Generated Method Project Files.

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.