Creating the digital output object instance class

We now proceed with the actuator. We prepare the ActuatorLwm2m project in the same way as the SensorLwm2m project. The main difference is the types of objects and object instances we choose to add to the Lwm2mClient object.

Just as there's an IPSO Digital Input object, there's an IPSO Digital Output smart object. It is quite similar with one main difference: the main parameter is writable, and we need to connect the value of that parameter to our output. Following the steps outlined previously, for the creation of the DigitalInput and DigitalInputInstance classes, we create similar DigitalOutput and DigitalOutputInstance classes. When it is time to create the main resource, the digital output state, we make sure to trap the OnRemoteUpdate event on the resource. We make sure to forward this event, as follows:

this.state = new Lwm2mResourceBoolean("Digital Output State", 
  ObjectInstanceId, InstanceId, 5550, true, false, 
  CurrentState); 
 
this.state.OnRemoteUpdate += (sender, e) => 
{ 
  this.state.TriggerAll(); 
  this.TriggerAll(); 
 
  try 
  { 
    this.OnRemoteUpdate?.Invoke(this, e); 
  } 
  catch (Exception ex) 
  { 
    Log.Critical(ex); 
  } 
}; 

Where the OnRemoteUpdate event is defined as follows:

public event CoapRequestEventHandler OnRemoteUpdate = null; 
..................Content has been hidden....................

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