Skip to content

Virtual Device Service Component

The Virtual Device Service component allows you to simulate different kinds of device and generated readings.

The Virtual Device Service supports the following key features:

  • Setting, and subsequently reading, values
  • Generating random boolean or numeric values in a specified range
  • Generating numeric value sequences representing a waveform
  • Generating numeric values, which steadily increase or decrease
  • Generating values following a fixed script

Note

Values can be of any type, unless specified in the above list.

Virtual Device Service Configuration

Note

The core components required for running the virtual device service (and all other device services) are contained in Device Service Component Configuration. Please refer to this page to ensure the appropriate core components are assigned before continuing.

Virtual Device Service Configuration Example

The following example configures four devices:

{
  "Library": "libxrt-virtual-device-service.so",
  "Factory": "xrt_virtual_device_service_factory",
  "Name": "virtual_device_service",
  "Topic": "virtual_device_service/data",
  "Devices": {
    "Random-Boolean-Device": {
      "profile": "Random-Boolean-Device",
      "protocols": {
        "Other": {
          "Address": "device-virtual-bool-01"
        }
      }
    },
    "Random-Float-Device": {
      "profile": "Random-Float-Device",
      "protocols": {
        "Other": {
          "Address": "device-virtual-float-01"
        }
      }
    },
    "Random-Integer-Device": {
      "profile": "Random-Integer-Device",
      "protocols": {
        "Other": {
          "Address": "device-virtual-int-01"
        }
      }
    },
    "Random-UnsignedInteger-Device": {
      "profile": "Random-UnsignedInteger-Device",
      "protocols": {
        "Other": {
          "Address": "device-virtual-uint-01"
        }
      }
    }
  },
  "Schedules": [
  {
    "device": "Random-Boolean-Device",
    "resource": "RandomValue_Bool",
    "frequency": 5000000000000
  },
  {
    "device": "Random-Float-Device",
    "resource": "RandomValue_Float32",
    "frequency": 50000000000000
  },
  {
    "device": "Random-Integer-Device",
    "resource": "RandomValue_Int32",
    "frequency": 50000000000000
  },
  {
    "device": "Random-UnsignedInteger-Device",
    "resource": "RandomValue_Uint32",
    "frequency": 50000000000000
  }],
  "ProfileDir": "profiles",
  "Scheduler": "sched",
  "Logger": "logger",
  "Pool": "pool",
  "Bus": "bus"
}

Virtual Device Profile

Details on general profile usage can be found on the Device Profiles page.

Every device that is created in the Virtual Device Service is associated with a device profile that specifies the following:

  • The readings available from the device
  • How the Virtual Device Service generates these readings

Note

More than one device can be configured to use the same device profile.

IOTech supplies a number of example device profiles with the Virtual Device Service. These device profiles provide random and fixed-sequence reading types. The available readings in a device profile are defined in the deviceResource section. Each deviceResource names the available reading and describes its properties, such as its datatype. The attributes of the deviceResource define the how the Virtual Device Service handles requests for a reading.

If the sequenceType attribute is not present, the reading initially has a zero value (for example, a zero, an empty string, or false value) or, if present, the value of the firstValue attribute. New values can be written to the reading and subsequent reads return the new value; however, this does not persist if the Device Service is restarted.

If the sequenceType attribute is set, the Device Service generates a sequence of values. With the exception of the random sequenceType, only numeric data, that is integer and float data, is supported. The random sequenceType additionally supports boolean data.

The supported sequence types are described in the following table:

SequenceType Description
Random Each reading returns a random value

Unless the deviceResource type is boolean, the maximum and minimum attributes, which specify the range of valid values, must be defined
arithmetic By default, generates a sequence starting from one and increasing by one with each new reading

To override the default sequence starting point, specify the firstValue attribute

To override the rate at which readings increase, specify a positive difference attribute

To override the rate and decrease the readings, specify a negative difference attribute
script Generates a sequence of values as specified by the sequence attribute

Must be a JSON array, where each element specifies a value and, optionally, a repeat

The generated sequence consists of each specified value in turn

If repeat is specified for a value, the value is repeated the specified number of times

When the end of the sequence is reached, the last value is repeated indefinitely
Waveform Used to generate waveforms of various shapes

The following table describes the attributes that characterize the waveform:
Attribute Description Required
shape Specifies the shape of the waveform

Valid values are as follows:
  • sinewave (default)
  • sawtooth
  • triangle
  • square
N
amplitude Specifies the amplitude of the wave

Measured peak-to-trough

The valid values depend on the data type assigned to the resource
Y
period Specifies the period of the wave; how many successive readings constitute a full cycle

Must be a positive integer
Y
offset Applies the specified offset to the generated values

Default is 0 (no offset)
N
phase Advances the wave by the specified number of readings

Must be a positive integer
N

For example, the following graph shows two reading sequences obtained from the sinewave generator, both with an amplitude of 4.0 and a period of 8; sinewave2 also has an offset of 10.0 and a phase of 2 (which causes it to lead sinewave by two readings):

Generated sine waves

Device Commands

See the Device Commands page for details on how to define device commands for grouping device resources for fewer requests.

Device Service Interaction

Run the Virtual Device Service

Find details on how to run the Virtual device service on the Run Device Services page.

Back to top