Skip to main content

i4connected Knowledge Base

The Modbus Adapter

Abstract

Check out the settings required to set up an i4connected Modubus Adapter by reading this article!

This article describes the settings required for a Modbus Adapter.

The Modbus Adapter settings

In order to add a new Modbus device, the user is required to fill in a set of Modbus specific settings:

Modbus_adapter.jpg

The Modbus Adapter settings

  • Modbus server address - the address of the server providing the data.

    Clicking on the Select Modbus adapter name field, the Select Modbus server is opened. In this view, the user can select an existing Modbus server or add a new one. By using the simple filtering mechanism the user can easily pinpoint the desired Adapter.

    Select_the_Modbus_server_panel.jpg

    The Select Modbus adapter panel

    When clicking the Add button, the Add Modbus Server panel is opened allowing the user to fill in the following settings:

    Note

    Only users with the Manage adapters permission enabled can add and edit Adapters.

    add_Modbus_adapter.jpg

    The Add Modbus Server panel

    • Name - the Name of the new Modbus Adapter.

    • Description - the user-friendly description of the Modbus Adapter.

    • Modbus server address - The IP address of the Modbus server

    • Port - The port used for the Modbus connection. Default value: 502.

    • Poll interval (ms) - The time interval (in milliseconds) between subsequent polls. By default, the value is set to 10000 ms.

    • Register Byte order - Allows the user to select the Register Byte order selecting between Little Endian and Big Endian. Big-endian is an order in which the "big end" (most significant value in the sequence) is stored first (at the lowest storage address). Little-endian is an order in which the "little end" (least significant value in the sequence) is stored first.

    • Registers order - The byte order. Can be:0123 - the default format2301 - the Motorola format when reading data from registers, the Modbus Adapter reads two bytes at once. If using the normal register reading, the first register is read, and then the second register is read, etc. If using the reversed register reading (the Motorola format), the registers are read backward, starting with the last register and ending with the first. The data is then reversed in order to interpret the bytes.

    • Maximum of Packets per read - Sets the maximum amount of Packets per reading. The default value is set to 100 packets.

    • Maximum of empty packets - Sets the maximum amount of empty packets. The default value is set to 30 packets.

    • Select owner - the name of the Adapter owner.

      select_owner.jpg

      Adapter owner selector

      By clicking on the owner selector, the Select Users panel is opened allowing the user to chose the Adapter's owner.

      select_users_panel.jpg

      Select Users panel

      Important

      When adding a new Adapter the creator user is by default set as Adapter's owner. However, the owner can be changed after the Adapter was saved, by all users having at least the Manage adapters permission enabled.

    • Time zone - The time zone used by the new Modbus Adapter. By default, the Time Zone is predefined for the currently logged-in user.

    • Trace level - trace levels determine which events the trace provider generates. The user can select the desired trace level from a drop-down list where the following predefined value is available: Trace, Debug, Info, Warn, Error, Fatal, and Off.

    • Enabled - If the setting is turned on, the Adapter is enabled and functional.

  • Unit ID - the identification number of the Unit initialising a new instance. This field allows the insertion of a number between 0 to 255.

Tip

For more details about the Modbus Signal settings please also visit the dedicated article here.

The Modbus Adapter Configuration XML file

The Modbus Adapter configuration file allows the user to configure the Modbus Adapter in order to retrieve and parse the data coming from a Modbus device. The configuration must follow a simple but logical structure, detailed below.

XML configuration example structure:

<server address="66.60.189.138" pollInterval="60000" reverseRegisters="true" maxChunkSize="100" maxWasteSize="30">
  <unit id="3" name="191201454">
    <inputRegister address="30057" name="Serial#" type="UInt32" />
    <inputRegister address="30201" name="Status" type="UInt32" />
    <inputRegister address="30247" name="Error" type="UInt32" />
    <inputRegister address="30513" name="E-Total" type="UInt64" />
    <inputRegister address="30775" name="Pac" type="Int32" />
    <inputRegister address="30803" name="Fac" type="UInt32" />
    <inputRegister address="30805" name="Qac" type="Int32" />
    <inputRegister address="30813" name="Sac" type="Int32" />
    <inputRegister address="30225" name="Riso" type="UInt32" />
    <inputRegister address="30795" name="Iac" type="UInt32" />
    <inputRegister address="30769" name="Ipv" type="Int32" />
    <inputRegister address="30771" name="Upv" type="Int32" />
    <inputRegister address="30783" name="Vacl12" type="UInt32" />
    <inputRegister address="30785" name="Vacl23" type="UInt32" />
    <inputRegister address="30787" name="Vacl31" type="UInt32" />
    <inputRegister address="30197" name="ErrNo" type="UInt32" />
  </unit>
</server>
The <server> element

The root element <server> is used to define Modbus slave machine and the polling settings for the device's data.

The following attributes define the <server> element:

Element

Data Type

Description

address

string

The IP address of the Modbus slave machine.

port

int

The port was used to access the Modbus slave machine. Default value: 502.

pollInterval

double

The interval of time, defined in milliseconds, between two data interrogations. Default value: 60000.

reverseRegisters

bool

Toggles between the normal register reading (default format) and the reversed register reading (Motorola format). This attribute must be set to true (setting enabled) when using the reversed registers reading (the Motorola format), in order to reverse the read data before interpretation.

When reading data from registers, the Modbus Adapter reads two bytes at once. If using the normal register reading, the first register is read, and then the second register is read, etc. If using the reversed register reading (the Motorola format), the registers are read backward, starting with the last register and ending with the first. The data is then reversed in order to interpret the bytes.

Example device data

Register 1

Register 2

Byte 1

Byte 2

Byte 3

Byte 4

0001 1011

1010 1111

0010 1010

1010 0001

Normal register reading (default format)

Reverse register reading (Motorola format)

Register 1

Register 2

Register 1

Register 2

Byte 1

Byte 2

Byte 3

Byte 4

Byte 3

Byte 4

Byte 1

Byte 2

0001 1011

1010 1111

0010 1010

1010 0001

0010 1010

1010 0001

0001 1011

1010 1111

NOTE

The bytes inside a register are always read in the normal order (first byte, second byte) and never reversed!

maxChunkSize

int

The maximum number of straight data records (uninterrupted by empty records) to be read. The reading starts with the first data record. Default value: 100.

If, while reading, the maximum number of straight data records is exceeded, the reading is split (the current reading breaks and another reading starts). The reading never breaks in the middle of a tag, but always before the tag where the maximum number of straight data records excess occurs.

maxWasteSize

int

The maximum number of straight empty records (uninterrupted by data records) to be read. Default value: 30.

If, while reading, the maximum number of straight empty records is exceeded, the reading is split (the current reading breaks and another reading starts).

NOTE

Within a certain limit, it is recommended to include empty records (waste) in a reading, in order to reduce the amount of transferred packets.

Note

The attributes emphasized using bold characters are required. The other attributes are optional or required only in specific situations. If a non-required attribute is not defined, the parser will fall back to its default value.

Example:

<server address="66.60.189.138" port="502" pollInterval="60000" reverseRegisters="true" maxChunkSize="100" maxWasteSize="30">

</server>
The <unit> element

The <unit> element defines the Modbus device containing the registers.

The following attributes define the <unit> element:

Element

Data Type

Description

id

int

The unique ID of the Modbus device.

name

string

The unique name of the device in the p.EMS.

NOTE

The attributes emphasized using bold characters are required. The other attributes are optional or required only in specific situations. If a non-required attribute is not defined, the parser will fall back to its default value.

Example:

<server address="66.60.189.138" pollInterval="60000" reverseRegisters="true" maxChunkSize="100" maxWasteSize="30">
  <unit id="3" name="191201454">
    
  </unit>
</server>
The <coil>/<holdingRegisters>/<inputRegister>/<discreteInputs> element

The <coil>/<holdingRegister>/<inputRegister>/<discreteInput> element defines the type of register of the Modbus device. There are four types of registers available:

  • Coils

  • HoldingRegisters

  • InputRegisters

  • DiscreteInputs

All of the above register types have the same attributes.

The following attributes define the <coil>/<holdingRegister>/<inputRegister>/<discreteInput> element:

Element

Data Type

Description

address

string

The name of the tag is to be read.

name

string

The signal name from the device.

type

string

The type of value. All the available value types can be found in the link below:

TypeCode Enumeration

IMPORTANT: the <coil> and <discreteInput> are always of Boolean type! <holdingRegister> and <inputRegister> are 16 bits (2 bytes).

length

int

The number of items of the array, if the registers are arrays. Default value: 1 (not array).

Note

The attributes emphasized using bold characters are required. The other attributes are optional or required only in specific situations. If a non-required attribute is not defined, the parser will fall back to its default value.

Example:

<server address="66.60.189.138" pollInterval="60000" reverseRegisters="true" maxChunkSize="100" maxWasteSize="30">
  <unit id="3" name="191201454">
    <coils address="30057" name="Serial#" type="Boolean" length="1" />
    <holdingRegister address="30201" name="Status" type="UInt32" length="1" />
    <inputRegister address="30247" name="Error" type="UInt32" length="1" />
    <discreteInput address="30513" name="E-Total" type="Boolean" length="1" />
    
  </unit>
</server>