Step 1: Open the Project and Compile the Server Application
Double-click on the file [ProjectNamespace].csproj (in this case ExampleProjectNs.csproj), compile and start the server.
- Note
- Sometimes the assemblies UnifiedAutomation.UaBase and UnifiedAutomation.UaServer cannot be found (indicated by exclamation marks in the solution explorer, see screenshot). Then you will have to add these assemblies manually.
-
First you have to remove the existing assemblies by choosing “Remove” from the context menu of the assembly. Then right-click on “References” in the solution explorer and choose “Add Reference”. Click on “Browse” to browse for the assemblies. The SDK installation directory contains a folder named “assemblies”, which itself contains several folders named “NET_[version]”. Add the assemblies located in the folder corresponding to the .NET framework you are using.
-
When connecting to the server with UaExpert, you can find the nodes created in UaModeler in the server’s address space (see screenshot).
Nodes in UaExpert
Step 2: Creating an Object Instance
As a next step, we are adding an instance of the newly created Object Type to the StartUp method in [ModelNamespace]NodeManager.cs (in our case ExampleModelNsNodeManager.cs).
public override void Startup()
{
try
{
Console.WriteLine("Starting ExampleModelNodeManager.");
DefaultNamespaceIndex = AddNamespaceUri("http://yourorganisation.org/ExampleModel/");
Console.WriteLine("Loading the ExampleModelNs Model.");
ImportUaNodeset(Assembly.GetEntryAssembly(), "examplemodel.xml");
CreateObjectSettings settings = new CreateObjectSettings()
{
ParentNodeId = UnifiedAutomation.UaBase.ObjectIds.ObjectsFolder,
ReferenceTypeId = UnifiedAutomation.UaBase.ReferenceTypeIds.Organizes,
RequestedNodeId = new NodeId("NewObject", DefaultNamespaceIndex),
BrowseName = new QualifiedName("NewObject", DefaultNamespaceIndex),
TypeDefinitionId = ObjectTypeIds.MyObjectType.ToNodeId(Server.NamespaceUris)
};
ObjectNode node = CreateObject(Server.DefaultRequestContext, settings);
...
Compile and run the server. When connecting with UaExpert, a new instance of the Object Type shows up in the Objects folder.
Instance in UaExpert
Step 3: Link Model to Node
Extend the StartUp method:
...
ObjectNode node = CreateObject(Server.DefaultRequestContext, settings);
MyObjectModel model = new MyObjectModel();
LinkModelToNode(node.NodeId, model, null, null, 500);
model.var1 = 123;
Compile, run and connect with UaExpert. You can see that the value of var1 is now 123.
Value of var1
Step 4: Implementing the Method
The last step in this HowTo is to implement the method fktSum in the file [ObjectType]Methods.cs (in our case MyObjectTypeMethods.cs).
public StatusCode fktSum(
RequestContext context,
MyObjectModel model,
uint in1,
uint in2,
out uint out1
)
{
out1 = in1 + in2;
return StatusCodes.Good;
}
Compile, run and connect with UaExpert. You should now be able to call the method (see screenshot).
Call Method