UaModeler  1.6.5.472
HowTo Create a New Project With a Method

This example decribes how to create a new project and generate C source files which can be used with the Unified Automation HP SDK version 1.2 and higher.

This will now be explained in simple steps.

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 and header files *.c 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 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.

As output directory (i.e. the folder to store the generated files), choose a folder to your liking for which you have read and write access.

wizard_hp_2.png

Step 3: Setting Project Settings

In this step, we enter the setting for the new application which will be created by UaModeler. Enter “Test” as Application Name.

Application Name
This is the name of your new application.
Enable User Authentication
This option allows the creation of files needed for supporting access to the server with username and password.
wizard_hp_3.png

Step 4: Selecting the Base Models

After confirming 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_hp_4.png

Step 5: Completing the Wizard With “New Model”

The last step of the wizard guides you to the “New Model” page. Here you specify the different information of 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.
Library
The library name that is passed to the xml2c executable of the HP sdk.
Prefix
The prefix that is used for the generated file names and for the generated type names.
AlternateStoreIndex
The alternate index of the store.
wizard_hp_5.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 → BaseObjectTypes. The new object will be derived from BaseObjectTypes. Right click on BaseObjectTypes and select “Add New Type”.

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.

In this example, we will add a method (Multiply) with two input and one output argument, each having the DataType Double.

By pressing the triangle next to “Children”, an input field shows up for adding node declarations. Clicking on “Select NodeClass” adds a new node. Select “Method” to add a new MethodNode. Enter the name “Multiply”.

For adding input and output arguments to a method, click on the green triangle at the right end of the row. Enter the two input arguments and one output argument. Confirm your changes by clicking on the “OK” button.

wizard_hp_6.png

Step 7: Creating an Instance of MyObjectType

Right click on the “Objects” folder in the Information Model Window and select “Add Instance” from the context menu.

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 *.c and *.h files located in the output folder.

The file located in the directory called “Generated” shall not be modfied by the user.

Step 9: Call CMake

Create a solution with the CMake gui. The source is located in the "src" folder in the target directory. Add CMake Variable SDKDIR with the installation path of the hp sdk. The selected output path shall be used as CMake_INSTALL_PREFIX.

Please see the documentation of HP SDK for more details about the usage of CMake.

wizard_hp_8.png

Step 10: Implement Method

Add the method implementation in file provider_prefix_myobjecttype_methods.c.

ua_statuscode provider_prefix_myobjecttype_multiply(
/* in */ struct uaprovider_call_ctx *ctx,
/* in */ const struct ua_nodeid *object_id,
/* in */ double factor1,
/* in */ double factor2,
/* out */ double *product)
{
UA_UNUSED(ctx);
UA_UNUSED(object_id);
*product = factor1 * factor2;
return 0;
}

Step 11: Start server and test with UaExpert

Connect to the server running on port opc.tcp://localhost:4840. Call method at Object → MyObject → Multiply.

wizard_hp_7.png