Creating an XMPP control server

To make our parameters available, we create a ControlServer object in our actuator project. We need a variable to reference our server:

private ControlServer controlServer = null; 

In our AttachFeatures method, we create our instance of the control server. We can either choose to provide a set of control parameters in the constructor of the control server, or override the OnGetControlParameters event and provide a dynamic set each time a set is requested. The first method is simplest, if we're building a simple actuator, as we do in our example. If we want to provide different control parameter sets for different nodes in the device, we must choose the second option.

The control server object does not have an event that is raised when control parameters are set. Instead, such callback methods are provided individually, for each control parameter. Apart from providing a name for each parameter, we also have to provide (in order) a page (think "tabbed dialog"), a label for the parameter, and a description (a tool-tip), as well as a get and a set callback method. These two methods are used whenever the control server needs to know the current value of the parameter, and when it wants the value to be updated. For our actuator, we define the control server as follows:

this.controlServer = new ControlServer(this.xmppClient, 
new BooleanControlParameter("Output", 
"Actuator", "Output:","Digital output.", 
(Node) => this.output, 
async (Node, Value) => 
{ 
try 
{ 
await this.SetOutput(Value, "XMPP"); 
} 
catch (Exception ex) 
{ 
Log.Critical(ex); 
} 
}));
If you're implementing asynchronous callback methods, make sure you trap all exceptions. Exceptions in asynchronous methods with a void return types that, if not caught, will cause the application to shut down unexpectedly.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.82.23