Epsilon LD - Modbus: User Guide
Epsilon LD - Modbus: User Guide
EPSILON LD - MODBUS
User Guide
DPA-302.1
Abstract
This document contains information on setting up Modbus communication on
industrial logic controllers of the Regul RX00 series. Setup is done using Epsilon LD
software.
Contents
Contents
Introduction.................................................................................................................. 4
General information ..........................................................................................................................................4
Recommended Documents ..............................................................................................................................4
Getting Started ..................................................................................................................................................5
Principle of Adding Devices .............................................................................................................................5
Modbus ASCII and Modbus RTU Configuration ...................................................... 8
Adding a Serial Port ..........................................................................................................................................8
Adding a Port ....................................................................................................................................................8
Port Settings ......................................................................................................................................................9
Configuring Modbus Serial Master ..................................................................................................................9
Configuring Modbus Serial Slave .................................................................................................................. 17
Modbus TCP Configuration ...................................................................................... 22
Configuring Modbus TCP Master .................................................................................................................. 22
Configuring Modbus TCP Slave..................................................................................................................... 24
Introduction
General information
The Regul controller software allows you to configure it both as a Modbus Master and
as a Modbus Slave. These implementations are independent of each other. The
controller can be a “master” on one of the communication lines, and on the other, a
“slave”.
As a Modbus Master, the controller polls the slaves via the RS-232 serial line | RS-485
(Modbus RTU | ASCII modes) or via Ethernet (Modbus TCP mode). As a Modbus Slave,
the controller also operates in three modes (RTU | ASCII | TCP).
The following functions of the Modbus protocol are supported:
• Reading and writing relay states Read Coils (0x01), Write Single Coil (0x05),
Write Multiple Coils (0x0F)
• Read Discrete Inputs (0x02)
• Read and write storage registers - Read Holding Registers (0x03), Write Single
Register (0x06), Write Multiple Registers (0x10)
• Read input registers - Read Input Register (0x04)
Recommended Documents
For more information on configuring other parameters of the Regul RX00 series
controllers in the Epsilon LD development environment, it is recommended that you
read the following documents:
• Epsilon LD Software. User Manual.
• Regul R600. System Manual.
• Regul R500. System Manual.
• Regul R400. System Manual.
• Regul R200. System Manual.
Getting Started
• Install Epsilon LD software on your computer. A description of the process of
installing the program, as well as instructions on how to use the program, are
given in the document “Epsilon LD Software. User's manual". The installation
program and documentation are available on the website www.gp-
systems.com.
• Launch Epsilon LD. Create or open a project. Make sure that there is a
controller in the project that will participate in the data exchange via the
Modbus protocol. If the controller is missing, add it using the Regul
Configuration Wizard (see the Epsilon LD Software User Guide).
The Add Device window opens where by default the list of devices that is currently
available for the user to insert is displayed, for example, when adding a crate the list
of crates, when placing modules in the crate the list of modules, to configure Modbus
the serial port, slave and master devices (Figure 2).
Select the desired device, click the Add device button or double-click the left mouse
button. The selected device will appear in the project in the device tree.
In the device tree you need to connect (depending on the situation) not only devices
that correspond to real-life modules, but also virtual devices that do not have a
hardware equivalent. For example, Modbus devices are virtual and are designed to
configure the parameters of the IEC library that is automatically loaded into the
project when a specific device is connected.
When configuring various modes, Modbus devices are connected to the
corresponding serial port or directly to the controller. In the figure 3 are shown
examples of configurations when configuring various Modbus modes:
• Option 1 - Modbus Serial Master, where the communication channel is the
built-in serial port of the controller
• Option 2 - Modbus Serial Slave, the communication channel is also an
integrated serial port
• Option 3 - Modbus Serial Master on the serial port of the communication
module
• Option 4 - Modbus Serial Slave on the serial port of the communication module
• Option 5 - Modbus TCP Master
• Option 6 - Modbus TCP Slave
Adding a Port
If any of the RS-485/232 ports of the processor module are used for data exchange,
then the Regul Serial Port device must be added to the controller in the configuration
(Regul → Serial Port→ Regul Serial Port). The number of possible devices of this type
is limited by the number of physical RS-485 (RS 232) ports on the central processing
unit.
If the communication module port is used for data exchange then the Extended Regul
Serial Port device (Regul → Serial Port → Extended Regul Serial Port) must be added
to the communication module in the configuration. The number of possible child
devices is limited to the module model.
Port Settings
Double-click the port name to open the main tab of the port settings. Go to the
internal tab Serial Port Settings (Figure 4, Figure 5). Set the switch in the Port
number field (matches the number indicated on the module). Next, selecting a value
from the drop-down list, set the following parameters:
• The speed is from 9600 to 115200
• Number of data bits - values: 8.7, 6, 5, 4
• Parity - parity, values: None, Odd, Even
• Duration of stop-bit - 1 or 2
Add a Modbus Serial Master device to the Regul Serial Port or Extended Regul Serial
Port (Regul → Modbus → Serial Modbus Master → Modbus Serial Master). Double-click
the Modbus Serial Master device name to open the parameters tab (Figure 6).
Selecting the check box in the Debug mode field enables debug mode (additional
information about the operation will be recorded in the controller log).
Next, one or several external slave devices (outer slaves) that will be polled by the
controller (Regul → Modbus → Serial Modbus Master → Modbus Serial Outer Slave)
need to be connected to the Modbus Serial Master device. The maximum number is
limited by the range of available Modbus addresses. Double-click the Modbus Serial
Outer Slave device name to open the parameters tab. By default, the first inner tab of
the Modbus Setup tab modbus serial outer slave is opened (Figure 7).
Checking the box in the Debug mode field enables debug mode.
Set the following parameters:
• Slave ADR is the slave address of the device according to the Modbus protocol.
Each of the devices (outer slave) on the common polling bus (serial line) must
have a unique address in the range from 1 to 247
• Responsetimeout - time to wait for a response to a request. The default is
1000 ms
• Behavior in STOP mode - behavior in STOP mode. Indicates what to do if the
RUN | STOP switch of the controller is set to the STOP position: No activity
option means stop polling, the Normal work option means continuing to work
in normal mode (the Modbus operating cycle does not depend on the Run |
Stop controller)
• Serial Mode - polling mode. Possible values: ASCII or RTU
Note: it is possible to independently activate "behavior in STOP mode" in the program code. This may be
necessary, for example, in a redundant system if the slave controller is required not to conduct a poll. When
adding a Modbus device an instance of the corresponding function block of the same name is also created.
To activate the mode the program requires the instance of the Modbus Serial Master function block (not a
slave!) to set the property TRUE to the ActivateStopBehavior property:
Modbus_Serial_Master.ActivateStopBehavior:=TRUE;
After that all slaves connected to this master will switch to STOP mode.
Next, you need to describe the data that the controller will request from the slave
devices. Go to the internal tabs of the channels modbus slave. Each Modbus request
is presented in the form of a so-called “modbus slave channel”. To set the description
of the new channel, click the Add Channel button, the dialog box opens. (Figure 8).
The Edit button opens the same form, but in the edit mode of an existing channel. The
Delete button deletes the description of the specified Modbus channel.
Set the following parameters:
• Name - friendly name (human readable)
• Function Code - the number of the Modbus function used to read / write data
• Channel type - if you select the Timer value, this request will be executed at
the frequency specified in the Call interval (ms) parameter, if you select the
Trigger value the request will be executed on an event (then you need to
specify the variable that triggers the event)
• Offset - the address of the first requested item, according to the Modbus
protocol
• Length - the number of requested items (registers or flags depending on the
function code)
• Call interval (ms) - the frequency of polling this channel, in milliseconds
• Description - optional text description
Figure 9 shows two examples: adding a channel to read 32 discrete values with a
periodicity of 1000 ms and adding a command to set a single flag (single coil) with
number 10 per event.
The added channels on the Modbus slave channels tab are as follows.:
Next, go to the Modbus Serial Outer Slave I/O Mapping tab. The Connect
parameter shows the connection status with the device based on the result of the last
request (no response - no connection) (Figure 11).
Figure 11. The Connect parameter displays the connection status with the device
For the data received from the slave device to be used in the controller program the
I/O Ratio tool is used. It allows you to compare the data of the Modbus channels with
the user variables of the controller program.
Note: in the terminology of the development environment the channel is any input or output parameter of
the device. To avoid confusion with the Modbus channels the channels listed in the table in Figure 12 are
called parameters in this section.
The following channel statuses are used when declaring a channel status transfer in
the PsModbusSerialMaster library (Table 1):
Table 1. Channel statuses in the PsModbusSerialMaster library
Name Initial Comment
Unreliable 0 unreliable
InProcess the request-response cycle is in progress
Timeout error - no answer
Ok data is reliable
ErrorInResponse error - error in response
UserReqArg error - invalid argument in user request
To associate an input / output parameter with a variable, on the Modbus Serial
Outer Slave I/O Mapping (Figure 12) double-click in the line of the desired channel.
A button appears that opens the Input Assistant window (Figure 13). Find the
desired variable. If the check box in the Structured view field is checked then open
the lists using the button. If the check box is cleared and the variables are presented
in one large list use the filter to make the search easier.
The Modbus Serial Outer Slave Tab_The ratio of inputs / outputs, where the
channel has already been assigned to variables, is as follows (Figure 14):
When polling for an event, you must associate the Trigger parameter with a variable
of type BOOL. The event will be the switching of the variable from the FALSE state to
the TRUE state. The Modbus driver does not resets the trigger. To repeat the request,
you must independently transfer the variable to the FALSE state and in the next cycle
of the controller's task to re-trigger the event.
Selecting the check box in the Debug mode field enables debug mode (additional
information about the operation will be recorded in the controller log).
Set the following parameters:
• Slave ADR is the slave address assigned to the controller according to the
Modbus protocol
Modbus_Serial_Slave_Device.ActivateStopBehavior:=TRUE;
Go to the internal tab of the modbus slave data area, where the description of the
Modbus data area available for querying from the external Master devices is placed.
To set a description of the new area, click the Add Data Area button, the dialog box
opens (Figure 16).
The Edit button opens the same form, but in the edit mode of an existing data area.
The Delete button deletes the description of the specified Modbus Slave data area.
Set the following parameters:
• Name - friendly name (human readable)
• Type - Modbus data type (Discrete Inputs, Coils, Input Registers, Holding
Registers)
• Offset - the address of the first element available for the request, according to
the Modbus protocol
• Length - the number of elements available for the request (registers or flags,
depending on the type of data Modbus)
• Variable name - here you specify the variable (controller program) in which
the transmitted data is stored the size of the variable must be at least the size
of the declared Modbus data area (the Length field)
• Description - optional text description
To fill in the Variable name field, click in this field the button that opens the
Input Assistant window. Find the desired variable. If the check box in the
Structured view field is checked, then open the lists using the button . If the check
box is cleared and the variables are presented in one large list use the filter to make
the search easier.
Figure 17 shows an example when 4 data fields are created, one for each Modbus data
type. The size of each data area is 2000 elements. For data areas such as Coils and
Discrete Inputs, the data element is a bit, respectively, the size of the variable to be
bound in bytes is calculated by the formula: (channel length-1) / 8 + 1. For data areas
of type Input Registers and Holding Registers, the data element is a register that
corresponds in size to the WORD type in the development environment. In our
example, arrays coils_area and di_area, corresponding to 250 bytes in size (Figure
18). are associated with data fields of the type Coils and Discrete Inputs, respectively
(Figure 18). The arrays ir_area and hr_area, respectively each with 2000 WORD
elements are associated with the Input Registers and Holding Registers data areas
(Figure 18).
Note: Variable binding is implemented at the PsModbusSerialSlave library level, and not using the I/O Mapping
mechanism, as in previous versions.
Figure 18. Variable declaration for Modbus channels with M-Memory and references
When working with data transmitted via Modbus, the strategies described below can
be applied.
The first strategy is to use the M-memory controller. For each data type Modbus is
created in one variable with a size sufficient to accommodate all transmitted values.
The variable is declared with the AT directive and an indication of the address in the
M memory. Next, you should create one Modbus channel for each data type (Discrete
Inputs, Coils, Input Registers, Holding Registers) linking them with previously
declared variables. These variables fulfill only the role of data buffers available for
reading and writing. The data that is required to be transmitted via Modbus may have
any type of development environment and must be declared also with the AT
directive located at the addresses that fall into the corresponding buffer. This
approach is implemented in the example shown in Figures 17 и 18 (marked as “Work
Option 1”). The arrays coils_area, di_area, hr_area, ir_area are data buffers, the
variables coils1, coils2, di1, di2, hr1, hr2, ir1, ir2 are test data elements placed in the
specified buffers.
The second strategy is to link the channel with the structure (data type STRUCT).
When you declare a structure in the development environment, you need to specify in
it all the fields that are intended to be issued via Modbus, then create a channel and
associate it with a variable — an instance of this structure.
Add a Modbus TCP Master device to the controller (Regul → Modbus → TCP Modbus
Master Modbus TCP Master). Using a double click on the name of the Modbus TCP
Master device open the parameters tab (Figure 20).
The general parameters of the device include the parameters, which usually do not
need to be changed:
• Socket Timeout – it is a timeout in milliseconds for a select operation ();
• Reconnect interval – if there is no TCP connection, after this time interval
expires (in milliseconds), an attempt will be made to re-establish the TCP
connection.
Next, one or several outer slaves (outer slaves) that will be polled by the controller
(Regul → Modbus → TCP Modbus Master → Modbus TCP Outer Slave) need to be
connected to the Modbus TCP Master device. Double-click the Modbus TCP Outer
Slave device name to open the parameters tab. By default, the first inner tab of the
modbus Tcp outer Slave Setup opens (Figure 21. Configuring parameters for Modbus
TCP Outer Slave
).
Selecting the check box in the Debug mode field enables debug mode (additional
information about the operation will be recorded in the controller log).
Set the following parameters:
• Unit ID – this is the address of the polled device. It may be required for some
specific devices that require explicit indication of the Modbus Slave address;
• Timeout – waiting time for a response to a request. The default is 1000 ms.
• IP Address – address of the slave device
• Port – TCP port number opened on the slave to connect
• Behavior in STOP mode – behavior in STOP mode. Indicates what to do if the
RUN | STOP switch of the controller is set to the STOP position — No activity
option means stop polling, Normal work means continuing normal operation
(Modbus operation cycle does not depend on Run | Stop of controller), Close
Connection means that the connection will be closed.
Note: it is possible to independently activate "behavior in STOP mode" in the program code. To activate the
mode, in the program, the corresponding ActivbusStopBehavior property of the corresponding Modbus TCP
Master function block of the same name is set to TRUE:
Modbus_Tcp_Master.ActivateStopBehavior:=TRUE;
After that, all slaves connected to this master will switch to STOP mode.
Next, you need to describe the data that the controller will request from the slave
devices. This procedure and further settings are completely analogous to those
described in the Configuring Modbus Serial Master section.
Selecting the check box in the Debug mode field enables debug mode (additional
information about the operation will be recorded in the controller log).
Set the following parameters:
• TCP Port – port number listened by the Modbus driver
• Behavior in STOP mode – behavior in STOP mode. It indicates what to do
when switch RUN|STOP of the PLC is moved into the STOP position. No activity
means to stop polling, Normal work means continuing of the operation (cycle
of Modbus does not depend on the Run|Stop of the controller), Close
Connection means that the connection will be closed and all attempts for a TCP
connection will be denied. Selection of Modbus Exception means that for any
request to Modbus the reply will contain error code 06 (Device busy).
Note: it is possible to independently activate "behavior in STOP mode" in the program code. To activate the
mode, it is required in the program to assign the value TRUE to the ActivateStopBehavior property of the
Modbus TCP Slave device instance:
Modbus_TCP_Slave_Device.ActivateStopBehavior:=TRUE;
The settings of the Modbus Slave data areas and the methods of working with them
are completely identical to those described in the section Configuring Modbus
Serial Slave.
GP Systems GmbH
Ochshäuser Str., 45
34123 Kassel Germany