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!
Type: Modbus TCP Server
ID: ID assigned
name suffix: Name control
Create: Press button to generate object
DisplayName: Name controller
IP/Port: Enter the IP address and port for the Modbus TCP Server Listener.
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.
+: Adding data areas to be used for communication
DataBlockID: ID for this data block.
Name: Name of the data area
Count: Data count in [Bit] for digital inputs/outputs, or in [16Bit] for analog inputs/outputs.
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.
StartAddress: Start address of the data in [Bit] for digital inputs/outputs, or in [16Bit] for analog inputs/outputs.
TwistRegisterBytes: Swap high and low bytes during register access (for analog inputs/outputs).
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.
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.
Modbus TCP Client¶
The Gefasoft TCP client is used to exchange data with a Modbus TCP server.
Type: Modbus TCP Client
ID: ID assigned
name suffix: Name control
Create: Press button to generate GInOut-Hardwar
DisplayName: Name controller
IP/Port: Enter the IP address and the port of the Modbus TCP server to which the client should connect.
UnitIdentifier: Unit ID for all data queried by the server (The UnitIdentifier is part of the Modbus header).
+: Adding data areas to be used for communication
DataBlockID: ID for this data block.
Name: Name of the data area
Count: Data count in [Bit] for digital inputs/outputs, or in [16Bit] for analog inputs/outputs.
EType: Data type
Type |
Unit |
Implement |
---|---|---|
EDigitalInputs |
[Bit] |
Yes |
EDigitalOutputs |
[Bit] |
Yes |
EHoldingRegisters |
[16Bit] |
Yes |
EInputRegisters |
[16Bit] |
Yes |
EOutputRegisters |
[16Bit] |
Yes |
EInputRegistersAcyclic |
[16Bit] |
Yes |
StartAddress: Start address of the data in [Bit] for digital inputs/outputs, or in [16Bit] for analog inputs/outputs.
TwistRegisterBytes: Swap high and low bytes during register access (for analog inputs/outputs).
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] !
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.
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.
Start cmd.exe
enter the following commands:
telnet 192.168.100.1
fc6 0x1043 0xC0
flash store
quit
Disable the watchdog of the Beckhoff BK9100 bus controller.
Create Modbus TCP Client in the HW Explorer (172.16.17.1:502).
Create data block holding register address 4384 (0x1120). This is the register for the watchdog time [ms].
Create GInOut data for the data block and write the value ‘0’ into register 4384 (0x1120).