.NET Based OPC UA Client/Server SDK
2.5.8.410
|
This section contains information on how to use UaModeler for generating the information model used in the Getting Started lessons. Please refer to the documentation of UaModeler for more detailed information on using this tool.
First, we have to create the model shown in the Introduction in UaModeler.
Select File → New Project from the menu bar to start the New Project Wizard.
At “General Project Settings” enter the Project Name as shown in the screenshot below. At “Location” choose a directory for storing the project files. Confirm with “Next”.
The “Generate Code” dialog will appear. At “Template Set”, select the .NET Server Templates. In addition, you have to specify an output directory for the generated code.
At the “Choose Base Models“ dialog, continue with default settings.
The new “New Model” dialog window will appear. Fill out the input fields as shown in the screenshot and finish the wizard.
Browse to Types → ObjectTypes → BaseObjectType and add a subtype to BaseObjectType by pressing the button “AddSubtype” or by choosing “Add New Type” from the context menu. Enter the name “ControllerType” at “Type” and confirm with OK. The newly created Type should now show up in the Information Model window beneath BaseObjectType.
Expand the input field at “Children” and add the Variables and Methods shown in Figure 2.2.
As a next step, add AirConditionerControllerType and FurnaceControllerType as Subtypes of ControllerType as shown in Figure 2.3, including Variables and Methods. To add input arguments, expand the method in the input field “Children” as shown in the following figure.
Finally, add ControllerEventType as Subtype of BaseEventType, containing the children Temperature and State.
The complete infomation model is shown in Figure 2.10.
To export the previously created model, select “Export XML” from the model’s context menu in the Project Window as shown in the following screenshot.
Finally, we generate source files by pressing the “Compile” button (the blue gear-wheel) in the menu bar. The model XML file (buildingautomation.xml) can be found in the project folder, the generated source code file (BAIdentifiers.cs) is located in the output directory specified above.
We are using the basic OPC UA server from Lesson 1 as a starting point. The prepared sample code can be found in the Lesson 2 project of the UA Server Getting Started solution.
At first, we have to add the file containing the model (buildingautomation.xml) to the Visual Studio project (Add → Existing Item). Choose “Properties” from the context menu and set “Build Action” to “Embedded Resource” as shown in the following screenshot.
Then, we have to load the model in Lesson2NodeManager.cs
Now we are ready to compile and start-up the server.
When connecting to the server with an OPC UA client, e.g. UaExpert, we will notice that the type nodes are already visible in the server’s address space (see Figure 2.13).
Next step: Preparing Instance Creation