Server Development Tutorial

Step 4 - Dealing with Writes from Clients

in this section you will see where to handle write requests from clients. This is especially useful for when you need to send the values (provided by the client) to a downstream system such as a PLC/Controller, or other sub-system.

This step is a continuation from Step 3 - Reading Values.

  1. All nodes are maintained within the address space by the UA .NET API automatically. Just as in the last example (step 3) we will assume that our "MyNode" is in variables[1] position.

  2. Add the following line of code, which will attach to the OnsimpleWriteValue event handler for this specific node:
    variables[1].OnSimpleWriteValue=new NodeValuesimpleEventHandler(OnWriteMyNode);

  3. The function "OnWriteMyNode" does not yet exist, so scroll to the bottom of the source code file and add the following code:
    private ServiceResult OnWriteMyNode( ISystemContext context, NodeState node, ref object value )
    {
       System.Windows.Forms.MessageBox.Show( "Received '" + value.toString() + "'." )
       return ServiceResult.Good;
    }

Upon writing to this node a modal popup window will display a message and show the value you wrote. While it is not an optimal solution it does demonstrate the technology.

You could define a single write function (event handler) that is used globally by all nodes within your application, or you could create different handlers for different nodes. You have many options available to you.

In the next step we will test our newly developed server.