Prévia do material em texto
1 Modbus RTU Master CP-series Function Block Practices Guide 2 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. 3 ■ 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) CP2E-E□□D□-□ CP2E-S□□D□-□ CP2E-N□□D□-□ CP Series CP2E CPU Unit Hardware User’s Manual W614 (CP2E) CP2E-E□□D□-□ CP2E-S□□D□-□ CP2E-N□□D□-□ CP Series CP2E CPU Unit Software User’s Manual W483 (CP1E/CP2E) CP1E-E□□D□-□ CP1E-N□□D□-□ CP2E-E□□D□-□ CP2E-S□□D□-□ CP2E-N□□D□-□ CP Series CP1E/CP2E CPU Unit Instructions Reference Manual W446 CXONE-AL□□D-V4 CX-Programmer Ver.9.□ Operation Manual 4 Practices Guide 5 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. 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. <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. CP2E-N/CP2E-S NB Series Inverter RUN/stop, frequency setting/monitoring, etc. Modbus RTU slave (e.g., inverter) Modbus RTU slave (e.g., inverter) Node 1 Node 2 Node 3 When the boot flags are turned ON simultaneously, Modbus RTU commands are sent and received sequentially. Frequency monitor (Node 1) Frequency monitor (Node 2) Frequency monitor (Node 3) ON ON ON Up to 32 Frequency setting (Node 3) ON Sends and receives commands sequentially 1 2 3 1 2 3 6 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 code Command name Function Serial port Function block name 01 Hex Read Coils Read multiple coils Port 1/built-in RS-232C _CP2E030_SendModRTU_F01_P1 Port 2/built-in RS-485 _CP2E030_SendModRTU_F01_P2 Port 1 (EX) _CP2E030_SendModRTU_F01_P1EX 03 Hex Read Holding Registers Read multiple holding registers Port 1/built-in RS-232C _CP2E030_SendModRTU_F03_P1 Port 2/built-in RS-485 _CP2E030_SendModRTU_F03_P2 Port 1 (EX) _CP2E030_SendModRTU_F03_P1EX 05 Hex Write Single Coil Write a single coil Port 1/built-in RS-232C _CP2E030_SendModRTU_F05_P1 Port 2/built-in RS-485 _CP2E030_SendModRTU_F05_P2 Port 1 (EX) _CP2E030_SendModRTU_F05_P1EX 06 Hex Read Single Register Write a single holding register Port 1/built-in RS-232C _CP2E030_SendModRTU_F06_P1 Port 2/built-in RS-485 _CP2E030_SendModRTU_F06_P2 Port 1 (EX) _CP2E030_SendModRTU_F06_P1EX 10 Hex Write Multiple Registers Write multiple holding registers Port 1/built-in RS-232C _CP2E030_SendModRTU_F10_P1 Port 2/built-in RS-485 _CP2E030_SendModRTU_F10_P2 Port 1 (EX) _CP2E030_SendModRTU_F10_P1EX Serial port name CP2E-E type CP2E-S type CP2E-N14/20 CP2E-N30/40/60 Built-in RS-232C (Port 1) Built-in RS-232C (Port 1) Built-in RS-485 (Port 2) Serial Port 2 (Serial option board mounted) CP1W-CIF01/CIF11/CIF12-V1 Serial Port 1 (Serial option board mounted) CP1W-CIF01/CIF11/CIF12-V1 CP2W-CIFD□ Serial Port 1 (EX) (Serial option board with 2 ports mounted) CP2W-CIFD□ Serial Port 1 (Serial option board mounted) CP1W-CIF01/CIF11/CIF12-V1 CP2W-CIFD□ Serial Port 1 (EX) (Serial option board with 2 ports mounted) CP2W-CIFD□ 7 ■ Function01: Read Coils (_CP2E030_SendModRTU_F01_P□) FB busy flag FB normal end FB error end Modbus error code P_On Boot flag 起動トリガ Modbus slave address Modbus スレーブアドレス Coil starting address コイル開始アドレス Quantity of coils コイル数 Area of read data 読出データ格納 CH種別 Word of read data 読出データ格納 CH番号 _CP2E030_SendModRTU_F01_P□ (BOOL) EN (BOOL) ENO (BOOL) Execute (BOOL) FB_BUSY (UINT) SlaveAddr (BOOL) FB_OK (UINT) ReadCoilAddr (BOOL) FB_NG (UINT) ReadCoilSize (WORD) ErrorCode (WORD) RecvAreaID (UINT) RecvAreaNo ■ Function03: Read Holding Registers (_CP2E030_SendModRTU_F03_P□) FB busy flag FB normal end FB error end Modbus error code P_On Boot flag 起動トリガ Modbus slave address Modbus スレーブアドレス Register starting address レジスタ開始アドレス Quantity of register レジスタ数 Area of read data 読出データ格納 CH種別 First word of read data 読出データ格納先頭 CH番号 _CP2E030_SendModRTU_F03_P□ (BOOL) EN (BOOL) ENO (BOOL) Execute (BOOL) FB_BUSY (UINT) SlaveAddr (BOOL) FB_OK (UINT) ReadRegAddr (BOOL) FB_NG (UINT) ReadRegSize (WORD) ErrorCode (WORD) RecvAreaID (UINT) RecvAreaNo ■ Function05: Write Single Coil (_CP2E030_SendModRTU_F05_P□) FB busy flag FB normal end FB error end Modbus error code P_On Boot flag Modbus slave address Output coil address Output value _CP2E030_SendModRTU_F05_P□ (BOOL) EN (BOOL) ENO (BOOL) Execute (BOOL) FB_BUSY (UINT) SlaveAddr (BOOL) FB_OK (UINT) WriteCoilAddr (BOOL) FB_NG (WORD) OutputValue (WORD) ErrorCode ■ Function06: Write Single Register (_CP2E030_SendModRTU_F06_P□) FB busy flag FB normal end FB error end Modbus error code P_On Boot flag Modbus slave address Register address Area of write data Word of Write data _CP2E030_SendModRTU_F06_P□ (BOOL) EN (BOOL) ENO (BOOL) Execute (BOOL) FB_BUSY (UINT) SlaveAddr (BOOL) FB_OK (UINT) ReadRegAddr (BOOL) FB_NG (WORD) SendAreaID (WORD) ErrorCode (UINT) SendAreaNo 8 ■ Function10: Write Multiple Registers (_CP2E030_SendModRTU_F10_P□) FB busy flag FB normalend FB error end Modbus error code P_On Boot flag Modbus slave address Register starting address Quantity of register Area of write data First word at erite data _CP2E030_SendModRTU_F10_P□ (BOOL) EN (BOOL) ENO (BOOL) Execute (BOOL) FB_BUSY (UINT) SlaveAddr (BOOL) FB_OK (UINT) WriteRegAddr (BOOL) FB_NG (UINT) WriteRegSize (WORD) ErrorCode (WORD) SendAreaID (UINT) 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 Serial Port 1 D1200 to D1299 A640.00 to 02 W127, D3850 to D3885 Built-in RS-485 Serial Port 2 D1300 to D1399 A641.00 to 02 W127, 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 PLC Settings Ladder programming 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 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 create programs. 9 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. Output frequency reference value 60.00 Hz W1.00: ON RUN Command (W0.00) Output Frequency Monitor Always monitoring while W2.00 is ON. Modbus-RTU master CP2E-S□□-type CPU Unit 3G3MX2-V1 Inverter Slave address: 3 Output Frequency Reference RUN Command Output Frequency Monitor Built-in RS-485 port 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 Reference Setting _CP2E030_Send ModRTU_F06_P2 Write Single Register Output Frequency Setting Parameter No. F001(LOW) Modbus register spec. No.: 0001 Hex (Register No.: 0002Hex-1) RUN Command _CP2E030_Send ModRTU_F05_P2 Write Single Coil RUN Command 0: Stop, 1: RUN Modbus coil spec. No. 0000 Hex (coil No.0001Hex-1) Output Frequency Monitor _CP2E030_Send ModRTU_F03_P2 Read Holding Registers Output Frequency Monitor Parameter No. d001(LOW) Modbus register spec. No.: 1001 Hex (Register No.: 1002Hex-1) 10 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. Built-in RS-485 port 3G3MX2-V1 Control circuit terminal block A- RS- B+ RS+ FG CP2E-S CPU Unit Turn ON the terminating resistor selector switch Turn ON the DIP switch for terminating resistance settings 3G3MX2-V1 Inverter 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 Settings Select the Custom Option and set the baud rate to 115200 and the format to 8,1,E. * 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). 11 (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 Reference Selection 03: Modbus communication 02 03 A002/A202 1st/2nd RUN Command Selection 03: Modbus communication 02 03 C071 Communication Speed Selection 03: 2400 bps 04: 4800 bps 05: 9600 bps 06: 19.3 kbps 07: 38.4 kbps 08: 57.6 kbps 09: 76.8 kbps 10: 115.2 kbps 05 10 115.2 kbps C072 Communication Station No. Selection (Modbus slave address) 1 to 247 1 3 C074 Communication Parity Selection 00: No parity 01: Even parity 02: Odd parity 00 01 Even parity C075 Communication Stop Bit Selection 1: 1 bit 2: 2 bits 1 1 1 bit 12 Parameter No. Function name Data Default data Set value C076 Operation Selection on Communication Error 00: Trip 01: Trip after deceleration stop 02: Ignore 03: Free-run stop 04: Deceleration stop 02 02 Ignore C077 Communication Error Timeout Time 0.00: Timeout disabled 0.01 to 99.99 0.00 0.00 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. 13 (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. ・ 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. Modbus slave address: 3 Register address: 0001 Hex Boot flag Area and word to store output frequency value to set: D100 The error code is stored in D120 if FB_NG 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) 14 (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. ・ 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. Modbus slave address: 3 Output coil address: 0000 Hex Boot flag Output value 1: #FF00 The error code is stored in D121 if FB_NG is turned ON 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) Modbus slave address: 3 Output coil address: 0000 Hex Boot flag Output value 0: #0000 The error code is stored in D122 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) 15 ・ 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. ・ 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. Modbus slave address: 3 Quantity of registers: 1 Register starting address: 1001 Hex Boot flag Area and word to store read output frequency: D110 The error code is stored in D123 if FB_NG is turned ON 16 Reference: difference allocation Modbus-RTU Easy Master Function and Function Block ■ Memory allocation of Modbus-RTU Easy Master function ■ Example of Modbus RTU Master Function Block FB busy flag FB normal end FB error end Modbus error code P_On Boot flag Modbus slave address Register starting address Quantity of registers Area of write data First word at write data _CP2E030_SendModRTU_F10_P□ (BOOL) EN (BOOL) ENO (BOOL) Execute (BOOL) FB_BUSY (UINT) SlaveAddr (BOOL) FB_OK (UINT) WriteRegAddr (BOOL) FB_NG (UINT) WriteRegSize (WORD) ErrorCode (WORD) SendAreaID (UINT) 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. - - Slave address - - Function code No. of communications data bytes Communications data (Coil address, register address, data, etc.) A641.00 Execution Bit A641.01 Execution Normal Flag A641.02 Execution Error Flag 15 07 00 D1300 D1301 D1302 D1303 . . . 17 ■ Practices Guide - Revision History Revision code Date Revised content A November 2019 Original production 18 Description of Functions 19 CP2E 030 Modbus RTU master: _CP2E030_SendModRTU Basic function Send Modbus RTU command from serial communication port. Symbol ◼Function01: Read Coils FB busy flag FB normal end FB error end Modbus error code P_On Boot flag Modbus slave address Coil starting address Quantity of coils Area of read data Word of read data _CP2E030_SendModRTU_F01_P□ (BOOL) EN (BOOL) ENO (BOOL) Execute (BOOL) FB_BUSY (UINT) SlaveAddr (BOOL) FB_OK (UINT) ReadCoilAddr (BOOL) FB_NG (UINT) ReadCoilSize (WORD) ErrorCode (WORD) RecvAreaID (UINT) RecvAreaNo ◼Function03:Read Holding Registers FB busy flag FB normal end FB error end Modbus error code P_On Boot flag Modbus slave address Register starting address Quantity of register Area of read data First word of read data _CP2E030_SendModRTU_F03_P□ (BOOL) EN (BOOL) ENO (BOOL) Execute (BOOL) FB_BUSY (UINT) SlaveAddr (BOOL) FB_OK (UINT) ReadRegAddr (BOOL) FB_NG (UINT) ReadRegSize (WORD) ErrorCode (WORD) RecvAreaID (UINT) RecvAreaNo ◼Function05:Write Single Coil FB busy flag FB normal end FB error end Modbus error code P_On Boot flag Modbus slave address Output coil address Output value _CP2E030_SendModRTU_F05_P□ (BOOL) EN (BOOL) ENO (BOOL) Execute (BOOL) FB_BUSY (UINT) SlaveAddr (BOOL) FB_OK (UINT) WriteCoilAddr (BOOL) FB_NG (WORD) OutputValue (WORD) ErrorCode ◼Function06:Write Single Register FB busy flag FB normal end FB error end Modbus error code P_On Boot flag Modbus slave address Register address Area of write data Word of Write data _CP2E030_SendModRTU_F06_P□ (BOOL) EN (BOOL) ENO (BOOL) Execute (BOOL) FB_BUSY (UINT) SlaveAddr (BOOL) FB_OK (UINT) WriteRegAddr (BOOL) FB_NG (WORD) SendAreaID (WORD) ErrorCode (UINT) SendAreaNo 20 Symbol ◼Function10:Write Multiple Registers FB busy flag FB normal end FB error end Modbus error code P_On Boot flag Modbus slave address Register starting address Quantity of register Area of write data First word at write data _CP2E030_SendModRTU_F10_P□ (BOOL) EN (BOOL) ENO (BOOL) Execute (BOOL) FB_BUSY (UINT) SlaveAddr (BOOL) FB_OK (UINT) WriteRegAddr (BOOL) FB_NG (UINT) WriteRegSize (WORD) ErrorCode (WORD) SendAreaID (UINT) 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 models CPU Unit CP2E CX-Programmer Version 9.72 or higher Conditions for usage ◼Settings ・ 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 Serial port1 D1200 to D1299 A640.00 to A640.02 W127 D3850 to D3885 Built-inRS-485 Serial port2 D1300 to D1399 A641.00 to A641.02 W127 D3900 to D3935 Serial port1(EX) D1400 to D1499 A638.00 to A638.02 W127 D3950 to D3985 21 Function description ◼Function block operation ・ 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 FB busy flag (FB_BUSY) FB normal end or FB error end (FB_OK/FB_NG) FB execution completed At FB normal end : Read or write operation is completed. ON OFF ON OFF EN (P_On) ON OFF Boot flag (Execute) ON OFF Send once Send continuously •Send processing will be repeated during Boot flag is ON. ◼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) Send command EN (P_On) ON OFF Boot flag (Execute) Instance 1 ON OFF Send command Boot flag (Execute) Instance 2 ON OFF Send command Boot flag (Execute) Instance 3 ON OFF Command is not sent if Boot flag is turned OFF before send command. Each instance is executed in the order in which Boot flag is turned ON. “1”? ”3”? ”2”? ”1”・・・ Each instance is executed in the order in which Boot flag is turned ON. “1”? ”2”? ”3”? ”1”・・・ 3 3 3 3 3 3 2 2 2 2 1 1 1 1 1 1 1 1 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 22 Kind of FB definition Connect Always ON type Connect the EN input to the Always ON Flag (P_On) ・ The same instance can not be used in two or more places. FB precautions ・ The FB is processed over multiple cycles. The FB busy flag (FB_BUSY) output variable can be used to 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 condition ・ Connect the EN input to the Always ON Flag (P_On). ・ If a different type of bit is connected to EN, the FB outputs will be maintained when the connected bit is turned OFF. Restrictions Input variables ・ Use the Always ON Flag (P_On) for EN. ・ If Boot flag (Execute) is turned OFF before Modbus RTU command is sent, Modbus RTU command is 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 example Send Modbus RTU command to Modbus RTU slave. Sends according to the ON / OFF status of W0.00 to W0.04. P_On W0.00 Instance0 (BOOL) EN (BOOL) Execute … P_On W0.01 Instance1 (BOOL) EN (BOOL) Execute … P_On W0.02 Instance2 (BOOL) EN (BOOL) Execute … P_On W0.03 Instance3 (BOOL) EN (BOOL) Execute … P_On W0.04 Instance4 (BOOL) EN (BOOL) Execute … Boot flag W0.00 ON ON ON ON ON W0.01 ON OFF OFF OFF OFF W0.02 ON ON ON OFF OFF W0.03 ON ON OFF ON OFF W0.04 ON ON OFF ON OFF Send command status Instance0 Send Send Send Send Send Instance1 Send Pending Pending Pending Pending Instance2 Send Send Send Pending Pending Instance3 Send Send Pending Send Pending Instance4 Send Send Pending Send Pending Related manuals CP2E CPU Unit Software User’s manual (W614) 14-4 Modbus RTU Easy Master Function 23 ◼ 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 address SlaveAddr UINT &1 &1 to &31 Coil starting address ReadCoilAddr UINT &0 &0 to &65535 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 address SlaveAddr UINT &1 &1 to &31 Register starting address ReadRegAddr UINT &0 &0 to &65535 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 data RecvAreaNo UINT &0 &0 to &3849 D0 to D3849 [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 address SlaveAddr UINT &1 &1 to &31 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 address SlaveAddr UINT &1 &1 to &31 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 24 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 address SlaveAddr UINT &1 &1 to &31 Register starting address WriteCoilAddr UINT &0 &0 to &65535 Quantity of register WriteRegSizeUINT &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 data SendAreaNo UINT &0 &0 to &3849 D0 to D3849 [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 25 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 address 2 bytes ReadCoilAddr 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 (from &4) Byte count 02 Hex Coil starting address (Low) Coil status 4 to 11 8A Hex W10.08 to W10.15 Quantity of coils (High) 000A Hex (10 bit) Quantity of coils (Low) Coil status 12 to 13 02 Hex W10.00 to W10.01 FB busy flag FB normal end FB error end Modbus error code P_On Boot flag Modbus slave address &2 Coil starting address &4 Quantity of coils &10 Area of read data P_WR Word of read data &10 _CP2E030_SendModRTU_F01_P□ (BOOL) EN (BOOL) ENO (BOOL) Execute (BOOL) FB_BUSY (UINT) SlaveAddr (BOOL) FB_OK (UINT) ReadCoilAddr (BOOL) FB_NG (UINT) ReadCoilSize (WORD) ErrorCode (WORD) RecvAreaID (UINT) RecvAreaNo Modbus slave 2 15 14 13 (1) 12 (0) 11 (1) 10 (0) 9 (0) 8 (0) 7 (1) 6 (0) 5 (1) 4 (0) 3 2 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. 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. Read 26 ◼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 address 2 bytes ReadRegAddr 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 (from &100) Byte count 06 Hex Register starting address (Low) Register value (High) AB12 Hex (D1000) Quantity of register (High) 0003 Hex (3 words) Register value (Low) Quantity of register (Low) Register value (High) 5678 Hex (D1001) Register value (Low) Register value (High) 9713 Hex (D1002) Register value (Low) FB busy flag FB normal end FB error end Modbus error code P_On Boot flag Modbus slave address &2 Coil starting address &100 Quantity of coils &3 Area of read data P_DM Word of read data &1000 _CP2E030_SendModRTU_F01_P□ (BOOL) EN (BOOL) ENO (BOOL) Execute (BOOL) FB_BUSY (UINT) SlaveAddr (BOOL) FB_OK (UINT) ReadCoilAddr (BOOL) FB_NG (UINT) ReadCoilSize (WORD) ErrorCode (WORD) RecvAreaID (UINT) RecvAreaNo 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 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 Read 27 ◼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 (&10) Output coil address (High) 000A Hex (&10) Output coil address (Low) Output coil address (Low) Output value FF00 Hex (ON) Output value FF00 Hex (ON) FB busy flag FB normal end FB error end Modbus error code P_On Boot flag Modbus slave address &2 Output coil address &10 Output value #FF00 _CP2E030_SendModRTU_F05_P□ (BOOL) EN (BOOL) ENO (BOOL) Execute (BOOL) FB_BUSY (UINT) SlaveAddr(BOOL) FB_OK (UINT) WriteCoilAddr (BOOL) FB_NG (WORD) OutputValue (WORD) ErrorCode CP2E Output Coil address: &10, Write data: FF00 Hex (ON) Modbus slave 2 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 0→1 Write 28 ◼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 (200) Register address (High) 00C8 Hex (200) Register address (Low) Register address (Low) Quantity of register (High) 3AC5 Hex (D500) Quantity of register (High) 3AC5 Hex Quantity of register (Low) Quantity of register (Low) FB busy flag FB normal end FB error end Modbus error code P_On Boot flag Modbus slave address &2 Register address &200 Area of write data P_DM Word of Write data &500 _CP2E030_SendModRTU_F06_P□ (BOOL) EN (BOOL) ENO (BOOL) Execute (BOOL) FB_BUSY (UINT) SlaveAddr (BOOL) FB_OK (UINT) WriteRegAddr (BOOL) FB_NG (WORD) SendAreaID (WORD) ErrorCode (UINT) SendAreaNo CP2E 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 D500 3 A C 5 D501 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 Write 29 ◼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 address 2 bytes WriteRegAddr 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 address 2 bytes Same as WriteRegAddr 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 (from 10) Register starting address (High) 000A Hex Register starting address (Low) Register starting address (Low) Quantity of register (High) 02 Hex (2 words) Quantity of register (High) 02 Hex (2 words) Quantity of register (Low) Quantity of register (Low) Byte count 04 Hex Register value1 (High) 0100 Hex (D2000) Register value1 (Low) Register value2 (High) 3A98 Hex (D2001) Register value2 (Low) FB busy flag FB normal end FB error end Modbus error code P_On Boot flag Modbus slave address &2 Register starting address &10 Quantity of register &2 Area of write data P_DM First word at write data &2000 _CP2E030_SendModRTU_F10_P□ (BOOL) EN (BOOL) ENO (BOOL) Execute (BOOL) FB_BUSY (UINT) SlaveAddr (BOOL) FB_OK (UINT) WriteRegAddr (BOOL) FB_NG (UINT) WriteRegSize (WORD) ErrorCode (WORD) SendAreaID (UINT) SendAreaNo 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 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 Write 30 ◼ 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. Practices Guide 1. Modbus RTU Master Function Block 1.1 Overview of Function Blocks 1.2 Function Blocks to Use 2. Operating Procedure 3. Programming Examples 3.1 Wiring Example 3.2 Setting 3.3 Ladder Programming Examples Description of Functions