Link Search Menu Expand Document

Self-Executing Device

Jan 1 2022 at 12:00 AM

  1. Typical use case
  2. Driver description
  3. Driver State Transitions
  4. Properties
  5. Call-back functions
    1. OnInitializeAsync
    2. OnStartAsync
    3. OnProcessDeviceCommandAsync
      1. Parameters
    4. OnGetPropertyMapsAsync
      1. Parameters
    5. OnNewOptionsAsync
      1. Parameters

Typical use case

  • You have one or more External Telemetry Sources that will push data to your device either directly, or through a subscription service.
  • You need configured property mapping
  • Each configured device communicates with exactly one External Telemetry Source.
  • The meta and telemetry sent from each configured device has the same Device Name, Device Type, Group Name and Gateway Id.

Driver description

Self-executing devices are automatic devices that are executed once. The responsibility of when to send the telemetry data is given to the device itself. Self-executing devices do handle the sending of Device Meta to the collector automatically without requiring the device to do it.

Driver State Transitions

Device Workflow is not used to coordinate the processes and so this must be controlled by the device.

Properties

Property NameData TypeDescription
CancellationTokenCancellationTokenHolds the cancellation token that will signal when the device is being shut down.
CanProcessDeviceCommandsboolSet to true if the device can process device commands.
DeviceHealthIComponentHealthStatusThe device health instance associated with this device. Use this to set the RAG status to show the health of the device.
DeviceNamestringHolds the configured name of the device.
DeviceTypestringHolds the configured type of the device.
OptionsTOptionsThe current options for this device.
OptionsVersionintThe version number of the options. This starts from 1 when the device is first created and increments each time the options change.

Call-back functions

OnInitializeAsync

  • Executed when the Device needs to be initialized.
  • If the device needs to report its Make and Model information with the Device Meta, it should obtain and set this information in this call-back.

OnStartAsync

  • Executed when the Device is started.
  • This task can be long running. Use the CancellationToken property to detect when the service shuts down.

OnProcessDeviceCommandAsync

  • Executed when a Device Command needs to be processed.
  • The device command, the current property list and the configured property maps are passed to the function as parameters. The function can set the current values for the property objects in the property list if it needs to.

Parameters

  • An IDeviceCommand instance containing the device command to process.
  • An ICurrentProperties instance containing a dictionary holding the current device properties and a dictionary holding the property mappings.

The function must return true if the device command was successfully processed.

OnGetPropertyMapsAsync

  • Executed one or more times when the workflow is loading the options for the device and the configured Default Properties device.
  • This function is executed at the start and whenever the options change.
  • The function is expected to return a dictionary containing the list of property mappings associated with the device passed as a parameter.
  • The device type is passed as an enumerated parameter. Current supported device types are Default Properties and Current Device.

Parameters

  • A MapDeviceType enumeration that specifies the type of the device. Currently this can be either DefaultProperties or CurrentDevice.
  • An IRaptorDevice instance holding the current device.
  • An IRaptorDeviceOptions instance holding the current device options.

The function must return a dictionary containing the property maps configured for the device.

OnNewOptionsAsync

  • Executed when the device’s options change.

Parameters

  • A TOptions instance holding the previous device options.
  • A TOptions instance holding the current (new) device options.