Modbus TCP

The Modbus protocol (standard IEC 61158) is a protocol for data exchange between a Modbus server and a Modbus client. Port 502 is reserved for Modbus TCP. The following data can be read or written:

Data type

Unit

Access

Digital outputs

[Bit]

Reading & Writing

Digital inputs

[Bit]

Read

Analog inputs

[16Bit]

Read

Analog inputs/outputs

[16Bit]

Reading & Writing

The following Modbus functions are implemented:

Number

Name

Server

Client

Description

FC1

Read Coils

Yes

Yes

read back several digital outputs

FC2

Read Discrete Inputs

Yes

Yes

read multiple digital inputs

FC3

Read Holding Register

Yes

Yes

read multiple analog inputs/outputs

FC4

Read Input Register

Yes

Yes

read multiple analog inputs/outputs

FC5

Write Single Coil

Yes

No

set a digital output

FC6

Write Single Register

Yes

No

write an analog output

FC15

Write Multiple Coils

Yes

Yes

set several digital outputs

FC16

Write Multiple Registers

Yes

Yes

Write multiple analog outputs

FC23

Read/Write Multiple Registers

No

Yes

write several analog outputs and read inputs/outputs simultaneously

Modbus TCP Server

In the Gefasoft Modbus TCP server, data blocks are created that can be read and written by a Modbus TCP client. Each data block must have a unique address range consisting of start address and data length. The unit of the start address or the data length depends on the data type. Digital inputs/outputs are addressed in [Bit] and analog inputs/outputs in [16Bit] or [WORD]. The data ranges of the digital inputs/outputs and analog inputs/outputs must not overlap!

../../../_images/gio-modbus-server-CreateNewHW.png
  1. Type: Modbus TCP Server

  2. ID: ID assigned

  3. name suffix: Name control

  4. Create: Press button to generate object

  5. DisplayName: Name controller

  6. IP/Port: Enter the IP address and port for the Modbus TCP Server Listener.

  7. UnitIdentifier: The Gefasoft Modbus server ignores the UnitIdentifier received from the client. Since there is only one unit, all unit identifiers are accepted. The data block is identified by the start address received from the client.

  8. +: Adding data areas to be used for communication

../../../_images/gio-modbus-server-CreateNewHW-EditDatablock.png
  1. DataBlockID: ID for this data block.

  2. Name: Name of the data area

  3. Count: Data count in [Bit] for digital inputs/outputs, or in [16Bit] for analog inputs/outputs.

  4. EType: Data type

Data type

Unit

Impement

Client access

EDigitalInputs

[Bit]

Yes

digital [Bit] & analog [16Bit] Read

EDigitalOutputs

[Bit]

Yes

digital [Bit] & analog [16Bit] read & write

EHoldingRegisters

[16Bit]

Yes

digital [Bit] & analog [16Bit] read & write

EInputRegisters

[16Bit]

Yes

digital [Bit] & analog [16Bit] Read

EOutputRegisters

[16Bit]

Yes

digital [Bit] & analog [16Bit] read & write

EInputRegistersAcyclic

[16Bit]

No

none

Hint

Since the Viper Modbus TCP Server keeps the process data in the main memory, access to all implemented data block types is possible via analog [16Bit] and digital [1Bit] Modbus functions.

  1. StartAddress: Start address of the data in [Bit] for digital inputs/outputs, or in [16Bit] for analog inputs/outputs.

  2. TwistRegisterBytes: Swap high and low bytes during register access (for analog inputs/outputs).

  3. Acyclic input registers: The Gefasoft Modbus server does not implement acyclic register access. All data is stored in the process image in memory and is read and written directly.

  4. FileName: Path to a file to permanently save the data of the data block. The data is saved on exit and read again on startup.

See also

Modbus TCP Client

The Gefasoft TCP client is used to exchange data with a Modbus TCP server.

../../../_images/gio-modbus-client-CreateNewHW.png
  1. Type: Modbus TCP Client

  2. ID: ID assigned

  3. name suffix: Name control

  4. Create: Press button to generate GInOut-Hardwar

  5. DisplayName: Name controller

  6. IP/Port: Enter the IP address and the port of the Modbus TCP server to which the client should connect.

  7. UnitIdentifier: Unit ID for all data queried by the server (The UnitIdentifier is part of the Modbus header).

  8. +: Adding data areas to be used for communication

../../../_images/gio-modbus-client-CreateNewHW-EditDatablock.png
  1. DataBlockID: ID for this data block.

  2. Name: Name of the data area

  3. Count: Data count in [Bit] for digital inputs/outputs, or in [16Bit] for analog inputs/outputs.

  4. EType: Data type

Type

Unit

Implement

EDigitalInputs

[Bit]

Yes

EDigitalOutputs

[Bit]

Yes

EHoldingRegisters

[16Bit]

Yes

EInputRegisters

[16Bit]

Yes

EOutputRegisters

[16Bit]

Yes

EInputRegistersAcyclic

[16Bit]

Yes

  1. StartAddress: Start address of the data in [Bit] for digital inputs/outputs, or in [16Bit] for analog inputs/outputs.

  2. TwistRegisterBytes: Swap high and low bytes during register access (for analog inputs/outputs).

  3. Acyclic input registers: Some analog data are not located in the process image of the Modbus server. These must then be read out via EInputRegistersAcyclic (FC23). The Modbus server is informed via the parameters ‘ReadAcyclStartAddressWrite = target address for register number’ and ‘ReadAcyclDataWrite = register number to be read’ which process data it should send to the client.

Hint

For analog outputs (registers), the data alignment must be set to two bytes, since the unit for transmitting the data in the Modbus protocol is [16Bit] !

../../../_images/gio-modbus-client-registers-data-alignment.png

Double-clicking the data node (1) opens the parameter dialog for the data settings. The parameter alignment (2) must be set to ‘2’. Also in the data editor (3) the data can then only ever be written 16bit by 16bit.

See also

Hint

With some Modbus TCP bus controllers it is necessary to switch off the watchdog on the server side, otherwise no error-free communication with the GInOut Modbus TCP client is possible.

Disable the watchdog of the bus controller B&R X20BC0087.

  1. Start cmd.exe

  2. enter the following commands:

  • telnet 192.168.100.1

  • fc6 0x1043 0xC0

  • flash store

  • quit

Disable the watchdog of the Beckhoff BK9100 bus controller.

  1. Create Modbus TCP Client in the HW Explorer (172.16.17.1:502).

  2. Create data block holding register address 4384 (0x1120). This is the register for the watchdog time [ms].

  3. Create GInOut data for the data block and write the value ‘0’ into register 4384 (0x1120).