Modbus Slave

Modbus is an open and de facto standard communications protocol that is available in many programmable logic controllers (PLCs) and field devices for transfer of static data values using serial or IP messaging.

Modbus Object/Data Types

Data is presented in four data types, each with an address space, type, read/write mode and size.

00001 – 09999: Coils (read/write): 1 bit
10001 – 19999: Discrete Inputs (read only): 1 bit
30001 – 39999: Input Registers (read only): 16 bits
40001 – 49999: Holding Registers (read/write): 16 bits

Example – using Modbus slave to connect RTU data with a local HMI panel

This example shows RTU variables have been associated to a Modbus slave (address 1).  

All four Modbus data types are used.

Discrete Input Bits 1-4 represent boolean states of pump running, pump fault, station auto and tank overflow.

Input Registers 1-3 represent integer values of tank level, power supply voltage and power supply load.

Holding Registers 1-2 represent integer values of set point limit values used for  stopping and starting the pump.

Coil Bits 1-2 represent remote start and stop commands.

Modbus slave example

Modbus Slave – setup is easy

Use the fieldbus configurator to add the Modbus slave protocol, set the slave address, then create slave ‘data blocks’ for each data type eg. input bits, coil bits, input registers and holding registers. Each data block is a set of contiguous addresses – add multiple blocks of the different data types if required. Then drag the variables of interest from your list of program variables in to the appropriate data block and set their offset/position in the address list.

Modbus slave fieldbus configuration interface

Modbus Slave – standard serial or IP setup

If using TCP/IP then nothing needs to be added – by default the RTU listens on port 502 for Modbus messages.

If using serial comms, then a listening port is defined using the MBSLAVERTU function block.  This block has three inputs, enable, port eg. ‘COM1:9600,N,8,1’ and slave address eg. 1.

Modbus Slave – advanced setup with function blocks in the logic application

In some applications the RTU may be required to act as multiple slave devices to one or Modbus masters.  The WorkSuite logic editor includes additional function blocks that allow management of multiple Modbus slave ‘sessions’ eg. multiple server instances.

MBSLAVERTUEX – used like the MBSLAVERTU block, but includes an additional parameter to identify the server instance.

MBSLAVERTUEXD – used like the MBSLAVERTUEX block, but includes message outputs (status and types of messages).

MBSLAVETCP – used to define an alternate TCP listening port.

MBSLAVETCPEX – used to associate a server instance and slave ID.

MBSLAVEUDP – used to define a UDP listening port.

MBSLAVEUDPEX – used to associate a server instance and slave ID.

Click on an icon below to find out more about a particular protocol or driver.