UaModeler  1.4.2.342
 All Pages
HowTo Create a New Project With a Structured Data 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.1 and higher.

The client connects to a server that provides a structured data 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. To ensure this, we will use the same model we create for the client to generate a Visual Studio server project.

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

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_net_2.png

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”.

wizard_net_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 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. This field must match the pattern [A-Za-z][A-Za-z0-9_]*, otherwise the generated code will not compile.
Namespace
The name of the namespace you will generate. This field must match the pattern [A-Za-z][A-Za-z0-9_]*, otherwise the generated code will not compile.
wizard_net_4.png

Step 5: Add a Structured Data Type

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”.

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

new_complextype_net_2.png

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

new_complextype_net_3.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”.

new_objecttype_net.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_objecttype_net_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 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”.

new_objecttype_net_3.png

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.

new_objecttype_net_4.png

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

new_objecttype_net_5.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.

add_instance_opendocument.png
Add Instance

Expand the input fields at “Instance”, select “MyObjectType” as Type Definition, enter “MyObject” as name, and confirm with “OK”.

new_instance_net.png
Set Instance Information

Step 8: Adding a New Event Type

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

new_eventtype_net.png

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.

new_eventtype_net_2.png

In this example the Event Type will have two 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 screenshot below and confirm with “OK”.

new_eventtype_net_3.png

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

new_eventtype_net_4.png

Step 9: 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.
select_model_net.png

Step 10: 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 Step 2: Selecting a Template).

generated_code_net.png

Congratulations—your design was turned into source code. Now you are able to integrate your created code into your client application.

Just one last step if you’d like to continue with the next HowTo: Generate a Default Server Application using the same model we created for the client. We will connect to this server in the section HowTo Use the Generated Files in a Visual Studio Project.

Step 11: Generate a Default Server Application

Select ProjectProject Settings from the menu bar and select the .NET Server 2.1 templates. Continue with “Next”.

project_settings_net.png
Choose Template Set

Fill out the next window as shown in the screenshot below. For more information on the input fields see the .NET Server tutorial.

project_settings_net_2.png
Set Project Variables

Leave the next window unchanged and press “Finish”.

project_settings_net_3.png
Set Model Variables

Press the “Compile” button and choose “Yes” when asked if already existing files should be overwritten. The generated files including a Visual Studio Project for a default server application can be found in the output folder.

generated_code_net_2.png
Generated Files

Finally, right-click on the model in the Project Window and select Export XML. Copy the xml file to the output folder.

You are now ready to continue with the section HowTo Use the Generated Files in a Visual Studio Project.