Accessing Modbus Data

To access data using a Modbus datasource, it is necessary to create and configure a corresponding Modbus IO-Item object in the I/O Model.

  1. To add a new IO-Item, select the Modbus datasource in the I/O Model, right click and in the context menu select Admin  New  External Interfaces  IO-Item.

  2. In the Create Object wizard enter a name for the IO-Item which is unique in the branch of this datasource and, optionally, an Object Description.

  3. Then enter the Item ID, following this schema:

    MB.<Item Type code>:<Reference>

    For Reference and Item Type refer to the vendor’s specification of the Modbus device. Then use the following table to find the Item Type Code corresponding to the Item Type.
    The first reference number is 1, and it may be padded with zeros.
    See a note below about specifying a byte order.

    Table 1. The Modbus Data Model
    Item Type Item Type Code Object Type Type of Access Comments

    Coils / Discrete Output

    0

    Single bit

    Read-Write

    This type of data can be altered by an application program.

    Discrete Input

    1

    Single bit

    Read-Only

    This type of data can be provided by an I/O system.

    Input Registers

    3

    16-bit word

    Read-Only

    This type of data can be provided by an I/O system

    Holding Registers / Output Registers

    4

    16-bit word

    Read-Write

    This type of data can be altered by an application program.

    modbus ioitem common
  4. In the Item Type section select 'Modbus'.
    This value can only be changed during the creation of the object. Once the object is created, its Item Type is fixed and can no longer be changed.

    This Item Type property refers to the type of IO-Item object, not the type of the Modbus data item.
    modbus ioitem itemtype selection
  5. Select the appropriate Data Type property for this IO-Item from the dropdown list.

    modbus ioitem datatype selection
  6. In the Elements number property set the number of elements of the Data Type or the length of a string. For a value higher than 1 this will lead to an array output for any Data Type but 'String'.

  7. Click Create to create the IO-Item in the I/O model.

Specifying byte order

The byte order can be specified in the ItemID property by appending .boDDDD, where D on the i-th position is a digit specifying the position of the i-th byte in the data sent to or received from a modbus device. It is applicable for all data types supported by the Modbus datasource but bits.

Modbus stores data in the Big-Endian format, however many clients run on a Little-Endian CPUs. Many vendors are trying to provide data in a convenient format. However there is a room of an interpretation of the convenience. So, sometimes one has to adjust the byte order. By default the order of registers is preserved, but the bytes within a register are swapped. This is how popular modbus clients work by default. E.g., the number 168496141 (hex: 0A 0B 0C 0D) on the Little-Endian platform is represented as hex: OD 0C 0B 0A. So, it will be sent as hex: 0C 0D 0A 0B` to the modbus device. It correspond to the byte order ".bo21".

The byte order can consist of up to 8 first different digits, starting with 1. If there are more characters in the definition then the definition is truncated. If the length of the byte order does not fit an integer number of times the length of the requested data, then the tail stays intact. E.g. for the string "abcde" if the byte order is ".bo321", then the value will be "cbade".