Virtual Modbus sensor

sim-modbus-sensor service simulates a Modbus sensor which can accept read register commands.

Features provided

The service provides a single (or multiple for data types longer than 16 bit) holding or input register (h@0 or i@0).

Using the source/kind field in the configuration, the service can modify the register in the following way:

  • none no modification. The register(s) can accept external write commands

  • random a random value, changed once a second

  • timestamp server timestamp, changed once a second

  • udp gets values from UDP port (the value must be sent as raw bytes)

With udp source the sensor can read data from any external generator e.g. from Matlab Simulink. The default Simulink UDP sink sends IEEE-754 64-bit floats only, set long_float source parameter to true to automatically convert incoming numbers to the desired data type.

Deployment

Note

A Virtual Modbus port must be deployed first.

eva svc create sim.modbus1.sensor1 /opt/eva4/sim/svc-tpl-sim-modbus-sensor.yml

where the service configuration template is:

command: sim/sim-modbus-sensor
bus:
  path: var/bus.ipc
config:
  port_svc: sim.modbus1.port
  # Modbus unit ID
  unit: 2
  # INT, UINT, DINT, UDINT, LINT, ULINT, REAL or REALB (IEEE-754 big-endian)
  type: UINT
  # h for h@0 (holding), i for i@0 (input)
  reg: h
user: nobody

EAPI methods

The following methods can be called via the local bus (see EAPI commons):

var.get

Description

Get the sensor value

Parameters

none

Returns

The sensor value

Return payload example:

{
    "value": 25
}

var.set

Description

Set the sensor value

Parameters

required

Returns

nothing

Parameters

Name

Type

Description

Required

value

Any

Sensor value

yes