Modbus SPS Erweiterungsmodule

During the development of an automatic system in CODESYS, the implementation step of a field bus system comes up quite often. For example, there is a need to carry out climate control in a vegetable storage facility based on the SPK207 control panel from akYtec. Since the SPK207 does not have its own inputs and outputs on board, it requires using expansion modules. For instance, the I/O-Modules of the MX110 series from akYtec can be connected to this control panel over the RS485 interface. Any modules with interface Ethernet can also be connected to the SPK207. This article describes in detail all necessary steps for proper configuring the SPK207 control panel for data exchange via Modbus protocol in CODESYS v3.5 SP3 Patch5.

General technique for configuring interfaces in CODESYS 3.5

Modbus communication settings in CODESYS

Interfaces

When the SPK207 is successfully connected to the PC (see Appendix C in the User guide or watch the video tutorial), you can open any previous project in CODESYS or create a new one. Keyboard shortcut Alt+0 opens the Device tree so you could right-click the target device (akYtec SPK2xx) and select option Add device in the context menu.

add target device CODESYS

Among the appearing interfaces you have to left-click Modbus to select item Modbus COM of the same target device version or an older one.

add Modbus COM Port CODESYS

Confirm your selection by clicking the Add device button in the dialogue window. Now a serial port is available in the Device tree. You have to double-click port Modbus COM to open tab Modbus Serial Port Configuration and set the required parameters.

Modbus Serial Port Configuration CODESYS

In a similar way you can add the Ethernet port. Just select Ethernet in the Add Device dialogue instead of Modbus.

SPK207 as Modbus Master

If the desired interface of the SPK207 is supposed to function as Master, a Master device should be added to this interface in the Device tree. For this purpose, you have to use command Add Device again by right-clicking the appropriate interface. After that, select Modbus TCP Master for Ethernet or Modbus Serial Master for Modbus COM in the appearing dialogue window.

add Modbus Master COM Port CODESYS add Modbus TCP Master CODESYS

Now the Masters are available in the Device tree and they can be double-clicked for opening the configuration dialogue.

Device tree with Modbus TCP Master and Modbus Master COM Port CODESYS

The Modbus TCP Master has two configuration parameters: Response Timeout and Socket Timeout.

Modbus TCP Master Configuring CODESYS

The Response Timeout defines the time interval within which the Master awaits the response from the Slave. If there is no response during this interval, the next Slave is to be polled. The defined Timeout is applied for all Slaves.

The Socket Timeout is a maximal period of time within which the Master waits for the incoming TCP/IP packages.

The COM interface has a similar configuration procedure, but here parameter Time between frames should be configured instead of Socket interface. The Time between Frames defines the time span which the Master awaits between the last response (or timeout) and the next request.

Modbus Master COM Port Configuring CODESYS

When the Master devices are configured, it is time to add Slaves through the already well-known Add device dialogue window. Just select Modbus Slave or Modbus TCP Slave, depending on the port type (COM or Ethernet).

add Modbus Slave COM Port CODESYS add Modbus TCP Slave CODESYS

Now the Slaves are available in the Device tree and can be double-clicked for opening the configuration dialogue.

Device tree with Modbus TCP Slave and Modbus Slave COM PortCODESYS

The Modbus TCP Slave has the following parameters:

  • Slave IP Address – the IP-address of the Slave
  • Unit-ID – the network address of the Slave device in the range between 1 and 247
  • Response Timeout – the time span may be adapted individually to the Slave and will override the Response Timeout set for the related Master.
  • Port – the port number of the Slave.
Modbus TCP Slave Configuring CODESYS

The Slave device connected to the COM port has similar parameters:

Modbus Slave COM Port Configuring CODESYS

Further settings are about specifying the communication channels. A channel is a group of register addresses which are placed one by one and are polled by only one function. In purpose to add a channel, you can press button Add Channel in tab Modbus Slave Channel. After that, a dialogue window opens where you can configure the channel. All parameters are described in Codesys Online Help (Ctrl + Shift + F1).

add Modbus Slave channel CODESYS

When all desired channels are added, switch to tab ModbusGenericSerialSlave I/O Mapping to assign the corresponding project variables to the device in- and output channels. Just double-click the field of the required channel in column Variable and left-click the now available button button to access Input Assistant. Here you can take any project variable to be assigned to the channel after pressing OK.

Modbus IO-mapping CODESYS

There is also a tab called Modbus Slave Init available in the configuration dialogue of any Slave device. This tab is intended for previous initialization of data. For instance, when it is required to set a sensor type before the data exchange is started. The procedure is similar to the channel adding.

Modbus Slave Init CODESYS

SPK207 as Modbus Slave

Whether the Ethernet port or the COM port of SPK207 is supposed to be used in mode Slave, a Slave device should be added to the Device tree. Just select Modbus Serial Device for the COM port or Modbus TCP Slave Device for port Ethernet in the dialogue window Add Device.

add Modbus as Slave COM Port CODESYS add Modbus TCP as Slave COM Port CODESYS

Now the Slaves are available in the Device tree and can be double-clicked for their configuring. The following parameters are available:

  • TimeOut – the waiting time with possible step size for entries of 500 ms.
  • Unit ID – the device network address
  • Slave Port – the port number of the Slave unit
  • Holding Register – the quantity of holding registers
  • Input Register – the quantity of input registers which
Modbus as Slave COM Port Configuring CODESYS Modbus TCP as Slave COM Port Configuring CODESYS

The project variables can be assigned for the holding and input registers in tab … I/O Mapping. This procedure is exactly the same like in mode Master.

After performing all the manipulations, you have just to connect secondary devices to the SPK207 (Master mode) or the SPK207 to the master device (Slave mode), and check if the data exchange is correct.

The Modbus settings for the SPK207 are completed.