Modbus master controller

Allows to communicate with Modbus-powered PLCs and other equipment.

Setup

Use the template EVA_DIR/share/svc-tpl/svc-tpl-controller-modbus.yml:

# Modbus master controller service
command: svc/eva-controller-modbus
bus:
  path: var/bus.ipc
config:
  modbus: 
    protocol: tcp # udp, rtu, ascii or native for the local bus
    path: 192.168.1.200:502 # for serial:
    #  /dev/ttySXX:SPEED:DATABITS:PARITY:STOPBITS, e.g. /dev/ttyS0:9600:8:N:1
    #  for the local bus: service name
    unit: 1 # default modbus unit
    # frame_delay: 0.1 # optional serial frame delay (sec), default: 0.1 (100ms)
    # set to false if the target device is unable to process FC16 (bulk set,
    # default: true)
    #fc16_supported: false
    # turn off TCP keep-alive (opens a new connection per request), can be used
    # for devices which can not handle Modbus command queue properly (SLOW!)
    #keep_alive: false
  # panic on critical errors in X seconds after happened (0 - panic immediately)
  panic_in: null
  # default retry attempts for all operations (0 - no retries, give up if the
  # first attempt fails)
  retries: 2
  # an optional delay betwen writing tags and verifying written value
  #verify_delay: 0.1
  # event queue size, pull events ARE DROPPED on overflow. consider ALWAYS
  # having queue size > max possible tags pulled
  queue_size: 32768
  # ttl cache for pull events (sec, skip non-modified)
  pull_cache_sec: 3600
  # PLC pull interval, in seconds
  pull_interval: 1
  # pull blocks and parse maps
  #
  # the configuration is very similar (but extended) to the widely-used
  # https://github.com/alttch/pulr tool
  #
  #pull:
    #- reg: h0 # h = holding, i = input, d = discrete, c = coils
      #count: 10
      #unit: 1 # override the default modbus unit
      #map:
        #- offset: 0
          #  Offsets ARE NOT register numbers, but absolute offsets in block
          #  can be written as N+N+N
          ## absoltue offset (reg no.) can be specified as =N
          #oid: sensor:tests/test0
          # allowed types: real (REAL), real32, real64 (LREAL), real32b,
          # real64b (for IEEE 754 big-endian), uint16 (UINT), word, uint32
          # (UDINT), dword, sint16 (INT), int16, sint32 (DINT),
          # int32, sint64 (LINT), int64, uint64 (ULINT), qword
          # float numbers are decoded/encoded as IEEE754
          #type: real
        #- offset: 0+4
          #oid: sensor:tests/test1
          #type: real
          #value_delta: 0.5 # report event only if the new value difference is >=
          #transform:
            #- func: multiply # multiply the value by N
              #params: [ 1000 ]
            #- func: divide # divide the value by N
              #params: [ 1000 ]
            #- func: round # round the value to N digits after comma
              #params: [ 2 ]
            #- func: calc_speed # use the value as calc-speed gauge (with N seconds delta)
              #params: [ 1 ]
            #- func: invert # invert the value between 0/1
            # #params: []
    # pull bits
    #- reg: h100
      #count: 1
      #unit: 1 # override the default modbus unit
      #map:
        #- offset: 0/0
          #oid: sensor:tests/flag0
        #- offset: 0/1
          #oid: unit:tests/u1
    # pull coils
    #- reg: c0
      #count: 2
      #unit: 1 # override the default modbus unit
      #map:
        #- offset: 0
          # pull coil as unit value   
          #oid: unit:tests/relay_1
        #- offset: 1
          #oid: unit:tests/relay_2
  # action queue size, per item, actions on overflow are not dropped but wait
  # their attempt to enter the queue. The core marks an action as failed if it
  # does not enter the queue for <action timeout> seconds
  action_queue_size: 32
  # verify written data for actions
  actions_verify: true
  # OID map for actions
  #action_map:
    #unit:tests/u1:
      #reg: h100
      #type: real
      #unit: 1 # override the default modbus unit
    #unit:tests/u3:
      #reg: c10
timeout:
  # startup timeout should be slightly langer than default to allow the
  # controller prepare connection pool
  startup: 10
user: nobody
react_to_fail: true

Create the service using eva-shell:

eva svc create eva.controller.modbus1 /opt/eva4/share/svc-tpl/svc-tpl-controller-modbus.yml

or using the bus CLI client:

cd /opt/eva4
cat DEPLOY.yml | ./bin/yml2mp | \
    ./sbin/bus ./var/bus.ipc rpc call eva.core svc.deploy -

(see eva.core::svc.deploy for more info)

EAPI methods

See EAPI commons for the common information about the bus, types, errors and RPC calls.

action

Description

Executes a mapped unit action

Parameters

See Unit actions

Returns

See Unit actions

kill

Description

Attempts to terinate/cancel all actions for a unit

Parameters

See Unit actions

Returns

See Unit actions

reg.get

Description

Get Modbus slave register

Parameters

required

Returns

Tag value, single or list

Parameters

Name

Type

Description

Required

unit

u8

Modbus unit ID

yes

reg

String

Register (h/i/d/c e.g. h100 for holding #100)

yes

type

String

Data type (e.g. DINT)

no

bit

u8

Get an individual bit

no

count

u32

Count of bits/registers

no

timeout

f64

Max operation timeout

no

retries

u8

Retry attempts

no

reg.set

Description

Set Modbus slave register

Parameters

required

Returns

nothing

Parameters

Name

Type

Description

Required

unit

u8

Modbus unit ID

yes

reg

String

Register (h/i/d/c e.g. h100 for holding #100)

yes

value

Any

value to set

yes

type

String

Data type (e.g. DINT)

no

bit

u8

Get an individual bit

no

verify

bool

Read the register back and verify its value

no

timeout

f64

Max operation timeout

no

retries

u8

Retry attempts

no

terminate

Description

Attempts to terminate/cancel a unit action

Parameters

See Unit actions

Returns

See Unit actions