0% found this document useful (0 votes)
520 views

CP-series Function Block Practices Guide

The document provides an overview and examples of using function blocks with the Modbus RTU Master function block in Omron's CP-series PLCs. Specifically: 1. It describes the Modbus RTU Master function block which sends Modbus RTU commands through a serial port and allows sending multiple commands sequentially without programming. 2. It lists the available function blocks for different Modbus command codes and serial ports. 3. It provides examples of the function blocks for reading coils and reading holding registers, showing the input and output parameters.

Uploaded by

bambang pramono
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
520 views

CP-series Function Block Practices Guide

The document provides an overview and examples of using function blocks with the Modbus RTU Master function block in Omron's CP-series PLCs. Specifically: 1. It describes the Modbus RTU Master function block which sends Modbus RTU commands through a serial port and allows sending multiple commands sequentially without programming. 2. It lists the available function blocks for different Modbus command codes and serial ports. 3. It provides examples of the function blocks for reading coils and reading holding registers, showing the input and output parameters.

Uploaded by

bambang pramono
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

CP-series Function Block

Practices Guide

Modbus RTU Master

1
About Intellectual Property Right and Trademarks
Microsoft product screen shots reprinted with permission from Microsoft Corporation.
Windows is a registered trademark of Microsoft Corporation in the USA and other countries.
Company names and product names in this guide are the trademarks or registered trademarks
of their respective companies.

2
■ Introduction
This guide describes examples of using function blocks.
Omron does NOT warrant that the function blocks work properly at all times in actual programs and
machines. Please obtain the user’s manuals of the used devices and be sure to understand the important
precautions and reminders described on the manuals before attempting to start operation.

■ Intended Audience
This guide is intended for the following personnel, who must also have knowledge of electrical systems (an
electrical engineer or the equivalent).
• Personnel in charge of installing FA systems
• Personnel in charge of designing FA systems
• Personnel in charge of managing FA systems and facilities

■ Related Manuals
Cat. No. Model Manual name
W613 CP2E-E□□D□-□ CP Series CP2E CPU Unit Hardware User’s Manual
(CP2E) CP2E-S□□D□-□
CP2E-N□□D□-□
W614 CP2E-E□□D□-□ CP Series CP2E CPU Unit Software User’s Manual
(CP2E) CP2E-S□□D□-□
CP2E-N□□D□-□
W483 CP1E-E□□D□-□ CP Series CP1E/CP2E CPU Unit
(CP1E/CP2E) CP1E-N□□D□-□ Instructions Reference Manual
CP2E-E□□D□-□
CP2E-S□□D□-□
CP2E-N□□D□-□
W446 CXONE-AL□□D-V4 CX-Programmer Ver.9.□
Operation Manual

3
Practices Guide

4
1. Modbus RTU Master Function Block
The Modbus RTU Master Function Block sends the Modbus RTU commands using the serial port.

1.1 Overview of Function Blocks


Modbus RTU is a widely used serial communication protocol to exchange data between the CP2E CPU Unit
and devices. An application example is velocity control for packing machines where RS-485 serial
communication is used to set and monitor inverters directly from the CP2E CPU Unit.

NB Series CP2E-N/CP2E-S

Inverter RUN/stop,
frequency
setting/monitoring,
etc. Modbus RTU slave
(e.g., inverter)

This function block sends and receives up to 32 Modbus RTU commands through a port automatically and
sequentially when the boot flags are turned ON after addresses and data are set.

Frequency monitor
1 (Node 1)
ON Sends and receives commands sequentially
2 Frequency monitor
(Node 2) 1 2 3
ON

3 Frequency monitor
(Node 3)
ON

Node 1 Node 2 Node 3


Frequency setting
ON (Node 3) Modbus RTU slave (e.g., inverter)

Up to 32

When the boot flags are turned ON simultaneously, Modbus RTU commands are sent and received sequentially.

<Previously>
Commands and data were set in the DM allocation area for the Modbus-RTU Easy Master function of the
CP2E CPU Unit to send and receive Modbus RTU commands through the serial port. The user had to create
sequence programs to send and receive multiple commands sequentially because the CP2E CPU Unit could
send or receive only one command per port.

5
1.2 Function Blocks to Use
The Modbus RTU Master Function Blocks send the Modbus RTU commands via the serial port. A function
block for each command and each serial port are available. For details on the function blocks, refer to
Description of Functions.

Function blocks
Function Command Function Serial port Function block name
code name
01 Hex Read Read multiple Port 1/built-in RS-232C _CP2E030_SendModRTU_F01_P1
Coils coils Port 2/built-in RS-485 _CP2E030_SendModRTU_F01_P2
Port 1 (EX) _CP2E030_SendModRTU_F01_P1EX
03 Hex Read Read multiple Port 1/built-in RS-232C _CP2E030_SendModRTU_F03_P1
Holding holding Port 2/built-in RS-485 _CP2E030_SendModRTU_F03_P2
Registers registers Port 1 (EX) _CP2E030_SendModRTU_F03_P1EX
05 Hex Write Write a single Port 1/built-in RS-232C _CP2E030_SendModRTU_F05_P1
Single Coil coil Port 2/built-in RS-485 _CP2E030_SendModRTU_F05_P2
Port 1 (EX) _CP2E030_SendModRTU_F05_P1EX
06 Hex Read Write a single Port 1/built-in RS-232C _CP2E030_SendModRTU_F06_P1
Single holding Port 2/built-in RS-485 _CP2E030_SendModRTU_F06_P2
Register register Port 1 (EX) _CP2E030_SendModRTU_F06_P1EX
10 Hex Write Write multiple Port 1/built-in RS-232C _CP2E030_SendModRTU_F10_P1
Multiple holding Port 2/built-in RS-485 _CP2E030_SendModRTU_F10_P2
Registers registers Port 1 (EX) _CP2E030_SendModRTU_F10_P1EX
Serial port name
CP2E-E type CP2E-S type

Built-in RS-232C Built-in RS-232C Built-in RS-485

(Port 1) (Port 1) (Port 2)


CP2E-N14/20 CP2E-N30/40/60

Serial Port 1 Serial Port 1 Serial Port 2


(Serial option board mounted) (Serial option board mounted) (Serial option board mounted)
CP1W-CIF01/CIF11/CIF12-V1 CP1W-CIF01/CIF11/CIF12-V1 CP1W-CIF01/CIF11/CIF12-V1
CP2W-CIFD□ CP2W-CIFD□
Serial Port 1 (EX) Serial Port 1 (EX)
(Serial option board with 2 ports mounted) (Serial option board with 2 ports mounted)
CP2W-CIFD□ CP2W-CIFD□

6
■ Function01: Read Coils (_CP2E030_SendModRTU_F01_P□)

P_On
_CP2E030_SendModRTU_F01_P□
(BOOL) (BOOL)
EN ENO
(BOOL) (BOOL) FB busy flag
Boot flag Execute 起動トリガ
FB_BUSY
(UINT) (BOOL) FB normal end
Modbus slave address SlaveAddr Modbus スレーブアドレス FB_OK
(UINT) (BOOL)
Coil starting address コイル開始アドレス FB error end
ReadCoilAddr FB_NG
(UINT) (WORD)
Quantity of coils コイル数 Modbus error code
ReadCoilSize ErrorCode
(WORD)
Area of read data RecvAreaID 読出データ格納 CH 種別
(UINT)
Word of read data RecvAreaNo 読出データ格納 CH 番号

■ Function03: Read Holding Registers (_CP2E030_SendModRTU_F03_P□)

P_On
_CP2E030_SendModRTU_F03_P□
(BOOL) (BOOL)
EN ENO
(BOOL) (BOOL) FB busy flag
Boot flag Execute 起動トリガ
FB_BUSY
(UINT) (BOOL) FB normal end
Modbus slave address SlaveAddr Modbus スレーブアドレス FB_OK
(UINT) (BOOL)
FB error end
Register starting address ReadRegAddr レジスタ開始アドレス FB_NG
(UINT) (WORD)
Quantity of register レジスタ数 Modbus error code
ReadRegSize ErrorCode
(WORD)
Area of read data RecvAreaID 読出データ格納 CH 種別
(UINT)
First word of read data 読出データ格納先頭 CH 番号
RecvAreaNo

■ Function05: Write Single Coil (_CP2E030_SendModRTU_F05_P□)


P_On
_CP2E030_SendModRTU_F05_P□
(BOOL) (BOOL)
EN ENO
(BOOL) (BOOL)
Boot flag FB busy flag
Execute FB_BUSY
(UINT) (BOOL)
Modbus slave address FB normal end
SlaveAddr FB_OK
(UINT) (BOOL)
Output coil address WriteCoilAddr FB_NG FB error end
(WORD) (WORD)
Output value OutputValue ErrorCode Modbus error code

■ Function06: Write Single Register (_CP2E030_SendModRTU_F06_P□)


P_On
_CP2E030_SendModRTU_F06_P□
(BOOL) (BOOL)
EN ENO
(BOOL) (BOOL)
Boot flag FB busy flag
Execute FB_BUSY
(UINT) (BOOL)
Modbus slave address SlaveAddr FB_OK FB normal end
(UINT) (BOOL)
Register address ReadRegAddr FB_NG FB error end
(WORD) (WORD)
Area of write data SendAreaID ErrorCode Modbus error code
(UINT)
Word of Write data SendAreaNo

7
■ Function10: Write Multiple Registers (_CP2E030_SendModRTU_F10_P□)

P_On
_CP2E030_SendModRTU_F10_P□
(BOOL) (BOOL)
EN ENO
(BOOL) (BOOL)
Boot flag FB busy flag
Execute FB_BUSY
(UINT) (BOOL)
Modbus slave address FB normal end
SlaveAddr FB_OK
(UINT) (BOOL)
Register starting address WriteRegAddr FB_NG FB error end
(UINT) (WORD)
Quantity of register WriteRegSize ErrorCode Modbus error code
(WORD)
Area of write data SendAreaID
(UINT)
First word at erite data SendAreaNo

Precautions for Correct Use of Function Blocks


• These function blocks use the Modbus RTU Easy Master function. Do not use the Modbus RTU Easy
Master function for the serial port used for the function blocks.
• Do not use the Work Area for the program.
Work Area for function blocks (area used for Modbus RTU Master Function Blocks)
Socket No. DM Area AR Area Work Area
Built-in RS-232C D1200 to D1299 A640.00 to 02 W127,
Serial Port 1 D3850 to D3885
Built-in RS-485 D1300 to D1399 A641.00 to 02 W127,
Serial Port 2 D3900 to D3935
Serial Port 1 (EX) D1400 to D1499 A638.00 to 02 W127,
D3950 to D3985
• Do not turn ON EN and Boot flag (Execute) at the same time. If EN and Execute are turned ON at the
same time, the command will not be sent.

2. Operating Procedure
Exchange data with an inverter using Modbus RTU via the serial port of the CP2E CPU Unit.

Wiring Connect the CP2E CPU Unit and an RTU slave using
a communication cable.

Make built-in RS-232C port, built-in RS-485 port, or serial


PLC Settings
port settings at PLC Settings in the CX-Programmer and
transfer the settings to the CP2E CPU Unit.

Insert the function blocks to send or receive data to


Ladder programming
create programs.

8
3. Programming Examples
The CP2E-S CPU Unit controls the 3G3MX2-V1 Inverter connected to the RS-485 port.
While always monitoring the frequency of the inverter, the CP2E-S CPU Unit changes the frequency and
operates and stops the inverter.
Modbus-RTU master
CP2E-S□□-type CPU Unit

3G3MX2-V1 Inverter
Built-in RS-485 port Slave address: 3
Output Frequency Reference Output Frequency Monitor
RUN Command

Output frequency reference value 60.00 Hz


W1.00: ON

RUN Command (W0.00)

Output Frequency Monitor Always monitoring while W2.00 is ON.

The following operations are performed:


1. When W1.00 is turned ON, the frequency is set to 60.00 Hz.
2. When W0.00 is turned ON, operation starts. When W0.00 is turned OFF, operation stops.
3. The frequency is always monitored while W2.00 is ON.
* The inverter operates according to the acceleration/deceleration and direction settings on the inverter

The following function blocks are used:


Setting CP2E Function block 3G3MX2-V1 Parameter
Output Frequency _CP2E030_Send Write Single Output Frequency Modbus register
Reference Setting ModRTU_F06_P2 Register Setting Parameter spec. No.: 0001 Hex
No. F001(LOW) (Register No.: 0002Hex-1)
RUN Command _CP2E030_Send Write Single RUN Command Modbus coil
ModRTU_F05_P2 Coil 0: Stop, 1: RUN spec. No. 0000 Hex
(coil No.0001Hex-1)
Output Frequency _CP2E030_Send Read Output Frequency Modbus register
Monitor ModRTU_F03_P2 Holding Monitor Parameter spec. No.: 1001 Hex
Registers No. d001(LOW) (Register No.: 1002Hex-1)

9
The following I/O memory is used:
I/O memory Description Set value Remarks
D100 Value of Output Frequency Reference Setting &6000
D110 Value of Output Frequency Monitor -

3.1 Wiring Example


Connect the 3G3MX2-V1 Inverter to the CP2E-S CPU Unit.

CP2E-S CPU Unit 3G3MX2-V1 Inverter


Built-in RS-485 3G3MX2-V1
port Control circuit terminal block
A- RS-
B+ RS+
FG

Turn ON the DIP switch Turn ON the terminating


for terminating resistance resistor selector switch
settings

3.2 Setting
■ PLC Settings for CP2E-S CPU Unit
(1) Serial Port Setting
Start the CX-Programmer.
Select the Built-in RS-485 Port Tab in the PLC Settings.
Set the Communications Settings Field and Response Timeout Field.

Setting example
Item Description
Communications Select the Custom Option and set the baud rate to 115200 and the format to 8,1,E.
Settings * Use the same settings as the connected inverter.
Mode Select Modbus-RTU simple master.
Response Timeout Set the default value of 0 (default 5000 ms).

10
(2) Communications Setting
Select the Startup/CPU Settings Tab in the PLC Settings.
Set the retry counts to 2 in the Comms Instructions Settings in FB Field.

■ Setting 3G3MX2-V1
Set the Modbus communication parameters according to the settings of the CP2E CPU Unit.
Parameter No. Function name Data Default data Set value
A001/A201 1st/2nd Frequency 03: Modbus communication 02 03
Reference Selection
A002/A202 1st/2nd RUN Command 03: Modbus communication 02 03
Selection
C071 Communication Speed 03: 2400 bps 05 10
Selection 04: 4800 bps 115.2 kbps
05: 9600 bps
06: 19.3 kbps
07: 38.4 kbps
08: 57.6 kbps
09: 76.8 kbps
10: 115.2 kbps
C072 Communication Station No. 1 to 247 1 3
Selection
(Modbus slave address)
C074 Communication Parity 00: No parity 00 01
Selection 01: Even parity Even parity
02: Odd parity
C075 Communication Stop Bit 1: 1 bit 1 1
Selection 2: 2 bits 1 bit

11
Parameter No. Function name Data Default data Set value
C076 Operation Selection on 00: Trip 02 02
Communication Error 01: Trip after deceleration stop Ignore
02: Ignore
03: Free-run stop
04: Deceleration stop
C077 Communication Error 0.00: Timeout disabled 0.00 0.00
Timeout Time 0.01 to 99.99 Disabled
C078 Communication Wait Time 0 to 1000 0 ms 0 ms
* Refer to the MX2 Series Type V1 User’s Manual (Cat. No. I585) for settings.

3.3 Ladder Programming Examples


(1) Inserting the Function Blocks
Save the function block files to use to your PC beforehand.
Right-click Function Blocks at the project workspace in the CX-Programmer and select Insert Function
Blocks - From File from the pop-up menu to load the CP2E030_SendModRtu_F03_P2.cxf file, the
CP2E030_SendModRtu_F05_P2.cxf file, and the _CP2E030_SendModRtu_F06_P2.cxf file.

12
(2) Ladder Programming for Frequency Reference Setting
Create a program to send the output frequency reference to the 3G3MX2-V1 Inverter when W1.00 is turned
ON.

Create Boot flag (W1.05) of the function


block.
W1.05 turns ON when W1.00 turns ON,
and W1.05 turns OFF when sending is
completed (FB_OK turns ON)

Boot flag

Modbus slave address: 3

Register address: 0001 Hex

Area and word to store


output frequency value
to set: D100

The error code is stored in D120 if


FB_NG is turned ON

・ When frequency reference bit (W1.00) is turned ON, Boot flag (W1.05) is turned ON and the function block
sends a command to write the value in output frequency (D100) to the Modbus register 0001 Hex in the
inverter with the slave address 3.
(When output frequency is 60.00 HZ, set D100 to &6000.)
・ FB_BUSY (W1.01) is ON during waiting for sending or during sending.
・ When sending is completed, FB_OK (W1.02) is turned ON and Boot flag (W1.05) is turned OFF.

13
(3) Ladder Programming for Starting and Stopping Operation
Create a program to start operation when W0.00 is turned ON and to stop operation when W0.00 is turned
OFF.

Create Boot flag (W0.05) of the


function block.
W0.05 turns ON when W0.00 turns ON,
and W0.05 turns OFF when sending is
completed (FB_OK turns ON)

Boot flag

Modbus slave address: 3

Output coil address: 0000 Hex

Output value 1: #FF00

The error code is stored in


D121 if FB_NG is turned ON

Create Boot flag (W0.12) of the function


block.
W0.12 turns ON when W0.00 turns OFF,
and W0.12 turns OFF when sending is
completed (FB_OK turns ON)

Boot flag

Modbus slave address: 3

Output coil address: 0000 Hex

Output value 0: #0000

The error code is stored in


D122 if FB_NG is turned ON

・ When RUN start bit (W0.00) is turned ON, Boot flag (W0.05) is turned ON and the function block sends a
command to write #FF00 (1: RUN) to the Modbus coil 0000 Hex in the inverter with the slave address 3.

14
・ When RUN start bit (W0.00) is turned OFF, Boot flag (W0.12) is turned ON and the function block sends a
command to write #0000 (0: Stop) to the Modbus coil 0000 Hex in the inverter with the slave address 3.
・ Give each FB instance a different name.
・ The error code is stored in D121,D122 if the function block ends in an error.

(4) Ladder Programming for Output Frequency Monitor


Create a program to monitor the output frequency while W2.00 is ON.

Boot flag

Modbus slave address: 3

Register starting address: 1001 Hex

Quantity of registers: 1

Area and word to store read


output frequency: D110

The error code is stored in


D123 if FB_NG is turned ON

・ When Boot flag (W2.00) is turned ON, the function block reads data from the Modbus register 1001 Hex in
the inverter with the slave address 3 and write the data to D110. (When the output frequency is 60.00 Hz,
&6000 is written.)
・ When Boot flag (W2.00) is turned ON, reading stops.
・ The error code is stored in D123 if the function block ends in an error.

15
Reference: difference allocation Modbus-RTU Easy Master Function and Function Block
■ Memory allocation of Modbus-RTU Easy Master function
15 07 00
D1300 - - Slave address A641.00 Execution Bit
D1301 - - Function code A641.01 Execution Normal Flag
D1302 No. of communications data bytes A641.02 Execution Error Flag
D1303
.
Communications data
. (Coil address, register
.
address, data, etc.)

■ Example of Modbus RTU Master Function Block

P_On
_CP2E030_SendModRTU_F10_P□
(BOOL) (BOOL)
EN ENO
(BOOL) (BOOL) FB busy flag
Boot flag Execute FB_BUSY
(UINT) (BOOL) FB normal end
Modbus slave address SlaveAddr FB_OK
(UINT) (BOOL)
Register starting address FB error end
WriteRegAddr FB_NG
(UINT) (WORD)
Quantity of registers Modbus error code
WriteRegSize ErrorCode
(WORD)
Area of write data SendAreaID
(UINT)
First word at write data SendAreaNo

・ Select a function block according to Function code.


・ The unit of Number of communications data bytes of the Modbus RTU Easy Master function is byte.
Number of communications data bytes corresponds to Quantity of registers whose unit is word in the
function block.
・ Set the register (starting)/ coil address and word to write data in Communications data of the Modbus RTU
Easy Master function in Register address and Area of write/ receive data and First word at write / receive
data in the function block respectively.
・ Instead of Execution Normal Flag and Execution Error Flag, FB normal end and FB error end in the
function block turn ON for one cycle.
・ Function block Boot flag need to keep ON until FB normal end.

16
■ Practices Guide - Revision History
Revision code Date Revised content
A November 2019 Original production

17
Description of Functions

18
CP2E
030 Modbus RTU master: _CP2E030_SendModRTU
Basic Send Modbus RTU command from serial communication port.
function
Symbol ◼Function01: Read Coils
P_On
_CP2E030_SendModRTU_F01_P□
(BOOL) (BOOL)
EN ENO
(BOOL) (BOOL)
Boot flag FB busy flag
Execute FB_BUSY
(UINT) (BOOL)
Modbus slave address FB normal end
SlaveAddr FB_OK
(UINT) (BOOL)
Coil starting address FB error end
ReadCoilAddr FB_NG
(UINT) (WORD)
Quantity of coils Modbus error code
ReadCoilSize ErrorCode
(WORD)
Area of read data
RecvAreaID
(UINT)
Word of read data
RecvAreaNo

◼Function03:Read Holding Registers


P_On
_CP2E030_SendModRTU_F03_P□
(BOOL) (BOOL)
EN ENO
(BOOL) (BOOL)
Boot flag FB busy flag
Execute FB_BUSY
(UINT) (BOOL)
Modbus slave address FB normal end
SlaveAddr FB_OK
(UINT) (BOOL)
Register starting address FB error end
ReadRegAddr FB_NG
(UINT) (WORD)
Quantity of register Modbus error code
ReadRegSize ErrorCode
(WORD)
Area of read data
RecvAreaID
(UINT)
First word of read data
RecvAreaNo

◼Function05:Write Single Coil


P_On
_CP2E030_SendModRTU_F05_P□
(BOOL) (BOOL)
EN ENO
(BOOL) (BOOL)
Boot flag FB busy flag
Execute FB_BUSY
(UINT) (BOOL)
Modbus slave address FB normal end
SlaveAddr FB_OK
(UINT) (BOOL)
Output coil address FB error end
WriteCoilAddr FB_NG
(WORD) (WORD)
Output value Modbus error code
OutputValue ErrorCode

◼Function06:Write Single Register


P_On
_CP2E030_SendModRTU_F06_P□
(BOOL) (BOOL)
EN ENO
(BOOL) (BOOL)
Boot flag FB busy flag
Execute FB_BUSY
(UINT) (BOOL)
Modbus slave address FB normal end
SlaveAddr FB_OK
(UINT) (BOOL)
Register address FB error end
WriteRegAddr FB_NG
(WORD) (WORD)
Area of write data Modbus error code
SendAreaID ErrorCode
(UINT)
Word of Write data
SendAreaNo

19
Symbol ◼Function10:Write Multiple Registers
P_On
_CP2E030_SendModRTU_F10_P□
(BOOL) (BOOL)
EN ENO
(BOOL) (BOOL)
Boot flag FB busy flag
Execute FB_BUSY
(UINT) (BOOL)
Modbus slave address FB normal end
SlaveAddr FB_OK
(UINT) (BOOL)
Register starting address FB error end
WriteRegAddr FB_NG
(UINT) (WORD)
Quantity of register Modbus error code
WriteRegSize ErrorCode
(WORD)
Area of write data
SendAreaID
(UINT)
First word at write data
SendAreaNo

File name ◼Built-in RS-232C port for CP2E-S/E / Serial port1 for CP2E-N
_CP2E030_SendModRtu_F01_P1.cxf : Function 01 (Read Coils)
_CP2E030_SendModRtu_F03_P1.cxf : Function 03 (Read Holding Registers)
_CP2E030_SendModRtu_F05_P1.cxf : Function 05 (Write Single Coil)
_CP2E030_SendModRtu_F06_P1.cxf : Function 06 (Write Single Register)
_CP2E030_SendModRtu_F10_P1.cxf : Function 10 (Write Multiple Registers)

◼Built-in RS-485 for CP2E-S / Serial port2 for CP2E-N


_CP2E030_SendModRtu_F01_P2.cxf : Function 01 (Read Coils)
_CP2E030_SendModRtu_F03_P2.cxf : Function 03 (Read Holding Registers)
_CP2E030_SendModRtu_F05_P2.cxf : Function 05 (Write Single Coil)
_CP2E030_SendModRtu_F06_P2.cxf : Function 06 (Write Single Register)
_CP2E030_SendModRtu_F10_P2.cxf : Function 10 (Write Multiple Registers)

◼Serial port1(EX) for CP2E-N


_CP2E030_SendModRtu_F01_P1EX.cxf : Function 01 (Read Coils)
_CP2E030_SendModRtu_F03_P1EX.cxf : Function 03 (Read Holding Registers)
_CP2E030_SendModRtu_F05_P1EX.cxf : Function 05 (Write Single Coil)
_CP2E030_SendModRtu_F06_P1EX.cxf : Function 06 (Write Single Register)
_CP2E030_SendModRtu_F10_P1EX.cxf : Function 10 (Write Multiple Registers)

Applicable CPU Unit CP2E


models
CX-Programmer Version 9.72 or higher
Conditions ◼Settings
for usage
・ PLC Setup: Comms Instructions Setting in FB
Retry Counts (default: 0)
◼ Shared Resources
・ DM Fixed area and Auxiliary area of Modbus RTU easy master
・ Work Area for Modbus RTU FB
Socket No. Modbus RTU easy master Work area
DM area AR area
Built-in RS232C D1200 to D1299 A640.00 to A640.02 W127
Serial port1 D3850 to D3885
Built-in RS-485 D1300 to D1399 A641.00 to A641.02 W127
Serial port2 D3900 to D3935
Serial port1(EX) D1400 to D1499 A638.00 to A638.02 W127
D3950 to D3985

20
Function ◼Function block operation
description ・ When Boot flag (Execute) is turned ON, send the Modbus RTU command to Modbus RTU slave
specified by Modbus slave address (SlaveAddr).
・ Send processing will be repeated during Boot flag (Execute) is ON.
・ Send processing will be stopped during Boot flag (Execute) is OFF.
・ Read data specified by Coil/Register starting address (ReadCoilAddr/ReadRegAddr) and Quantity of
Coil/Register (ReadCoilSize/ReadRegSize) from Modbus RTU slave when read command is sent.
・ Write data specified by Coil/Register starting address (WriteCoilAddr/WriteRegAddr) and Quantity of
Coil/Register (WriteRegSize) to Modbus RTU slave when write command is sent.
・ The send and receive data word designations are specified using the area of write/read data
(Send/RecvAreaID) and First word of write/read data (SendAreaNo/RecvAreaNo).
For example, for D1000, the area type is set to P_DM and the first word address is set to &1000.
・ If send processing is completed normally, ON is set to FB normal end (FB_OK) and “#0000” is stored in
Modbus error code (ErrorCode).
・ If the send processing produces an error, ON is set to FB error end (FB_NG) and Modbus error code will
be output to the Modbus error code (ErrorCode).

Time chart

EN (P_On) ON
OFF
Send once Send continuously

Boot flag ON
(Execute) OFF

FB busy flag ON
(FB_BUSY) OFF

FB normal end or ON
FB error end OFF
(FB_OK/FB_NG)
•Send processing will be repeated during Boot flag is ON.

FB execution completed
At FB normal end : Read or write operation is completed.

◼Instance operation
・ Serial port can be executed to send only one command. Each instance is executed in the order in which
Boot flag (Execute) is turned ON.
・ The instance that Boot flag (Execute) is OFF is not executed.
If Boot flag is turned OFF before Modbus RTU command is sent, Modbus RTU command is not sent.
Time chart : Three instances (Example)

EN (P_On) ON
OFF Command is not sent if Boot flag is
turned OFF before send command.
Instance 1
ON
Boot flag (Execute) OFF

Send command 1 1 1 1 1 1 1 1 1

Instance 2
ON
Boot flag (Execute) OFF

Send command 2 2 2 2

Instance 3
ON
Boot flag (Execute) OFF

Send command 3 3 3 3 3 3

Each instance is executed in the order Each instance is executed in the order
in which Boot flag is turned ON. in which Boot flag is turned ON.
“1”? ”2”? ”3”? ”1”・・・ “1”? ”3”? ”2”? ”1”・・・

Supported command
Function code コマンド名称 機能
01 Hex Read Coils Read multiple coils
03 Hex Read Holding Registers Read multiple holding registers
05 Hex Write Single Coil Write a single coil
06 Hex Write Single Register Write a single holding register
10 Hex Write Multiple Registers Write multiple holding registers

21
Kind of FB Connect Always ON type
definition Connect the EN input to the Always ON Flag (P_On)
・ The same instance can not be used in two or more places.
FB ・ The FB is processed over multiple cycles. The FB busy flag (FB_BUSY) output variable can be used to
precautions check whether the FB is being processed.
・ It can be set max 32 instances on each serial port.
・ This FB is used Modbus RTU Easy Master function. When using this FB, do not use Modbus RTU Easy
Master function for serial port used this FB.
・ Do not use the work area of shared resource, when this FB is used.
EN input ・ Connect the EN input to the Always ON Flag (P_On).
condition ・ If a different type of bit is connected to EN, the FB outputs will be maintained when the connected bit is
turned OFF.
Restrictions ・ Use the Always ON Flag (P_On) for EN.
Input ・ If Boot flag (Execute) is turned OFF before Modbus RTU command is sent, Modbus RTU command is
variables not sent. Set Boot flag (Execute) to turn OFF after FB normal end (FB_OK) is ON.
・ Do not turn ON EN and Boot flag (Execute) at the same time. If EN and Execute are turned ON at the
same time, linear interpolation will not be executed.
・ If the input variables are out of range, the ENO will turn OFF and the FB will not be processed.
Application Send Modbus RTU command to Modbus RTU slave.
example Sends according to the ON / OFF status of W0.00 to W0.04.

P_On Instance0 Boot flag


(BOOL)
EN W0.00 ON ON ON ON ON
(BOOL) W0.01 ON OFF OFF OFF OFF
W0.00 Execute
W0.02 ON ON ON OFF OFF

W0.03 ON ON OFF ON OFF
W0.04 ON ON OFF ON OFF
P_On Instance1
(BOOL)
EN Send command status
(BOOL) Instance0 Send Send Send Send Send
W0.01 Execute
… Instance1 Send Pending Pending Pending Pending
Instance2 Send Send Send Pending Pending
Instance3 Send Send Pending Send Pending
P_On Instance2 Instance4 Send Send Pending Send Pending
(BOOL)
EN
(BOOL)
W0.02 Execute

P_On Instance3
(BOOL)
EN
(BOOL)
W0.03 Execute

P_On Instance4
(BOOL)
EN
(BOOL)
W0.04 Execute

Related CP2E CPU Unit Software User’s manual (W614)


manuals 14-4 Modbus RTU Easy Master Function

22
◼ Variable Tables
Input Variables

Function01: Read Coils


Name Variable name Data type Default Range Description
EN EN BOOL 1 (ON): FB started.
0 (OFF): FB not started.
Boot flag Execute BOOL 1 (ON): start to send Modbus command
0 (OFF): stop to send Modbus command
Modbus slave SlaveAddr UINT &1 &1 to &31
address
Coil starting ReadCoilAddr UINT &0 &0 to &65535
address
Quantity of coils ReadCoilSize UINT &1 &1 to &16 Read coils : max 16 bit

Area of read data RecvAreaID WORD #00B1 - P_WR (#00B1): Work Area

Word of read data RecvAreaNo UINT &0 &0 to &126 W0 to W126

Function03: Read Holding Registers


Name Variable name Data type Default Range Description
EN EN BOOL 1 (ON): FB started.
0 (OFF): FB not started.
Boot flag Execute BOOL 1 (ON): start to send Modbus command
0 (OFF): stop to send Modbus command
Modbus slave SlaveAddr UINT &1 &1 to &31
address
Register starting ReadRegAddr UINT &0 &0 to &65535
address
Quantity of registers ReadRegSize UINT &1 &1 to &20 Read registers : max 20 word

Area of read data RecvAreaID WORD #0082 - P_DM (#0082): Data Memory Area

First word of read RecvAreaNo UINT &0 &0 to &3849 D0 to D3849


data [First word of read data + Quantity of
registers] will be set below range.
D0- D3849

Function05: Write Single Coil


Name Variable name Data type Default Range Description
EN EN BOOL 1 (ON): FB started.
0 (OFF): FB not started.
Boot flag Execute BOOL 1 (ON): start to send Modbus command
0 (OFF): stop to send Modbus command
Modbus slave SlaveAddr UINT &1 &1 to &31
address
Output Coil address WriteCoilAddr UINT &0 &0 to &65535

Output value Output value WORD #0000 ON: #FF00


OFF: #0000

Function06: Write Single Registers


Name Variable name Data type Default Range Description
EN EN BOOL 1 (ON): FB started.
0 (OFF): FB not started.
Boot flag Execute BOOL 1 (ON): start to send Modbus command
0 (OFF): stop to send Modbus command
Modbus slave SlaveAddr UINT &1 &1 to &31
address
Register address WriteRegAddr UINT &0 &0 to &65535

Area of write data SendAreaID WORD #0082 - P_DM (#0082): Data Memory Area

Word of write data SendAreaNo UINT &0 &0 to &3849 D0 to D3849

23
Function10: Write Multiple Registers
Name Variable name Data type Default Range Description
EN EN BOOL 1 (ON): FB started.
0 (OFF): FB not started.
Boot flag Execute BOOL 1 (ON): start to send Modbus command
0 (OFF): stop to send Modbus command
Modbus slave SlaveAddr UINT &1 &1 to &31
address
Register starting WriteCoilAddr UINT &0 &0 to &65535
address
Quantity of register WriteRegSize UINT &1 &1 to &20 Write registers : max 20 word

Area of write data SendAreaID WORD #0082 - P_DM (#0082): Data Memory Area

First word of write SendAreaNo UINT &0 &0 to &3849 D0 to D3849


data [First word of write data + Quantity of
registers] will be set below range.
D0- D3849

Output Variables
Name Variable name Data type Range Description
ENO ENO BOOL 1 (ON): FB processed normally.
0 (OFF): FB not processed or ended in an error.
FB Busy Flag FB_BUSY BOOL Automatically turns OFF when processing is completed.
FB Normal end FB_OK BOOL Turns ON for one cycle when processing ends normally.
Error end FB_NG BOOL Turns ON for one cycle when processing ends in an
error.
Error code ErrorCode DWORD Outputs the Modbus error code when execution ends in
an error.
When ErrorCode is 0088 Hex, Exception code will be set
to ErrorCode+1.

■Modbus RTU error code


Error code Contents Course
0000 Hex Normal end -
0004 Hex Serial communication mode error The Modbus-RTU Easy Master function was executed when the
serial communications mode was not the Modbus-RTU Easy Master
Mode
0084 Hex CRC error CRC error is occurred
0085 Hex Incorrect response address Response slave address is not match to sending command
0086 Hex Incorrect response function code Response function code is not match to sending command
0087 Hex Response size over Response data size is large
0088 Hex Exception response Exception response from Modbus slave
Exception code will be set to ErrorCode+1.
008F Hex Other error Other error is occurred.
FFFD Hex Instance over Instance is used over 32
FFFF Hex Out of range of variable input Out of range of variable input

24
Detail of Modbus command
◼Function 01 Read Coils: Read to Work Aera (W) from Multiple coils.

Request
Field name Data length Data or Input variable name
Slave address 1 byte SlaveAddr
Function code 1 byte 01 Hex
Coil starting 2 bytes ReadCoilAddr
address 0 to FFFF Hex (&0 to &65535)
Quantity of coils 2 bytes ReadCoilSize
0 to 10 Hex (&0 to &16)

Response
Field name Data length Data or variable input name
Slave address 1 byte Same as SlaveAddr
Function code 1 byte 01 Hex
Byte count 1 byte 1 or 2 Hex
Coil status 1 or 2 bytes Work area (W) specified with Area of read data
(RecvAreaID), Word of read data (RecvAreaNo).
Example: Area of read data: P_WR
Word of read data: &10
Read to W10CH
* : Response data except for Coil status is not confirmed on FB.

Example: Read 10 bit (10 10001010 =28A Hex) to W10 from Coil starting address 4 (0004 Hex) on slave address 2.

Request (CP2E: Modbus master) Response (Modbus slave)


Field name Data Field name Data
Slave address 02 Hex Slave address 02 Hex
Function code 01 Hex Function code 01 Hex
Coil starting address (High) 0004 Hex Byte count 02 Hex
Coil starting address (Low) (from &4) Coil status 4 to 11 8A Hex
Quantity of coils (High) 000A Hex W10.08 to W10.15
Quantity of coils (Low) (10 bit) Coil status 12 to 13 02 Hex
W10.00 to W10.01

P_On
_CP2E030_SendModRTU_F01_P□
(BOOL) (BOOL)
EN ENO
(BOOL) (BOOL)
Boot flag FB busy flag
Execute FB_BUSY
(UINT) (BOOL)
Modbus slave address FB normal end
SlaveAddr FB_OK
&2
(UINT) (BOOL)
Coil starting address FB error end
ReadCoilAddr FB_NG
&4
(UINT) (WORD)
Quantity of coils Modbus error code
ReadCoilSize ErrorCode
&10
(WORD)
Area of read data
RecvAreaID
P_WR
(UINT)
Word of read data
RecvAreaNo
&10

Modbus slave 2
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
(1) (0) (1) (0) (0) (0) (1) (0) (1) (0)
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
* : The subscript numbers in the shaded boxes indicate the coil address and ON/OFF (1/0) status.

Read
CP2E
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
W9CH - - - - - - - - - - - - - - - -
W10CH (1) (0) (0) (0) (1) (0) (1) (0) - - - - - - (1) (0)
W11CH - - - - - - - - - - - - - - - -
* : The subscript numbers in the shaded boxes indicate the ON/OFF (1/0) status.

25
◼Function 03 Read Holding Registers: Read to Data Memory Area (D) from Multiple Holding registers.

Request
Field name Data length Data or Input variable name
Slave address 1 byte SlaveAddr
Function code 1 byte 03 Hex
Register starting 2 bytes ReadRegAddr
address 0 to FFFF Hex (&0 to&65535)
Quantity of register 2 bytes ReadRegSize
1 to 0014 Hex (&1 to&20)

Response
Field name Data length Data or Input variable name
Slave address 1 byte Same as SlaveAddr
Function code 1 byte 01 Hex
Byte count 1 byte 2×N (N:Quantity of register)
Read register data 2×N bytes Data memory area (D) specified with Area of read data
(RecvAreaID), Word of read data (RecvAreaNo).
Example: Area of read data: P_DM
Word of read data: &1000
Read from D1000
* : Response data except for Read register data status is not confirmed on FB.

Example: Read 3 words (AB12, 5678, 9713 Hex) to D1000, D1001 and D1002 from Register starting address 100 (0064 Hex)
on slave address 2.

Request (CP2E: Modbus master) Response (Modbus slave)


Field name Data Field name Data
Slave address 02 Hex Slave address 02 Hex
Function code 03 Hex Function code 03 Hex
Register starting address (High) 0064 Hex Byte count 06 Hex
Register starting address (Low) (from &100) Register value (High) AB12 Hex
Quantity of register (High) 0003 Hex Register value (Low) (D1000)
Quantity of register (Low) (3 words) Register value (High) 5678 Hex
Register value (Low) (D1001)
Register value (High) 9713 Hex
Register value (Low) (D1002)

P_On
_CP2E030_SendModRTU_F01_P□
(BOOL) (BOOL)
EN ENO
(BOOL) (BOOL)
Boot flag FB busy flag
Execute FB_BUSY
(UINT) (BOOL)
Modbus slave address FB normal end
SlaveAddr FB_OK
&2
(UINT) (BOOL)
Coil starting address FB error end
ReadCoilAddr FB_NG
&100
(UINT) (WORD)
Quantity of coils Modbus error code
ReadCoilSize ErrorCode
&3
(WORD)
Area of read data
RecvAreaID
P_DM
(UINT)
Word of read data
RecvAreaNo
&1000

Modbus slave 2
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
100 A B 1 2
101 5 6 7 8
102 9 7 1 3

Read
CP2E
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
D1000 A B 1 2
D1001 5 6 7 8
D1002 9 7 1 3

26
◼Function 05 Write Single Coil: Write Single coil

Request
Field name Data length Data or Input variable name
Slave address 1 byte SlaveAddr
Function code 1 byte 05 Hex
Output Coil address 2 bytes WriteCoilAddr
0 to FFFF Hex (0 to &65535)
Output value 2 bytes ON(1): #FF00
OFF(0): #0000

Response
Field name Data length Data or Input variable name
Slave address 1 byte Same as SlaveAddr
Function code 1 byte 05 Hex
Output Coil address 2 bytes WriteCoilAddr
0 to FFFF Hex (0 to &65535)
Output value 2 bytes ON(1): FF00 Hex
OFF(0): 0000 Hex
* : Response data except for Coil status is not confirmed on FB.

Example: Set coil of output Coil address 10 on slave address 2.

Request (CP2E: Modbus master) Response (Modbus slave)


Field name Data Field name Data
Slave address 02 Hex Slave address 02 Hex
Function code 05 Hex Function code 05 Hex
Output coil address (High) 000A Hex Output coil address (High) 000A Hex
Output coil address (Low) (&10) Output coil address (Low) (&10)
Output value FF00 Hex Output value FF00 Hex
(ON) (ON)

P_On
_CP2E030_SendModRTU_F05_P□
(BOOL) (BOOL)
EN ENO
(BOOL) (BOOL)
Boot flag FB busy flag
Execute FB_BUSY
(UINT) (BOOL)
Modbus slave address FB normal end
SlaveAddr FB_OK
&2
(UINT) (BOOL)
Output coil address FB error end
WriteCoilAddr FB_NG
&10
(WORD) (WORD)
Output value Modbus error code
OutputValue ErrorCode
#FF00

CP2E
Output Coil address: &10, Write data: FF00 Hex (ON)

Write
Modbus slave 2
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
0→1

27
◼Function 06 Write Single Register: Write to single holding register from Data Memory Area (D)

Request
Field name Data length Data or Input variable name
Slave address 1 byte SlaveAddr
Function code 1 byte 06 Hex
Register address 2 bytes WriteRegAddr
0~FFFF Hex (0~&65535)
Register value 2 bytes Data memory area (D) specified with Area of read data
(RecvAreaID), Word of read data (RecvAreaNo).
Example: Area of read data: P_DM
Word of read data: &500
Write to D500

レスポンス
Field name Data length Data or Input variable name
Slave address 1 byte Same as SlaveAddr
Function code 1 byte 06 Hex
Register address 2 bytes Same as WriteRegAddr
0 to FFFF Hex (0 to &65535)
Register value 2 bytes 0000 to FFFF Hex

* : Response data except for Read register data status is not confirmed on FB.

Example: Write 1 word (3AC5 Hex) to D500 from Register address 200 on slave address 2.

Request (CP2E: Modbus master) Response (Modbus slave)


Field name Data Field name Data
Slave address 02 Hex Slave address 02 Hex
Function code 06 Hex Function code 06 Hex
Register address (High) 00C8 Hex Register address (High) 00C8 Hex
Register address (Low) (200) Register address (Low) (200)
Quantity of register (High) 3AC5 Hex Quantity of register (High) 3AC5 Hex
Quantity of register (Low) (D500) Quantity of register (Low)

P_On
_CP2E030_SendModRTU_F06_P□
(BOOL) (BOOL)
EN ENO
(BOOL) (BOOL)
Boot flag FB busy flag
Execute FB_BUSY
(UINT) (BOOL)
Modbus slave address FB normal end
SlaveAddr FB_OK
&2
(UINT) (BOOL)
Register address FB error end
WriteRegAddr FB_NG
&200
(WORD) (WORD)
Area of write data Modbus error code
SendAreaID ErrorCode
P_DM
(UINT)
Word of Write data
SendAreaNo
&500

CP2E
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
D500 3 A C 5
D501

Write
Modbus slave 2
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
200 3 A C 5
201

28
◼Function 10 Write Multiple Registers: Write to multiple holding registers from Data Memory Area (D)

Request
Field name Data length Data or Input variable name
Slave address 1 byte SlaveAddr
Function code 1 byte 10 Hex
Register starting 2 bytes WriteRegAddr
address 0 to FFFF Hex (0 to &65535)
Quantity of register 2 bytes WriteRegSize
0 to 0014 Hex (0 to &20)
Byte count 1 byte 2×N (N:Quantity of register)
Registers value 2×Byte count bytes Data memory area (D) specified with Area of read data
(RecvAreaID), Word of read data (RecvAreaNo).
Example: Area of read data: P_DM
Word of read data: &2000
Read from D1000

Response
Field name Data length Data or Input variable name
Slave address 1 byte SlaveAddr
Function code 1 byte 10 Hex
Register starting 2 bytes Same as WriteRegAddr
address
Quantity of register 2 bytes Same as WriteRegSize
* : Response data except for Read register data status is not confirmed on FB.

Example: Write 2 words of Register starting address 10 (000A Hex) from D2000,D2002 (0100, 3A98 Hex) on slave address 2.

Request (CP2E: Modbus master) Response (Modbus slave)


Field name Data Field name Data
Slave address 02 Hex Slave address 02 Hex
Function code 10 Hex Function code 10 Hex
Register starting address (High) 000A Hex Register starting address (High) 000A Hex
Register starting address (Low) (from 10) Register starting address (Low)
Quantity of register (High) 02 Hex Quantity of register (High) 02 Hex
Quantity of register (Low) (2 words) Quantity of register (Low) (2 words)
Byte count 04 Hex
Register value1 (High) 0100 Hex
Register value1 (Low) (D2000)
Register value2 (High) 3A98 Hex
Register value2 (Low) (D2001)

P_On
_CP2E030_SendModRTU_F10_P□
(BOOL) (BOOL)
EN ENO
(BOOL) (BOOL)
Boot flag FB busy flag
Execute FB_BUSY
(UINT) (BOOL)
Modbus slave address FB normal end
SlaveAddr FB_OK
&2
(UINT) (BOOL)
Register starting address FB error end
WriteRegAddr FB_NG
&10
(UINT) (WORD)
Quantity of register Modbus error code
WriteRegSize ErrorCode
&2
(WORD)
Area of write data
SendAreaID
P_DM
(UINT)
First word at write data
SendAreaNo
&2000

CP2E
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
D2000 0 1 0 0
D2001 0 0 5 4

Write
Modbus slave2
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
10 0 1 0 0
11 0 0 5 4

29
◼ Version History
Version Date Contents
001 2019.11 New

Note
This manual is a reference that explains the function block functions.
It does not explain the operational limitations of Units, components, or combinations of Units and components. Always read
and understand the Operation Manuals for the system’s Units and other components before using them.

30

You might also like