UaModeler  1.6.5.472
HowTo Create a New Project to create a Client Application

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 3.0 and higher.

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

Step 3: Project Settings

Generate a Visual Studio Project
If this check box is selected, a whole Visual Studio solution is generated, including project for the model related classes and a project for the client application. If this box is not selected, a Visual Studio project for the model related classes is generated.
Application Organization
First level of the .NET Namespace of the code files for the client application. It has to start with an upper or lowercase letter. Allowed characters are upper and lower case letters, numerals and the underscore character. Otherwise the generated code will not compile.
This information is only used if “Generate a Visual Studio project” is selected.
Application Namespace
Second level of the .NET Namespace of the code files for the client application. It has to start with an upper or lowercase letter. Allowed characters are upper and lower case letters, numerals and the underscore character. Otherwise the generated code will not compile.
This information is only used if “Generate a Visual Studio project” is selected.
NetFramework
The .NET framework the application should be built against. If “standard” is selected, a VS project for .NET Core 2.0 will be generated.
wizard_net_client_appl_3.png

Step 4: Selecting model

To generate code for a client application the information model must match the regarding information model of the server.

Step 4a: Model available

If the model of the server addressspace is available, e.g. because the server vendor is distributing it, then you should add this model in the “Choose Base Models” page of the wizard and browse to the model file to import. In most times a server vendor will provide the model in a NodeSet2 XML format that is defined by the OPC Foundation.

If the model to import has dependencies to other models, these dependent models need to be imported as well.

You need to specify suitable values for Organization and Namespace for the selected model.

Organization
Specifies the top level of the .NET Namespace of the code files for the current model. Namespaces must match the pattern [A-Za-z][A-Za-z0-9_]*, otherwise the generated code will not compile.
Namespace
The namespace of the model. Specifies the second level of the .NET Namespace of the code files for the current model. Namespaces must match the pattern [A-Za-z][A-Za-z0-9_]*, otherwise the generated code will not compile.
wizard_net_client_appl_4.png

At the “New Model” page you can click at “No new model” and “Finish” wizard.

Step 4b: Model not available

If the model is not available, then you need to create the model yourself.

Enter suitable values in the “New Model” page and “Finish” the wizard.

Please see Step 4: Completing the Wizard With “New Model”.

For structured DataTypes you need to make sure that the structure fields are correct and the DataTypeId and the Encoding NodeIds are matching the IDs on server side.

You can do the modelling as described in Step 5: Add a Structured Data Type.

Step 5: 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. You need to select the imported model by right clicking on the model node and clicking at “Generate Namespace”.

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

Step 6: Using generated code

There is a generated Visual Studio solution that can be opened with Visual Studio 2017 or later. You can modify the file Program.cs analog to Step 6: Read a Variable Having a Structured Data Type.