UaModeler  1.2.0.214
 All Pages
HowTo Create a new project with a complex type

This example decribes how to create a new project and generate C# source files which can be used with the Unified Automation .NET Client SDK version 2.0.

The client connects to a server that provides a complex type “Vector”. In this tutorial the parts of the information model used by a client (HowTo Use the generated files in a Visual Studio Project) will be defined. We expect that the server that the client will connect to, provides exactly this information model. Especially we expect that the server uses the same NamespaceUri, the same browse names and the same node ids.

This will now be explained in 9 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 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.

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.

Step 3: 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”.

Step 4: 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.
Organization
The name of the organization. This will be the top level of the namespace
Namespace
The name of the namespace you will generate.

Step 5: Add a ComplexType

In the Information Model Window on the left pane of the UaModeler you browse down to Types → DataTypes → BaseDataType → Structure. The new data type will be derived from Structure. Right click on Structure and select “Add New Structured DataType”.

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 structure (here “Vector”). All other information can be added later. Confirm by clicking on the “OK” button.

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

In this example, we will add three fields, called “X”, “Y” and “Z”, all having the data type “Double”. By pressing the triangle next to “Children”, an input field shows up for adding fields. Click on “Add Name” to add a new field.

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

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. Confirm by clicking on the “OK” button.

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 two components to the Object Type, a variable of data type Vector (DemoVector) and one method (VectorAdd) with two input and one output argument, each having the DataType Vector.

By pressing the triangle next to “Children”, an input field shows up for adding node declarations. Clicking on “Select NodeClass” adds a new node. For chosing the DataType “Vector” (created in the previous step), select <Add another node ...> from the drop-down menu to open a browse window. The DataType “Vector” can be found in the tree below of “Structure”. For adding input and output arguments to a method, click on the green triangle at the right end of the row. Confirm your changes by clicking on the “OK” button.

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

Step 7: Adding a new Event Type

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

The type definition document will show up in the middle of the UaModeler window. Fill in a name for the object (here “MyEventType”) and confirm by clicking on the “OK” button.

In this example the Event Type will have 2 components, a variable with data type Int32 and a variable with data type Vector. Select the newly created Event Type in the Information model window, add the nodes to the input field at “Children” like shown in the screen shot below and confirm with “OK”.

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

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.

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 your generated *.cs files located in the output folder (as set in the “New Project” dialog).

Congratulations—your design was turned into source code. Now you are able to integrate your created code into your client application. Just follow the steps in the section HowTo Use the generated files in a Visual Studio Project.