Sie sind auf Seite 1von 70

SIMATIC S7 - OPEN MODBUS / TCP Communication via CP343-1 and CP443-1

Manual

Preface, Table of Contents Product Description Mounting

1 2 3 4 5 6 7 8

SIMATIC S7
Getting Started

OPEN MODBUS / TCP Communication via CP343-1 and 443-1


Manual

Commissioning Licensing FB MODBUSCP Diagnostics Application Samples Appendices Literature Glossary

Edition 4.1

Safety Precautions and Warnings

This manual contains warnings, which you should note for your own safety as well as for the prevention of damage to property. These warnings are indicated by means of a triangle and displayed as follows in accordance with the level of danger: __________________________________________________________________
Danger indicates that loss of life, severe personal injury or substantial damage will result if proper precautions are not taken.

__________________________________________________________________ __________________________________________________________________
Warning indicates that loss of life, severe personal injury or substantial damage can result if proper precautions are not taken.

__________________________________________________________________ __________________________________________________________________
Caution indicates that minor personal injury or property damage can result if proper precautions are not taken.

__________________________________________________________________ __________________________________________________________________
Note call attention to information that is especially significant to the product, handling of the product or a specific part of this documentation.

__________________________________________________________________
Qualified Personnel The equipment may be commissioned and put into operation by qualified personnel only. For the purpose of safety relevant warnings of this manual a qualified person is one who is authorized to commission, ground and tag devices, systems and circuits. Please note the following: ___________________________________________________________________ Warning This equipment must only be used in applications as prescribed in the catalogue and the technical description and in conjunction with equipment and components recommended and authorized by Siemens. Successful and safe operation of this equipment is dependent upon proper transport, and storage, erection and installation as well as careful operation and maintenance.

Use as prescribed

SIMATIC and SIMATIC NET are registered trademarks of SIEMENS AG. Trademarks The other brand names in this manual may be trademarks use of which by third parties for their purposes may infringe the proprietors rights. Exclusion from Liability
We have checked the contents of this document with regard to conformity to the described hardware and software. Deviations, however, cannot be excluded; therefore we cannot accept prejudice for its complete conformity. The information in this document is checked regularly and necessary corrections are contained in subsequent issues. Any suggestions for improvement are gratefully received. We reserve the right to make technical changes.

Copyright Siemens AG 2004-2009 All Rights Reserved


The reproduction, transmission or use of this document or its contents is not permitted without express written authority. Offenders will be liable for damages. All rights, including rights created by patent grant or registration of a utility model or design, are reserved. Siemens AG Industry Sector Engineering and Construction I IS IN E&C P.O. Box 3240, D- 91050 Erlangen IT4.Industry@siemens.com

Preface

Preface
Purpose of the Manual The information in this manual allows you to set up and put in operation the connection between the CP 343-1/CP 443-1 and a device that supports the Open MODBUS/TCP protocol. This manual describes the function of the function block MODBUSCP and its integration into the hardware and software of the communication processors CP 343-1/CP 443-1. The manual contains the following topics: Production description / Mounting Getting Started Commissioning Parameterization Licensing Function block MODBUSCP Diagnostics Application samples

Contents of the Manual

Scope of this Manual

This manual is valid for the following software: Product OPEN MODBUS / TCP FB 108 MODBUSCP FB 106 MB_CPCLI FB 107 MB_CPSRV Identification number 2XV9 450-1MB00 From version 4.1 1.1 / 2.0 1.1 / 2.0 1.1 / 2.0

Note This manual contains the FB description, as it is valid at the time of publication.

How to Access the Information in this Manual

To enable you a quick access to selected information, the manual provides the following access aids: The next pages contain a complete table of contents.

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

Preface

Additional Sources of Information

All additional information concerning CP 343/CP 443 (mounting, commissioning etc.) can be found in the manual SIEMENS SIMATIC NET S7-CPs for Industrial Ethernet device manual C79000-G8900-C155 SIEMENS SIMATIC NET S7-CPs for Industrial Ethernet device manual part B1 CP 343-1 / CP 343-1EX20 C79000-G8900-C158 SIEMENS SIMATIC NET S7-CPs for Industrial Ethernet device manual part B4 CP 443-1 C79000-G8900-C152 SIEMENS SIMATIC NET NCM S7 for Industrial Ethernet manual C79000-G8900-C129 Additional information concerning STEP7 can be found in the following manuals: SIEMENS SIMATIC Software Base software for S7 and M7 STEP7 user manual C79000-G7000-C502-.. SIEMENS SIMATIC Software System software for S7-300/400 System and standard functions Reference manual C79000-G7000-C503-02

Additional Questions

If you have further questions regarding the use of the FBs described in this manual, which are not answered in this document, please contact your Siemens partner who supplied you with this function block. This document uses the term CP or CP 343/CP 443. The descriptions only apply to communications processor CP 343-1/CP 443-1. The function block described in this manual establishes a connection between the CP 343-1/CP 443-1 and third party MODBUS devices.

Terminology

Scope of Application

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

Table of contents

Table of Contents
1 ...... Product Description....................................................................................................... 1-1 1.1 ........ Field of Applications.......................................................................................... 1-1 1.2 ........ Hardware and Software Prerequisites.............................................................. 1-2 2 ...... Mounting ......................................................................................................................... 2-1 2.1 ........ Interface Connection ........................................................................................ 2-1 3 ...... Getting Started ............................................................................................................... 3-1 4 ...... Commissioning .............................................................................................................. 4-1 4.1 ........ Installing the Library on the STEP7 PG/-PC .................................................... 4-1 4.2 ........ Configuration of the Communication Link ........................................................ 4-2 4.3 ........ Parameterization of the CP .............................................................................. 4-3 4.4 ........ Network Configuration ...................................................................................... 4-5 4.5 ........ How to Select the Appropriate Modbus Block ................................................ 4-10 4.6 ........ Insertion of the Function Blocks into the Program.......................................... 4-11 4.7 ........ Multiple Connections via Port 502 .................................................................. 4-13 4.8 ........ Start_up Characteristics of CP343 / CP443 ................................................... 4-14 4.9 ........ Changeover of a Previous Version to V4.x .................................................... 4-15 5 ...... Licensing ........................................................................................................................ 5-1 6 ...... Function Block MODBUSCP ......................................................................................... 6-1 6.1 ........ Functionality of the FB ...................................................................................... 6-1 6.2 ........ Parameters of the Function Block MODBUSCP .............................................. 6-4 6.3 ........ Address Mapping............................................................................................ 6-12 6.4 ........ Data and Standard Functions used by the FB ............................................... 6-15 6.5 ........ Renaming of Standard Functions ................................................................... 6-17 7 ...... Diagnostics..................................................................................................................... 7-1 7.1 ........ Diagnostics via the Display Elements of the CP .............................................. 7-1 7.2 ........ Verification by the FB MODBUSCP.................................................................. 7-2 7.3 ........ Diagnostic Messages of the FB MODBUSCP.................................................. 7-5 OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1 ii

Table of contents

7.4 ........ Diagnostic Messages of FC5/FC6 and FC50/FC60....................................... 7-11 7.5 ........ Diagnostic Messages of included FCs/SFCs ................................................. 7-11 7.6 ........ Diagnostic Messages of SFC24 ..................................................................... 7-11 8 ...... Application Samples...................................................................................................... 8-1 8.1 ........ Sample project STL .......................................................................................... 8-2 8.2 ........ Sample project CFC ......................................................................................... 8-3

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

iii

Product description

Product Description

1.1

Field of Applications
Placement in the System Environment The driver described here is a software product for the Communications Processor CP343-1/CP443-1. The CP343-1 can be used in the SIMATIC S7-300 automation system and can establish communication links to partner systems. CP443-1 can be used in the SIMATIC S7-400 automation systems and can establish communication links to partner systems. Function of the FBs These function blocks enable a communication link between CP343-1 / CP443-1 and a device that supports the Open MODBUS/TCP protocol. The function codes 1, 2, 3, 4, 5, 6, 15 and 16 are provided. Data transmission is carried out following the Client-Server principle. The SIMATIC S7 can act as both client and server during the data transmission. TCP/IP with CP343-1 / CP443-1 TCP/IP with CP343-1 and CP434-1 uses static connections. The TCP connection is not disconnected during errror-free operation. Network configuration of STEP7 enables only a unique use of a specific port number, when using TCP native stack of the CP. However, with specific CP modules it is possible to use multiple connection via port 502 to different clients simultaneously. In section 4.7 Mulitple connections via port 502 you can find technical details regarding this matter.

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

1-1

Product description

1.2

Hardware and Software Prerequisites


Usable Modules You can find the latest hardware prerequisites on the internet: www.siemens.com/s7modbus. The usage of the FB MODBUSCP is possible with STEP7 Version 5.1 or higher with the option NCM S7 for Industrial Ethernet. From version 5.3 of STEP 7 the option NCM is part of the main package of STEP 7.

Software Versions

Memory requirements

The FB MODBUSCP requires ca. 6k byte work and load memory. The FB MB_CPCLI requires ca.10k byte work and memory. The FB MB_CPSRV requires ca. 10 k byte work and load memory. The particular length of the blocks can be determined in the properties of the block in the Simatic Manager.

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

1-2

Mounting

Mounting

2.1

Interface Connection
General Information An Industrial Ethernet connection to a subsystem can be established. The connection of the CP to Industrial Ethernet is possible via Bus coupler or a twisted pair connection. Bus Coupler (Transceiver) via AUI-Connection The CP produces and supplies the required voltage for the Bus Coupler.

Transceiver cable Plugable cable 727-1

Bus coupler

Industrial Twisted Pair Connection e. g via OSM

When using the Industrial Ethernet installation instructions according to the following diagram the CP will recognize the Twisted Pair and automatically change to it.

E. g. Optical Switch Module (OSM)

ITP installation cable

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

2-1

Mounting

Twisted Pair Connection via RJ45connector

In an environment with low EMC pollution like offices and switchboards, the CP can be connected to the Ethernet using a Twisted Pair cable with a RJ-45 connector.

E. g. Optical Switch Module (OSM)

Additional Information

Note An AUI/ITP connector or a TP connector may be connected for a flawless connection. When hardware is changed (a cable is disconnected and plugged to another interface) during the run mode it is possible that the new connection (change) is not recognized. Therefore, the device must be turned off before you change the interface.

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

2-2

Getting started

Getting Started
1. Install OpenModbusTCP CP. => Section 4.1 2. Parameterize the connection parameters regarding your requirements (IP-address, port number, etc.). => Section 4.2 to 4.4 3. Insert the Modbus function blocks into your SIMATIC project. => Section 4.6 4. Call the Modbus block FB108 in the required OBs. => Section 6.1 5. Parameterize the Modbus block for initialization (client/server, DB areas, Modbus addresses) and runtime. => Section 6.2 6. Load the user program into the PLC and license the Modbus block for this CPU. => Section 5

Procedure

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

3-1

Commissioning

Commissioning
The configuration of the CP443-1/CP343-1 is possible via MPI or LAN/Industrial Ethernet. STEP7 is required with NCM S7 for Industrial Ethernet (shortly named NCM IE). The information below about STEP7 and the communication link configuration refers to STEP7 Version 5.1 and NCM S7 Industrial Ethernet Version 5.1. In later versions, the sequences, names and directories might be different.

General Information

Requirements

Knowledge of AWL and basic knowledge of STEP7 and PLC.

4.1

Installing the Library on the STEP7 PG/-PC


What We Provide You The attached CD contains a setup, which installs the library Modbus_TCP_CP, 2 example projects and the manuals in English and German in the corresponding STEP7 directories. The manuals are available outside the setup additionally, to give you the opportunity to get all information regarding the software without installation. Requirements To install, STEP7 must be installed. With older STEP7 versions the option NCM S7 for Industrial Ethernet is necessary additionally. Insert your Modbus CD into the CD-ROM drive and follow step-by-step the instructions that are automatically displayed by the installation program. If the installation program fails to automatically run, perform these steps: 1. Using Windows Explorer, navigate to the CD-ROM drive and go to the directory setup and double-click Setup.exe file to start the installation procedure. 2. Follow step-by-step the instructions that are displayed by the installation program. Now you can find the library in the manual in \Program Files\Siemens\Step7\S7libs, \Program Files\Siemens\Step7\S7manual\S7Comm, 2 example projects in \Program Files\Siemens\Step7\Examples, the software registration form in \Program Files\Siemens\Step7\S7libs\Modbus_TCP_CP. To access the Modbus library the first time, use the browse function of the open dialog for libraries. The manual can be accessed via short cut in \Program Files \Siemens \Documentation as well.

Installation

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

4-1

Commissioning

4.2

Configuration of the Communication Link


Introduction The configuration of the communication link consists of the order of the hardware in the configuration table using HW Config. You do the configuration using STEP7 software. For an Industrial Ethernet link, the SIMATIC 400-Station, SIMATIC 300-Station, the communication partner and the Industrial Ethernet-network must be configured. S7 Project Before you can do the configuration, you must have created a new S7 Project on STEP7. Insert the necessary project components with SIMATIC-Manager into the opened project: SIMATIC-Station, Other Station, Industrial Ethernet network. Before each insertion, click on the opened project to select it. SIMATIC 300-Station Insert Station SIMATIC 300-Station for your S7 Program (Rack, PS, CPU, CP343-1, ...), Insert Station Other Station for the communication partner Insert Subnet Industrial Ethernet for an Industrial Ethernet network between the SIMATIC 300 -Station and the communication partner. SIMATIC 400-Station Insert Station SIMATIC 400-Station for your S7-Program (Rack, PS, CPU, CP443-1, ...), Insert Station Other Station for the communication partner, Insert Subnet Industrial Ethernet for an Industrial Ethernet network between the SIMATIC 400-Station and the communication partner. Configure Hardware The configuration of the hardware includes the selection of the hardware components and its characteristics. SIMATIC 300-Station or SIMATIC 400-Station By selecting the SIMATIC-Station and double clicking on Hardware (or Edit Open object) HW Configuration is started. With Insert Hardware components insert a RACK, a PS, a CPU and the CP Industrial Ethernet CP x43-1 with the appropriate order numbers. The procedures for configuring S7 devices are described in detail in the user manual of STEP7.

Project Components

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

4-2

Commissioning

4.3

Parameterization of the CP
After the devices are arranged on your rack with HW Config they have to be parameterized. The parameterization window of the CP 343-1 or CP 443-1 can be started in HW Config by double clicking the CP or selecting the CP and clicking the menu item Edit Object properties. Properties CP343-1 Properties CP443-1 General or General

Parameterization of the CP

Click on tab General, then select Properties (single click). This will open the Ethernet interface window. Here you can enter the IP Address and the Subnet Mask of the CP. If you have your stations connected with each other without a router, then they have to be within the same subnet. In the field Subnet connect the CP with the Industrial Ethernet. In order to do that, select the entry with the name of your network. For newly created networks this is normally Ethernet(1).

After the successful parameterization you will be back in the dialog box, Properties CP343-1 or Properties CP443-1. Here click on OK to finish the parameterization of the CP and you will be back in the dialog box HW Config. Save and Compile the parameterization and close HW Config. You will be back in the main menu of the STEP7 project.

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

4-3

Commissioning

Parameterization of the Communication Partner

In the mode CP is client an other station is required for network configuration. After you have inserted the communication partners station into your STEP7 project (as described in Project components: Insert Other station) you have to specify the object properties of the external station. Starting from the STEP7 project, you can select the communication partner (Other station) by clicking it. Select the menu item Edit Object Properties. This opens the dialog box Properties Other Station. 1) Properties Other Station Interfaces

On the tab Interfaces click on New. In the upcoming selection, select Industrial Ethernet and click on OK.

This opens a dialog box Properties Ethernet Interface. Enter an IP Address that is in the same subnet as the communication partners station. The subnet mask should be the same as the one of the partners station. Select the associated subnet that connects the CP interface with the communication partners interface.

Click on the OK button. This will bring you back to the tab Interfaces. OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1 4-4

Commissioning

2) Properties Other Station General In tab General you do not have to make any settings. Click on the OK button and you will be back in the main menu of the STEP7 project. An external station can have multiple interfaces (= Ethernet devices) and may be connected to different Ethernet networks.

4.4

Network Configuration
Communications Connection The CP is the link for the Industrial Ethernet connection between the S7-CPU and the communication partner / bus. A connection configuration must be made for the connection of the interfaces to the communication partner / bus. In the STEP7 project, select the CPU in your S7 300/S7 400-Station and open Network configuration by double clicking Connections. This opens the program NetPro with which your connections can be configured.

Configure Network in mode CP is Client

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

4-5

Commissioning

After selecting Insert New Connection... the dialog box Insert new connection will come up.

Select the connection partner (Other Station) for the new connection and use TCP Connection for the connection. Put a check mark on Show properties dialog

Click OK. This will take you back to the dialog box Properties TCP connection.

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

4-6

Commissioning

Object Properties of the Connection

An ID is provided. You can change the ID if needed. Click on the button Routing and the configured connection will be shown. The MODBUS client must execute Active connection establishment.

In the register Addresses the port numbers are defined.

Click on OK and the inputs are accepted. Save the network configuration and close the program NetPro. Please note that the connection ID (Local ID) has to be used when the FB is called in the user program. Selection of the Port Number In a MODBUS communication a MODBUS server are normally addressed via port 502, whereas a MODBUS client uses a port from 2000.

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

4-7

Commissioning

Unspecified Connection with CP is server

If you have got a communication with CP as MODBUS server, the communication is set up as unspecified connection. The client must carry out active connection establishment. After selecting Insert New Connection... the dialog box Insert new connection will come up.

Select here unspecified instead of the communication partner and use TCP Connection for the connection. Put a check mark on Show properties dialog

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

4-8

Commissioning

Click OK. This will take you back to the dialog box Properties TCP connection. The check box active connection establishment must not be activated.

In the register addresses all information regarding the partner, IP and PORT are left blank.

Click on OK and the inputs are accepted.

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

4-9

Commissioning

4.5

How to Select the Appropriate Modbus Block


The block AG_CNTRL of the SIMATIC_NET library permits to terminate and reestablish an established connection. This block was also implemented in the Modbus blocks for a more effective use of the resources of CPU and CP. However, previous CPs or previous firmware releases do not support the use of AG_CNTRL. Therefore the library contains directories for both alternatives, each for S7-300 CPs and S7-400 CPs: Current CP 300 Current CP 400 Previous CP 300 Previous CP 400 CPs of S7-300 which support AG_CNTRL (not for CPU315 and 317) CPs of S7-400 which support AG_CNTRL CPs of S7-300 which do not support AG_CNTRL CPs of S7-400 which do not support AG_CNTRL

General Information

Pay attention to the count of local data of the used CPU! The required local data for both alternatives are written in chapter 6.4.

Which CPs support AG_CNTRL?

Here you can find up-to-date information which CPs and which firmware releases support AG_CNTRL: Ethernet CPs and AG_CNTRL If the used CP is not mentioned here, the Modbus blocks without AG_CNTRL must be used.

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

4-10

Commissioning

4.6

Insertion of the Function Blocks into the Program


The following blocks are required for the Modbus communication: MODBUSCP MB_CPCLI MB_CPSRV

Content of MODBUS library

AG_CNTRL

The block MODBUSCP calls the blocks EQ_STRNG of the standard library and AG_CNTRL of the Simatic Net library amongst others. As both blocks are named FC10, the block AG_CNTRL is already renamed to FC11 in the Modbus library Current CP.

Insertion of the MODBUS FBs

In order to exchange data with MODBUS devices, you need the function blocks MODBUSCP, MB_CPCLI, MB_CPSRV and AG_CNTRL if applicable. To be able to insert this into your project you have to copy the function block from the library. For that, open the library Modbus_TCP_CP by selecting the menu item File Open. In the dialog box Open Project select the tab Libraries. Select the library Modbus_TCP_CP using the Browse-Button and click OK. This opens the library. Open the folder CP 300 or CP 400 according to your Configuration by double clicking it. Select the function blocks and copy it via Edit Copy. Then change back to your project . In the Step7 project, in your opened S7 300/S7 400-Station, select the CPU. Double click S7-program, and then Blocks. This will open the Blocks folder. Select Edit Paste. This will insert the block into your program.

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

4-11

Commissioning

Insertion of the Communication Blocks

The Modbus function blocks use the function blocks AG_SEND and AG_RECV in S7-300 or AG_LSEND and AG_LRECV in S7-400. These should be inserted into your program. You can find these communication function blocks in the library SIMATIC_NET_CP which are included in the software package NCM S7 for Industrial Ethernet. Open the library by selecting File Open. In the dialog box Open Project select the tab Libraries. Select the library SIMATIC_NET_CP and click OK. This will open the library. For CP 300 family open the folder CP 300 by double clicking it. Select the function FC5 (AG_SEND) and FC6 (AG_RECV) and copy it with Edit Copy. Then change back to your project. Select in the STEP7 project in your opened S7 300-Station the CPU. Open the Blocks folder by double clicking S7-Programm and then Blocks. With Edit Paste, insert the function block into your program.

CP 300

CP 400

For CP 400 family, open the folder CP 400 by double click. Select the function FC50 (AG_LSEND) and FC60 (AG_LRECV) and copy it with Edit Copy. Then change back to your project. Select in the STEP7 project in your opened S7 400-Station the CPU. Open the Blocks folder by double clicking S7-Programm and then Blocks. With Edit Paste, insert the function block into your program. Please note, that the following versions of the FCs are a prerequisite for the faultless function of the FB MODBUSCP: S7-400: AG_LSEND AG_LRECV AG_SEND AG_RECV V3.0 or higher V3.0 or higher V4.2 or higher V4.7 or higher

S7-300:

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

4-12

Commissioning

4.7

Multiple Connections via Port 502


Some CP modules are able to multiplex TCP connections. In doing so several Modbus clients can establish a connection via port 502. The CP acts as Modbus server. Here you can find information which CP and which firmware release support multiple connections via port 502: www.siemens.com/s7modbus

General

Pre-requisits

To use the functionality, the parameterization must be carried out as follows: CP is server port 502 as local port unspezified TCP connection in NETPRO passive connection establishment

Please note that only 1 connection is parameterized in NETPRO irrespective of the number of clients which address the CP as server. Number of Connections Displaying the Status of the Connection The CP is capable to keep up to 8 connections to different clients. A ninth attempt for connection establishment will be rejected. The status of the connection is displayed even in NETPRO online as well as in special diagnosis of the CP. As only 1 connection is parameterized in NETPRO, the display shows the status of all TCP connections to the several clients. As long as no client has established a connection Passive connection establishment in progress is displayed. As soon as one client has established a connection established is displayed. It is not possible to check how many clients have actually established a connection to the CP. Characteristics of the Error Handling The FB MODBUSPN and the CP respectively must terminate and reestablish the connection in certain error situations. This action is carried out by the FB MODBUSPN. Thereby all existing connections via port 502 are terminated. When several connections are established via port 502, it is not possible to identify the client which has sent the recent request. If the clients use different UNIT numbers, the verification of the same in the user program allows a determination.

Tip for your User Program

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

4-13

Commissioning

4.8

Start_up Characteristics of CP343 / CP443


The start up of the CP is divided into the following phases: Initialization (Power on of the CP) Parameterization

Introduction

Initialization

As soon as the CP is connected to power, the hardware self test runs. The firmware of the CP is set up for operation. During parameterization the CP receives the device parameters that are assigned to its slot. The CP is now ready for operation.

Parameterization

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

4-14

Commissioning

4.9

Changeover of a Previous Version to V4.x


If a previous version of "ModbusTCP CP" is already used, some changes must be carried out in the S7 program. An update with the menu file -> "check and update access" is not possible because the interface of the block has changed. 1. Copy the new Modbus blocks FB106, FB107, FB108 and DB3 into your project.,You can rename the modbus blocks, if these block numbers are already used. 2. Open the blocks, in which the modbus blocks have been called so far (OB100 and cyclical OB). 3. Call the new block FB108 MODBUSCP directly after the prior MODBUS or MODB4 call with a new instance DB. 4. Transcribe the following parameters of MODBUS or MODB4 to MODBUSCP depending on the calling OB. id, laddr, MONITOR, db_0 to db_8, ENQ_ENR, server_client, START_ADDRESS, LENGTH, WRITE_READ, INPUT_HOLDING, TI, UNIT, DONE_NDR, ERROR and STATUS. Capital letters represent runtime parameters, small letters initialisation parameters. 5. Add suitable values to the new parameters: REG_KEY, single_write, data_type_x, LICENSED, BUSY and STATUS_FUNC. It is not necessary to allocate the parameter IDENT_CODE. You can find the description of the new parameters in the parameter list in section 6.2. 6. The output parameters are displayed dynamically, i.e. they are only available for one PLC cycle. They have to be copied to an additional memory area if you need to process them or to display the values in a VAT (STEP7 variable table). Adapt your program correspondingly. 7. Insert the programming fault block OB121 in your program if this has not been included yet. This block is necessary for the licensing, see section 5 "licensing" for further information. 8. Delete the previous Modbus call or comment it out. Load the program into the CPU and execute a restart of the CPU.

General Information for Changeover to V4.0 Procedure for Changeover to V4.0

Notes to V4.1

Here you find information to V4.1: www.siemens.com/s7modbus, tab Downloads.

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

4-15

Licensing

Licensing
The block MODBUSCP must be licensed for each CPU individually. The licensing takes place in two steps: reading the IDENT_CODE and declaring the registration key REG_KEY. The OB121 must be available in the CPU. The FC10 "EQ_STRNG" (Standard Library) is needed for the registration.

General

Read the IDENT_CODE

To read the IDENT_CODE please proceed as follows: 1. Parameterize the block MODBUSCP in the cyclic OB (OB1 or cyclic interrupt OB) and in OB100 according to your requirements. Transfer the program to the PLC and turn it to RUN mode. 2. Open the instance DB of the block MODBUSCP. Data block -> Open Online to open the DB. Monitoring the block via the button is insufficient.

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

5-1

Licensing

3. The output IDENT_CODE shows an 18 character string Copy this string per copy/paste from the DB und and insert it in the form IT4Industry SOFTWARE REGISTRATION FORM. This form is stored in the library path ..\Program Files\Siemens\Step7\S7LIBS\Modbus_TCP_CP during installation and is also available on the installation CD. Insert the License-No. of the product package into the form.

4. Please send the form per e-mail to IT4Industry it4.industry@siemens.com. Hereupon you will receive the registration key for your PLC. Please note: No ident code can be displayed as long as an initialisation error exists. Evaluate the output STATUS and correct the parameterization.

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

5-2

Licensing

Declaration of the Registration Key REG_KEY

The registration key REG_KEY must be declared for each call of the block MODBUSCP. The registration key REG_KEY should be stored in a global DB. Via this global DB all MODBUSCP blocks can receive the registration key (See also the following example). Please proceed as follows to declare the registration key REG_KEY: 1. Copy the prepared license block DB3 of the library Modbus_TCP_CP into your project. If the DB number is already used in your project, rename the license DB. 2. Open the license DB and copy the 17 digit registration key you received from IT4industry to the column Initial value.

3. Declare the registration key in the data block as initial value to avoid a repeated insertion after reloading the PLC. Open the data block in the SIMATIC manager with the editor in the declaration view. Change over to the data view via the menu View -> Data View. Choose in the menu Edit > Initialize Data Block all values of the column initial value are copied to actual values. 4. Assign the value DB3.REG_KEY to the parameter REG_KEY of the block MODBUSCP. 5. Transfer the changed blocks to the PLC. The registration key can be set at run time. A STOP -> RUN transition is not necessary. The block is now licensed for this CPU.

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

5-3

Licensing

Missing or Wrong Licensing

When the registration key is missing or a wrong one is detected, the SF LED (S7-300) or the INTF LED (S7-400) of the CPU is flashing. A cyclic error message regarding the missing license is displayed in the diagnostic buffer too. The error number of the missing license is W#16#A090.

_____________________________________________________________ Warning

The CPU will turn to STOP mode, if the OB121 is not available. _____________________________________________________________

Modbus communication is carried out even with a missing or wrong registration key, but the output STATUS is set to W#16#A090 no valid license. If this error code is shown although the registration key has been inserted, please check if the FC EQ_STRING is copied into the project.

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

5-4

Function Block MODBUSCP

Function Block MODBUSCP

6.1

Functionality of the FB
General Information The function block MODBUSCP allows a communication between a CP443-1 and CP 343-1 and a partner, which supports Open MODBUS/TCP protocol. The function codes 1, 2, 3, 4, 5, 6, 15 and 16 are supported. Depending on the parameterization the FB can be operated both in client and in server mode. It is also possible to operate a CP as a client and as a server at the same time. In this case two NetPro connections and 2 FB calls are necessary. In the operating mode server the functionality multitasking, according to the MODBUS reference, is not implemented. There is no limitation of the maximum number of parallel called modbus blocks on the part of the library. Though it depends on the CPU and CP how many AG functions can run simultaneously. The maximum number of AG calls can be taken from the manual of the CPU: "Technical Data" > "Communication". In the manual of the CP its detailed, how many AG_SEND/AG_RECV or AG_LSEND/AG_LRECV can be processed by this CP simultaneously. The block MODBUSCP calls the blocks MB_CPCLI (FB106) and MB_CPSRV (FB107) internally. The block MB_CPCLI comprises the function of Modbus client, the block MB_CPSRV executes the function of Modbus server. The function block performs the following functions: Calls the standard functions for the data transfer between the CPU and the CP Generates MODBUS specific telegram header before send Verification of the MODBUS specific telegram header after receive Verification if the memory areas exist which are requested by the client Generate exception telegrams when failures occur (only when CP is in server mode) Exception code 1 2 3 Meaning The requested function code is not supported. An access to a not existing or not permitted address was carried out. An invalid length was indicated for this function code.

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

6-1

Function Block MODBUSCP

Online-Help

Data transfer to and from the parameterized DB Monitoring the data reception with a time-out Verification of the registration key

In Simatic Manager an online help for function block MODBUSCP is provided. Mark the FB and press the key F1. The online help is displayed; it contains the main information regarding the FB. The function block MODBUSCP has to be called in two OBs: in the start up OB100 and in a cyclic OB (OB1 or cyclic interrupt OB, e.g. OB35) In doing so the same instance DB has to be used. The subordinate blocks of the Modbus library MB_CPCLI and MB_CPSRV must not be called additionally in an organization block. A coexistent call of FB MODBUSCP in OB1 and a cyclic interrupt OB, e.g. OB35 is not permissible. The OB121 must be available in the CPU. You will find more information regarding this matter in section 5 Licensing.

Call of the FB

Start Up of the FB

The function block MODBUSCP should unconditionally be called once in OB100. The initialization parameters must be set according to the station configuration. The initialization parameters will be evaluated and copied into the instance DB. The runtime parameters are not evaluated during start up.

Cyclical Operation of the FB

In cyclical operation the FB MODBUSCP is called in OB1 or a cyclic interrupt OB. According to the runtime parameters, the functions of the function block are activated. While a request is running changes to the runtime parameters are ignored. In the cyclical operation initialization parameters are ignored.

OB121 Programming Error

If the block has not been licensed yet, the OB121 is called.

Warning

The CPU will turn to STOP mode, if the OB121 is not available.

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

6-2

Function Block MODBUSCP

Initiate Request CP is Client

A rising edge at the trigger input ENQ_ENR initiates a request. Depending on the input parameters UNIT, DATA_TYPE, START_ADDRESS, LENGTH, TI and WRITE_READ a MODBUS request telegram is generated and sent to the partner station via the TCP/IP connection. The client waits for the parameterized monitoring time MONITOR for a response from the server. When the monitoring time elapses (no response from the server) the activated request is terminated with an error. A new request can be initiated again. After the receipt of the response telegram a validity check is carried out. If the result is positive, necessary actions will be taken and the request will be terminated without error. The output DONE_NDR is set. When an error is recognized during verification, the request is terminated with an error, the ERROR bit is set and an error number is returned in STATUS.

Activation of the Function Block CP is Server

With TRUE signal at the trigger input ENQ_ENR the FB is ready for receiving a request telegram from the client. The server remains passive. The received telegram is verified. If the telegram is verified positive, the response telegram is sent. The completed transmission is reported to the user by setting the DONE_NDR bit. At this point the completed function is indicated at the outputs UNIT, DATA_TYPE, START_ADDRESS, LENGTH, TI and WRITE_READ. A faulty request telegram causes an error message and the ERROR bit is set. The error number is returned in STATUS. The request of the client is not answered.

Data Transfer CPU CP

The data transfer between CP and CPU are done with the standard function blocks AG_SEND and AG_RECV respectively AG_LSEND and AG_LRECV. At the activation of a MODBUS request by the user (CP is client) or at the receipt of a telegram from the client (CP is server) the standard blocks necessary for the CP are called by the FB in the right order and number. At the receipt of a telegram, the first 6 Bytes are read with the function AG_RECV. This header contains the length of the rest of the telegram. A second call of the AG_RECV function follows with the rest of the telegram length. The verification of the received user data takes place after the complete receipt of the data.

TCP/IP with CP343-1 / CP443-1

TCP/IP with CP 343-1 and CP443-1 uses static connections. The TCP connection cannot be disconnected while in run mode. Given this system characteristic, telegrams might be lost under unfavorable conditions when the synchronization had been lost after an error. The function of the FB in these situations is described in chapter 7. If the CP acts as server and the communication partner terminates the TCP connection, the next receive can be started not until an idle time of 1 second has elapsed. If the CP acts as Client, the next send can be started not until an idle time of 150 milliseconds has elapsed. This delay, due to system characteristics, is executed by the function block.

Termination of the TCP connection by the Communication Partner

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

6-3

Function Block MODBUSCP

6.2

Parameters of the Function Block MODBUSCP


Parameter id laddr MONITOR Decl. IN IN IN Type WORD WORD TIME Description Connection-ID as per configuration in NetPro Input-Address of the CP in HW Config Monitoring Time: Wait for data from communication partner Shortest adjustable time is 20 ms Value range 1 to 64 CPU dependent T#20ms to T#+24d20h31 m23s647ms Character TRUE FALSE TRUE FALSE yes 1 2 3 4 1 to 65535
W#16#1 to W#16#FFFF

Init yes yes no

REG_KEY server_client single_write

IN IN IN

STRING Registration key to activate the license [17] BOOL BOOL CP/FB operates in server mode or client mode Write 1 Coil/Register: Function code 5 and 6 are used respectively Function code 15 and 16 are used respectively 1st data area: data type Coils Inputs Holding Register Input Register 1st data area: data block number

no yes yes

data_type_1

IN

BYTE

db _1

IN

WORD

yes

start _1

IN

WORD

1st data area: first Modbus address in this DB

0 to 65535
W#16#0000 to W#16#FFFF

yes

end _1

IN

WORD

1st data area: last Modbus address in this DB

0 to 65535
W#16#0000 to W#16#FFFF

yes

data_type_2

IN

BYTE

2nd data area: data type (Coils, Inputs, Holding Register, Input Register), NULL if not used 2nd data area: data block number

0 to 4

yes

db _2

IN

WORD

1 to 65535
W#16#1 to W#16#FFFF

yes

start _2

IN

WORD

2nd data area: first Modbus address in this DB 2nd data area: last Modbus address in this DB 3rd data area: data type (Coils, Inputs, Holding Register, Input Register), NULL if not used 3rd data area: data block number

0 to 65535
W#16#0000 to W#16#FFFF

yes

end _2

IN

WORD

0 to 65535
W#16#0000 to W#16#FFFF

yes

data_type_3

IN

BYTE

0 to 4

yes

db _3

IN

WORD

1 to 65535
W#16#1 to W#16#FFFF

yes

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

6-4

Function Block MODBUSCP

Parameter start _3

Decl. IN

Type WORD

Description 3rd data area: first Modbus address in this DB

Value range 0 to 65535


W#16#0000 to W#16#FFFF

Init yes

end _3

IN

WORD

3rd data area: last Modbus address in this DB

0 to 65535
W#16#0000 to W#16#FFFF

yes

data_type_4

IN

BYTE

4th data area: data type (Coils, Inputs, Holding Register, Input Register), NULL if not used 4th data area: data block number

0 to 4

yes

db _4

IN

WORD

1 to 65535
W#16#1 to W#16#FFFF

yes

start _4

IN

WORD

4th data area: first Modbus address in this DB

0 to 65535
W#16#0000 to W#16#FFFF

yes

end _4

IN

WORD

4th data area: last Modbus address in this DB

0 to 65535
W#16#0000 to W#16#FFFF

yes

data_type_5

IN

BYTE

5th data area: data type (Coils, Inputs, Holding Register, Input Register), NULL if not used 5th data area: data block number

0 to 4

yes

db _5

IN

WORD

1 to 65535
W#16#1 to W#16#FFFF

yes

start _5

IN

WORD

5th data area: first Modbus address in this DB

0 to 65535
W#16#0000 to W#16#FFFF

yes

end _5

IN

WORD

5th data area: last Modbus address in this DB

0 to 65535
W#16#0000 to W#16#FFFF

yes

data_type_6

IN

BYTE

6th data area: data type (Coils, Inputs, Holding Register, Input Register), NULL if not used 6th data area: data block number

0 to 4

yes

db _6

IN

WORD

1 to 65535
W#16#1 to W#16#FFFF

yes

start _6

IN

WORD

6th data area: first Modbus address in this DB

0 to 65535
W#16#0000 to W#16#FFFF

yes

end _6

IN

WORD

6th data area: last Modbus address in this DB

0 to 65535
W#16#0000 to W#16#FFFF

yes

data_type_7

IN

BYTE

7th data area: data type (Coils, Inputs, Holding Register, Input Register), NULL if not used 7th data area: data block number

0 to 4

yes

db _7

IN

WORD

1 to 65535
W#16#1 to W#16#FFFF

yes

start _7

IN

WORD

7th data area: first Modbus address in this DB

0 to 65535
W#16#0000 to W#16#FFFF

yes

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

6-5

Function Block MODBUSCP

Parameter end _7

Decl. IN

Type WORD

Description 7th data area: last Modbus address in this DB

Value range 0 to 65535


W#16#0000 to W#16#FFFF

Init yes

data_type_8

IN

BYTE

8th data area: data type (Coils, Inputs, Holding Register, Input Register), NULL if not used 8th data area: data block number

0 to 4

yes

db _8

IN

WORD

1 to 65535
W#16#1 to W#16#FFFF

yes

start _8

IN

WORD

8th data area: first Modbus address in this DB

0 to 65535
W#16#0000 to W#16#FFFF

yes

end _8

IN

WORD

8th data area: last Modbus address in this DB

0 to 65535
W#16#0000 to W#16#FFFF

yes

ENQ_ENR LICENSED

IN OUT

BOOL BOOL

CP is client: Initiate request at TRUE signal CP is server: Ready to receive at TRUE signal License state of the function block: Block is licensed Block is not licensed Operating state of the functions AG_SEND and AG_RECV Job processing No job processing active CP is client: Active request finished without errors CP is server: Request from the client was executed and answered An error has occurred No error has occurred Error number

TRUE FALSE TRUE FALSE

no no

BUSY

OUT

BOOL

no TRUE FALSE TRUE/FALSE no

DONE_NDR

OUT

BOOL

ERROR STATUS STATUS_ FUNC

OUT OUT OUT

BOOL WORD

TRUE FALSE 0 to FFFF Character Character

no no no no

STRING[ Name of the function, which causes the error 8] at STATUS STRING[ Identification for licensing 18] Please order your license with this identification string. BYTE BYTE Unit identification (INPUT if in CLIENT mode, OUTPUT if in SERVER mode) Data type to be accessed: (INPUT if in CLIENT mode, OUTPUT if in SERVER mode) Coils Inputs Holding registers Input registers MODBUS start address (INPUT if in CLIENT mode, OUTPUT if in SERVER mode)

IDENT_CODE OUT

UNIT DATA_TYPE

IN/ OUT IN/ OUT

0 to 255

no no

1 2 3 4 0 to 65535 no

START_ ADDRESS

IN/ OUT

WORD

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

6-6

Function Block MODBUSCP

Parameter LENGTH

Decl. IN/ OUT

Type WORD

Description Number of registers to be processed (INPUT if in CLIENT mode, OUTPUT if in SERVER mode) Coils: reading function writing function Inputs: reading function Holding Register: reading function writing function Input Register: reading function Transaction Identifier (INPUT if in CLIENT mode, OUTPUT if in SERVER mode) INPUT if in CLIENT mode, OUTPUT if in SERVER mode: Write access Read access

Value range

Init no

1 to 2000 1 to 1968 1 to 2000 1 to 125 1 to 123 1 to 125 0 to 65535 no no TRUE FALSE

TI WRITE_ READ

IN/ OUT IN/ OUT

WORD BOOL

General Information

The parameters of the FB MODBUSCP can be divided into two groups: Initialization parameters Runtime parameters

Initialization parameters are evaluated only during the initial execution of the function block MODBUSCP and taken over into the instance DB. They are marked in the above table in the column INIT with yes. A modification of the initialization parameters during run mode has no impact. After a modification of these parameters (e. g. during the test phase), the instance DB must be initialized again via a STOP RUN transition of the CPU. Runtime parameters can by modified during the cyclical operation. In the mode CP is client, it is not advisable to modify the input parameters while a request is active. Wait with the next request and the change of the parameters until the previous request ends with DONE_NDR or ERROR. In the operation mode CP is server, the output parameters may only be evaluated when DONE_NDR is TRUE. The output parameters are displayed dynamically, i.e. they are only available for one PLC cycle. They have to be copied to an additional memory area if you need to process them or to display the values in a VAT (STEP7 variable table). Range of Values For the range of values of the different parameters, CPU specific restrictions must be taken into consideration.

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

6-7

Function Block MODBUSCP

id

For each configured connection in STEP7 (NetPro) a connection ID is assigned. The connection ID identifies unambiguously the connection from the CPU via the CP to the communication partner. The number from the connection configuration has to be entered here. The range of values for this parameter is 1 to 64. The parameter LADDR is the base address of the CP from HW Config (input address). The configured value has to be entered here. The range of values for this parameter depends on the CPU. The parameters ID and LADDR can also be taken from the dialog box Properties of TCP Connection. The monitoring time MONITOR observes the data input from the communication partner. The monitoring time can be set in the format T#.... A monitoring time of approximately 1,5 second is recommended. In the operating mode CP is client MONITOR specifies the timeout for the receipt of the complete response telegram from the server. When the monitoring time elapses, the active request is cancelled with an error. The timer is started after the completed send of the request telegram and is stopped after the receipt of the complete data. In the operating mode CP is server the receipt of the second part of the telegram is monitored with the MONITOR time. When the time elapses an error is reported. The timer is started after the receipt of the MODBUS specific telegram header and is stopped after the receipt of the complete request telegram.

laddr

MONITOR

REG_KEY

The block MODBUSCP must be licensed for each CPU individually to permit a correct program sequence. With the registration key REG_KEY the block MODBUSCP is licensed and the Modbus communication runs without any restraint. You can find further information in section 5 Licensing. This parameter differentiates the client from the server mode. If the input is TRUE, then the operating mode is CP is server. If the input is FALSE, then the operating mode is CP is Client. In operating mode CP is client and single_write = TRUE write requests with length 1 are carried out with the function codes 5 and 6. With single_write = FALSE all write requests use the function codes 15 and 16. The parameter data_type_x defines the MODBUS data type which is to be mapped with this definition. If data_type_x set to 0, this data area is not used. Identifier 0 1 2 3 4 Data type Area not used Coils Inputs Holding Register Input Register Bit Bit Word Word Size

server_client

single_write

data_type_x

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

6-8

Function Block MODBUSCP

db_x

The parameter db_x defines the number of the data block in which the consecutively defined MODBUS registers or bits are mapped. 0 cannot be used as DB number since it is reserved for system functions. db_x DB-Number

1 - 65535 (W#16#0001 to W#16#FFFF)

start_x end_x

Start_x specifies the first register or bit address, which is stored in the data element 0 of the DB. End_x defines the last MODBUS address. When accessing registers, the number of the data element of the S7 DB in which the last register is mapped, can be calculated with the following formula: DBW number = (end_x start_x) 2 When accessing coils or inputs, the number of the data element of the S7 DB in which the last bit is mapped, can be calculated with the following formula: DBB number = (end_x start_x + 7) / 8 The defined memory areas must not overlap. The parameter end_x must not be smaller than start_x. In case of an error occurring, the initialization of the FB is stopped with an error. When start_x is equal to end_x, one Modbus address (1 register or 1 bit) is allocated. In section 6.3 you can find an example of the mapping of the MODBUS addresses to S7 memory areas.

ENQ_ENR

Operating mode CP is client: The data transfer is initiated with a TRUE signal at the input. The request telegram is generated with the values of the input parameters UNIT, DATA_TYPE, START_ADDRESS, LENGTH, TI and WRITE_READ. A new request may only be initiated, when the previous one is ended with DONE or ERROR. Operating mode CP is server: The FB is activated with a TRUE signal at the input. Telegrams from the client can be received. With a FALSE signal at the input data is received from the CP and discarded.

LICENSED

If this output is TRUE, then the Modbus block is licensed on this CPU. If the output is FALSE, none or a faulty license string was typed in. You can find further information in section 5 Licensing. If this output is TRUE, one of the functions AG_SEND or AG_RECV is running.

BUSY

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

6-9

Function Block MODBUSCP

DONE_NDR

In the operating mode CP is client the activated request was executed without error. For a read function the response data from the server has already been entered into the DB. For a write function the response to the request telegram has been received from the server. In the operating mode CP is server this output indicates a telegram exchange without errors. In the parameters UNIT, DATA_TYPE, START_ADDRESS, LENGTH, TI and WRITE_READ the request parameters of the client are displayed. These outputs are only available and valid as long as DONE_NDR is TRUE.

ERROR

When this output is set, an error was recognized. In the operating mode CP is client the activated request was ended with an error. The error number is displayed in the STATUS output. In the operating mode CP is server an error is detected at a request telegram of the client or at sending a response telegram. The error number is displayed in the STATUS output.

STATUS

The STATUS output displays the error number when ERROR is TRUE. The error numbers are described in chapter 7. This parameter shows the name of the function, which caused the error occurred. After start-up of the PLC this parameter displays the identification code, an 18 character string. With this IDENT_CODE you can order the registration key at IT4industry. You can find further information in section 5 Licensing.

STATUS_FUNC

IDENT_CODE

UNIT

In mode CP is client the parameter UNIT is an input parameter. This input has to be set according to the requirements. The FB copies this value to the request telegram and verifies when the respond telegram is received. In mode CP is server the parameter UNIT is an output parameter. The FB copies this value from the request telegram to the respond telegram. The output is set with the received value when the job is finished without error.

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

6-10

Function Block MODBUSCP

DATA_TYPE

The parameter DATA_TYPE defines which Modbus data type is to be accessed with the current job. The following data types are available: Coils Inputs Holding Register Input Register B#16#1 B#16#2 B#16#3 B#16#4

In the operating mode CP is client, DATA_TYPE is an input parameter. In the operating mode CP is server, DATA_TYPE is an output parameter. The different data types are related directly to the used function codes. Data type Coils Coils Coils Coils Inputs Holding Register Holding Register Holding Register Holding Register Input Register START_ADDRESS DATA_ TYPE 1 1 1 1 2 3 3 3 3 4 Function read write write write read read write write write read Length any 1 1 >1 any any 1 1 >1 any single_ write irrelevant TRUE FALSE irrelevant irrelevant irrelevant TRUE FALSE irrelevant irrelevant Function code 1 5 15 15 2 3 6 16 16 4

The parameter START_ADDRESS specifies the first MODBUS address that is read or written. In the operating mode CP is client it is an input parameter, in the operating mode CP is server it is an output parameter.

LENGTH

The parameter LENGTH specifies the number of MODBUS registers or bits that are read or written. In the operating mode CP is client it is an input parameter. In the operating mode CP is server it is an output parameter. For read functions, a maximum of 125 registers or 2000 bits is possible per telegram. For write functions a maximum of 123 registers or 1968 bits is possible. All registers or bits have to be in the same DB per telegram.

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

6-11

Function Block MODBUSCP

TI

The parameter TI, Transaction Identifier is copied by the server from the request telegram to the respond telegram according to the MODBUS specification. In the operating mode CP is client it is an input parameter. The FB copies this value to the request telegram and verifies when the respond telegram is received. In the operating mode CP is server it is an output parameter. The FB copies this value from the request telegram to the respond telegram. The Transaction Identifier is used for identification of telegrams, respectively the distinct correlation of request and respond. The FB MODBUSCP can only do this correlation if the TI is changed with each transaction. A changed TI can only solve some special situations caused by TCP. A reliable operation of the FB can be obtained with a changed TI. Therefore we recommend to increment the TI by 1 with any request.

WRITE_READ

This parameter defines if a read or write function should be carried out. If the value of the input/output is FALSE, it specifies the read mode. The value TRUE specifies the write mode. Only Holding Registers and Coils can be written. Input Registers and Inputs can be read merely. In the operating mode CP is client it is an input parameter. In the operating mode CP is server it is an output parameter.

6.3

Address Mapping
Interpretation of Modbus Addresses MODBUS bases its data model on a series of tables, which have distinguishing characteristics. The distinction between these memory areas is done via the register address by some systems, e.g. MODICON PLCs. So a MODBUS message requesting the read of a holding register at offset 0 would return the value known to the application programmer as found in register 40001 (memory type 4xxxx, reference 0001). One potential source of confusion is the varying interpretation of the register address in different manuals. Sometimes the register address means the address of the application layer, sometimes the address transferred. The FB MODBUS uses the Modbus address transferred at its parameters start_x und START_ADDRESS. So it is possible to use register addresses from von 0000H to FFFFH with each function code.

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

6-12

Function Block MODBUSCP

Example: Parameterization of the Memory Areas

data_type_1 db_1 start_1 end_1 data_type_2 db _2 start _2 end _2 data_type_3 db _3 start _3 end _3 data_type_4 db _4 start _4 end _4 data_type_5 db _5 start _5 end _5 data_type_6 db _6 start _6 end _6 data_type_7 db _7 start _7 end _7 data_type_8 db _8 start _8 end _8

B#16#3 W#16#B W#16#1 W#16#1F4 B#16#3 W#16#C W#16#2D0 W#16#384 B#16#4 W#16#D W#16#2D0 W#16#3E8 B#16#0 0 0 0 B#16#1 W#16#E W#16#280 W#16#4E2 B#16#2 W#16#F W#16#6A4 W#16#8FC B#16#1 W#16#10 W#16#6A4 W#16#8FC B#16#0 0 0 0

Holding Register DB 11 Start address: 1 End address: 500 Holding Register DB 12 Start address: 720 End address: 900 Input Register DB 13 Start address: 720 End address: 1000 Not used 0 0 0 Coils DB 14 Start address: 640 End address: 1250 Inputs DB 15 Start address:1700 End address: 2300 Coils DB 16 Start address: 1700 End address: 2300 Not used 0 0 0

Address Mapping

The following diagram shows the comparison of the SIMATIC memory area and the Modbus typical register oriented storage arrangement. The diagram is based on the above parameterization. The Modbus addresses printed in black refer to the Data Link Layer, the ones printed in grey refer to the Application Layer. The SIMATIC addresses printed in black are the offset in the DB. You can find additionally the Modbus register numbers printed in grey.

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

6-13

Function Block MODBUSCP

SIMATIC
DB 14 + 0.0 + 0.1 ... +76.2 DB 16 + 0.0 + 0.1 ... +74.7 +75.0 DB 15 + 0.0 + 0.1 ... +74.7 +75.0 DB 13 + 0.0 + 2.0 ... +560.0 DB 11 + 0.0 + 2.0 ... +996.0 +998.0 DB 12 + 0.0 + 2.0 ... +358.0 +360.0 899 900 900 901 720 721 720 499 500 1 2 1000 720 721 2299 2300 1700 1701 0 2299 2300 1700 1701 1250 640 641

Modbus device
Coils (from 00001) 0 00001 ... 640 641 00641 00642 ... 1250 01251 ... 1700 01701 ... 2300 Inputs (from 10001) 10001 ... 1700 1701 11701 11702 ... 2300 2301 12301 12302 Input Register (from 30001) 0 1 30001 30002 ... 720 721 30721 30722 ... 1000 Holding Register (from 40001) 0 1 40001 40002 ... 499 500 501 40500 40501 40502 ... 40721 ... 40901 40902 1001 31001 31002 2301 02301 02302

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

6-14

Function Block MODBUSCP

6.4

Data and Standard Functions used by the FB


Instance DB The function block MODBUSCP stores its data in an instance DB. This instance DB is created by STEP7 at the first call of the FB. The instance data block contains parameters of type Input, Output, Input/Output as well as static variables that it needs for its execution. These variables are non-volatile and keep its validity between FB calls. The variables control the internal process flow of the FB. Required memory of the instance-DBs: Instance-DB MODBUSCP Local Variables work memory ca. 1kByte load memory ca. 2kByte

The FB requires 80 Bytes of local variables. Additionally the subordinate FBs require local variables: FBs MB_CPCLI (30 byte) or MB_CPSRV (30 byte). V1.x: AG_SEND/AG_RECV or AG_LSEND/AG_LRECV require, up to 58 bytes, depending on the used function block. That gives a maximum of 168 bytes of local data for a FB MODBUSCP V1.x-call. V2.x: The function AG_CNTRL requires 178 bytes local data. That gives a maximum of 288 bytes of local data for a FB MODBUSCP V2.x-call. The function block does not use any timer. The function block does not use any flag. The function blocks MB_CPCLI and MB_CPSRV respectively called by FB MODBUSCP use the blocks AG_SEND/AG_RECV (S7-300) and AG_LSEND/AG_LRECV (S7-400) from the SIMATIC_NET library for the data transfer between CPU and CP. The blocks MODCLI and MODSRV version 2.x use the block AG_CNTRL additionally to reset and reestablish the connection in case of error. The following versions of the FCs are tested with FB MODBUSCP and released for the communication: S7-300: FC5 AG_SEND version 4.2 FC6 AG_RECV version 4.7 AG_CNTRL version1.0 FC50 AG_LSEND version 3.0 FC60 AG_LRECV version 3.0 AG_CNTRL version 1.0

Timers Flags Standard FCs for Data Transfer

S7-400

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

6-15

Function Block MODBUSCP

MODBUSCP: SFCs for Miscellaneous Functions

The FB MODBUSCP uses the following SFBs/SFCs from the standard library: FC10 EQ_STRING

SFB4 TON SFC6 RD_SINFO SFC20 BLKMOV SFC51 RDSYST SFC52 WR_USMSG

MB_CPCLI and MB_CPSRV: SFCs for Miscellaneous Functions

The FBs MB_CPCLI and MB_CPSRV use the following SFCs from the standard library: SFC20 BLKMOV SFC24 TEST_DB SFB4 TON

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

6-16

Function Block MODBUSCP

6.5

Renaming of Standard Functions


Inducement Whether you have already used the numbers of standard functions in your project or the block number is reserved for a different application, you may rename the internal called functions AG_SEND/AG_RECV or AG_LSEND/AG_LRECV or the blocks MODBUSCP, MB_CPCLI and MB_CPSRV. It is not possible to rename the system functions SFC6, SFC20, SFC24, SFC51 and SFC52 as well as the system function block SFB4. Behavior A set of rules concerning the function block numbering have to be considered when rewiring function blocks in SIMATIC STEP 7 Manager: When rewiring a function block make sure that the previous function blocks in the call hierarchy have descending numbers. Exemplification: The call hierarchy in MODBUSCP:
FC5 AG_SEND FB106 MB_CPCLI FB108 MODBUSCP FB107 MB_CPSRV FC50 AG_LSEND FC6 AG_RECV FC60 AG_LRECV FC AG_CNTRL

Rewiring FC5 is possible:


FB108 MODBUSCP FB106 MB_CPCLI FC5 AG_RECV

Internally, function block FB108 calls the function block FB106, which then calls FC5. In this line-up it is possible to rewire FB65 since it is called by MB_CPCLI (FB106) which has a smaller function block number than MODBUSCP (FB108).

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

6-17

Function Block MODBUSCP

Rewiring FC5 is not possible:


FB99 MODBUSCP FB106 MB_CPCLI FC5 AG_RECV

Precondition: The block MODBUSCP was renamed to first to e.g. FB99. Internally, function block FB99 calls function block FB106, which then calls FC5. In this line-up it is not possible to rewire FC5, since the function block MB_CPCLI (FB106) has a higher function block number than MODBUSCP (FB99). Solution: If blocks are to be rewired, it is recommended to start with the low-level instance (e.g. FC5). The following rule applies: The block of the first instance needs a larger block number than the one of the second instance, so that the block of the third instance can be renamed. Renaming To rename the blocks proceed as described subsequently: 1. Get the information about the used operand by clicking "Extras > Reference data > Display". 2. Set the operand priority in the object properties of the block folder to "Absolute value". 3. Call the function "Extras > Re-wire" in the SIMATIC Manager, in order to re-wire the operands into free areas. 4. To be able to keep on using the symbolism diagnostics tools, add the modifications in the symbolism table supplementary.

The modifications can be verified by clicking "Extras > Reference data > Display".

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

6-18

Diagnostics

Diagnostics
The diagnostic functions of the CP 343/ CP 443 allow you fast failure localization. The following diagnostic features are available: Diagnostics via the display elements of the CP Diagnostics via the STATUS output of the function block MODBUSCP.

Diagnostic Function

Display Elements (LED)

The display elements inform you about the operating mode or about the failure conditions of the CP. The display elements give you an overview of internal failures, external failures and interface specific failures. For error diagnostics, the function block MODBUSCP has got a STATUS output. By reading the STATUS output you get a general indication of failures that have occurred during the communication. The STATUS parameter can be evaluated in the user program. The output STATUS_FUNC shows the name of the function, which has caused the error.

STATUS Output of the FB MODBUSCP

7.1

Diagnostics via the Display Elements of the CP


Display Functions The display elements of the CP give you information on the module status. There are two types of display functions: Group Error Displays - INTF Internal failure - EXTF External failure Special Displays CP 343-1: - RX/TX A telegram is being transmitted via the interface. CP 443-1: - TXD A telegram is being sent via the interface. - RXD A telegram is being received via the interface. A detailed description of the display elements can be found in the device manual of the CP.

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

7-1

Diagnostics

7.2

Verification by the FB MODBUSCP


During start up Parameter group data_type_x, db_x, start_x, end_x (x = 1 to 8) 1. With data_type_x = 0 the register area is disabled and not verified further. At least the first area (_1) must be enabled. 2. Validity check of data_type_x 3. Check of db_x <> 0 4. Test end_x >= start_x 5. Modbus addresses with the same data type that are defined in two DB_x lead to an error message (overlap). Errors during start up provoke the ERROR bit to remain set. In the cyclical operation no requests are executed. A correction of the parameterization and a STOP RUN transition of the CPU are necessary. Cyclical Operation CP is Client Verification when the FB is called: Valid registration key Range of values MONITOR Range of values START_ADDRESS Range of values LENGTH At the execution of a request, it is checked whether the data block that is specified by the Modbus register or bit address is available and has the necessary length. The DB number must not be 0 and/or identical to the number of the instance DB. Receipt of the response telegram within the monitoring time The monitoring time can also elapse if less data than specified in the MODBUS telegram header is received. Subsequent failures with loss of telegrams can occur.

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

7-2

Diagnostics

Verification in the response telegram: Received transaction identifier is equal to the sent one. Protocol identifier = 0 Length is between 3 and 253 Besides the length in the header of the response telegram is checked for plausibility regarding the request. UNIT sent is equal to the received one FC sent is equal to the received one Response is an Exception Code Telegram For write requests it is verified that start address and number of registers/bits match with the request telegram. FC 5 or FC6: Echo in the respond is equal to the request Valid registration key Receipt of the second part of the request telegram within the monitoring time The monitoring time also can elapse if less data than specified in the MODBUS telegram header is received. Subsequent failures can occur with loss of telegrams. Protocol Identifier = 0 Length between 6 and 207 Received FC is verified. If the FC is not equal to 1, 2, 3, 4, 5, 6, 15 or 16 an exception telegram is sent. For write requests, the length in the header, the number of registers/bits and the byte count in the telegram must match. The number of registers/bits is verified. If the number is too large an exception telegram is sent. Access to write protected area: Send exception telegram At the execution of a request, it is checked whether the data block that is specified by the modbus address is present and has the necessary length. The DB number must not be 0 and/or identical to the number of the instance DB. In case of an error an exception telegram is sent.

Cyclical Operation CP is Server

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

7-3

Diagnostics

Lost Synchronization

The lost synchronization described below can only occur when the communication partner has extreme malfunctions or there are serious interferences on the transmission line. In order to read a MODBUS specific telegram header, the function block MODBUSCP starts an AG_RECV with 6 bytes length. With the length in the telegram header another AG_RECV is started. If the length in the telegram header is not equal to the actual number of bytes sent to the CP (which is a serious failure), the CP resolves this situation as follows: 1. More data as specified in the header is received: The next AG_RECV gets data that are not compliant with the MODBUS specific header. This leads to after effects like wrong TI or PI, data is interpreted as a length specification, the length used by FB/AG_RECV is wrong. 2. Less data as specified in the header is received: The activated AG_RECV returns no ready signal and the monitoring time MONITOR elapses. The activated AG_RECV has only received a part of the data, therefore it is still in the receiving state. This AG_RECV cannot be cancelled. More data has to be received in order to be synchronized again. In operating mode CP is client the request of the FB MODBUSCP is cancelled with ERROR. Another FB request can be activated. The response data is received with the old AG_RECV. Receiving must continue until the expected amount of data has been received. Multiple requests, which all end with the status monitoring time elapsed, might be necessary to regain synchronization. In the operating mode CP is server the expected amount of data must be reached with request telegrams of the client. Multiple error messages No response from server might occur at the client. When the old AG_RECV ends, the FB reads a single byte in order to receive a possible telegram fragment from the CP. The reading is observed with the monitoring time MONITOR as well. When the monitoring time elapses it is assumed that the synchronization has been regained. The normal operation of the FB MODBUSCP is continued. 3. The announced amount of data does not match the request telegram (CP is client): The FB MODBUSCP receives the announced amount of data and ignores it. ERROR and STATUS return an error code. The above mentioned function of the FB is necessary because neither the TCP/IP connection nor the activated AG_RECV can be cancelled.

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

7-4

Diagnostics

7.3

Diagnostic Messages of the FB MODBUSCP


Messages at the STATUS Output of the FB The block MOBUSCP has got 2 status outputs: STATUS and STATUS_FUNC. STATUS displays all error numbers. STATUS_FUNC shows the name of the function, which caused the error. STATUS is valid when ERROR is TRUE. Below you can find a list of FB-specific error messages. The FB MODBUSCP, MB_CPCLI and MB_CPSRV use the standard functions SFC6, SFC20, SFC24, SFC51, SFC52, FC5 and FC6, or FC50 and FC60. The error messages of these blocks are passed on to STATUS without any changes. In the diagnostics buffer or in the online help of SIMATIC Manager you will find further details on these error messages, as well as in the SIMATIC STEP7 NCM S7 Industrial Ethernet Manual. Error messages of FB MODBUSCP STATUS Event text
(Hex)

Error Messages of the called SFCs and FCs

Remedy Correct the parameterization of start_x and end_x Extend the DB. CP is Client: Correct the parameters START_ADDRESS or LENGTH CP is Server: Modify the request of the client.

A002 A003

The parameter end_x is less than start_x. The DB, to which MODBUS addresses shall be mapped, is too short. Minimum length: registers: ( end_x start_x + 1 ) 2 bits: ( end_x - start_x ) / 8 + 1 Other possible reasons: Wrong initialization parameter (CP is client) Wrong address area in the request telegram of the client (CP is server)

A004

Applies only with CP is client: An invalid combination of DATA_TYPE and WRITE_READ is given. CP is client: An invalid value for the parameter LENGTH is given. CP is Server: The number of registers/bits in the request telegram is invalid. The CP sends an exception telegram. Range of values: Read coils/inputs: 1 to 2000 Write coils: 1 to 1968 Read registers: 1 to 125 Write holding registers: 1 to 123

Correct the parameters. Only data type 1 or 3 can be written. CP is Client: Correct the parameter LENGTH. CP is Server: Modify the number of registers/bits in the request telegram.

A005

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

7-5

Diagnostics

Error messages FB MODBUSCP STATUS Event text


(Hex)

Remedy CP is Client: Correct the parameters combination DATA_TYPE, START_ADDRESS and LENGTH. CP is Server: Modify the request of the client or correct the parameterization of data_type_x. Correct the parameterization.

A006

The given range of data defined with DATA_TYPE, START_ADDRESS and LENGTH does not exist in data_type_1 to data_type_8. CP is server: The CP sends an exception telegram.

A007

CP is client: An invalid monitoring time MONITOR is parameterized. A value > 20ms is required. Monitoring time MONITOR elapsed when AG_RECV waits for receipt. E.g. Partner is not ready.

A008

Verify error messages at the communication partner.

MODBUSCP V2.x: Check if the communication All connections via Port 502 are terminated and partner needs a special unit reestablished. identifier. MODBUSCP V1.x: As an after effect the loss of synchronization can occur, which leads to a loss of telegrams. A009 CP is client: The received transaction identifier TI is not equal to the sent one. MODBUSCP V2.x: All connections via Port 502 are terminated and reestablished. CP is client: The received UNIT is not equal to the sent one. MODBUSCP V2.x: All connections via Port 502 are terminated and reestablished. CP is client: Received function code is not equal to the sent one. CP is server: An invalid function code was received. The CP sends an exception telegram. MODBUSCP V2.x: All connections via Port 502 are terminated and reestablished. MODBUSCP V1.x: As an after effect the loss of synchronization can occur, which leads to a loss of telegrams. A00C The received byte count does not match the number of registers/bits. CP is server: The CP sends an exception telegram. MODBUSCP V2.x: All connections via Port 502 are terminated and reestablished. Only when CP is client: The register/bit address or the number of registers/bits in the response telegram is not equal to the one in the request telegram. CP is client: Verify the data of the communication partner with the help of a telegram trace. CP is server: The FB MODBUSCP supports the function codes 1, 2, 3, 4, 5, 6, 15 and 16. Verify the data of the communication partner with the help of a telegram trace.

A00A

A00B

Verify the data of the communication partner with the help of a telegram trace.

A00D

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

7-6

Diagnostics

Error messages the FB MODBUSCP STATUS Event text


(Hex)

Remedy

A00E

The length indicated in the MODBUS specific telegram Verify the data of the communication partner with the header does not match the number of registers/bits or the byte count in the telegram. The FB receives all data help of a telegram trace. and ignores them. MODBUSCP V2.x: All connections via Port 502 are terminated and reestablished. MODBUSCP V1.x: As an after effect a loss of synchronization might occur. A protocol identifier <> 0 was received. MODBUSCP V2.x: All connections via Port 502 are terminated and reestablished. MODBUSCP V1.x: As an after effect a loss of synchronization might occur. In the parameterized area db_1 to db_8 a DB number is Correct the parameterization of used twice. db_x. An invalid value for DATA_TYPE is given (Value range: Correct the parameters. 1 to 4). The parameterized areas data_type_1 and data_type_2 Correct the parameterization. overlap. The data areas must not contain The parameterized areas data_type_1 and data_type_3 any overlapping register areas. overlap. The parameterized areas data_type_1 and data_type_4 overlap. The parameterized areas data_type_1 and data_type_5 overlap. The parameterized areas data_type_1 and data_type_6 overlap. The parameterized areas data_type_1 and data_type_7 overlap. The parameterized areas data_type_1 and data_type_8 overlap. 0 is assigned to one of the parameters db_x while the according data_type_x is <> 0. DB 0 cant be used; it is reserved for system functions. Wrong length in header: Range of values: 3 to 253 bytes. MODBUSCP V2.x: All connections via Port 502 are terminated and reestablished. Correct the parameterization of db_x to > 0. Verify the data of the communication partner with the help of a telegram trace.

A00F

A010 A011 A012 A013 A014 A015 A016 A017 A018 A019

A01A

A01B

CP is server and function code 5: An invalid value for coils was received. The CP sends an exception telegram.

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

7-7

Diagnostics

Error messages of FB MODBUSCP STATUS Event text


(Hex)

Remedy Check the error message of the communication partner and verify the data with a telegram trace if needed.

A01E

The CP has received invalid data which could not be assigned. MODBUSCP V2.x: All connections via Port 502 are terminated and reestablished. MODBUSCP V1.x The CP has lost synchronization and needs data from the communication partner to finish the active AG_RECV.

A01F A023 A024 A025 A026 A027 A028 A034 A035 A036 A037 A038 A045 A046 A047 A048 A056 A057 A058

The FB MODBUSCP has turned to an invalid state. The parameterized areas data_type_2 and data_type_3 overlap. The parameterized areas data_type_2 and data_type_4 overlap. The parameterized areas data_type_2 and data_type_5 overlap. The parameterized areas data_type_2 and data_type_6 overlap. The parameterized areas data_type_2 and data_type_7 overlap. The parameterized areas data_type_2 and data_type_8 overlap. The parameterized areas data_type_3 and data_type_4 overlap. The parameterized areas data_type_3 and data_type_5 overlap. The parameterized areas data_type_3 and data_type_6 overlap. The parameterized areas data_type_3 and data_type_7 overlap. The parameterized areas data_type_3 and data_type_8 overlap. The parameterized areas data_type_4 and data_type_5 overlap. The parameterized areas data_type_4 and data_type_6 overlap. The parameterized areas data_type_4 and data_type_7 overlap. The parameterized areas data_type_4 and data_type_8 overlap. The parameterized areas data_type_5 and data_type_6 overlap. The parameterized areas data_type_5 and data_type_7 overlap. The parameterized areas data_type_5 and data_type_8 overlap.

Please contact the product support. Correct the parameterization. The data areas must not contain any overlapping register areas.

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

7-8

Diagnostics

Error messages of FB MODBUSCP STATUS Event text


(Hex)

Remedy Correct the parameterization. The data areas must not contain any overlapping register areas.

A067 A068 A078 A07A A07C A07D A07E A080

The parameterized areas data_type_6 and data_type_7 overlap. The parameterized areas data_type_6 and data_type_8 overlap. The parameterized areas data_type_7 and data_type_8 overlap.

An invalid value id is parameterized. Range of values is Correct the parameterization of 1 to 64. the input id. An invalid value data_type_x was given. The value range is 0 to 4. Parameter data_type_1 is not defined. The parameter area _1 is the default area and must be defined. The DB number of db_x is identical to the number of the instance DB. Different instance DBs were used for the call of MODBUSCP in OB100 and the cyclic OB. Only if CP is client and function code 5: The received coil status is not equal to the sent one. Correct the parameterization of data_type_x. Correct the parameterization of data_type_1. Correct the parameterization of db_x. MODBUSCP must be called with the identical instance DB in OB100 and the cyclic OB. Verify the data of the communication partner with the help of a telegram trace.

A081

A082

Only if CP is client and function code 6: Verify the data of the The received register value is not equal to the sent one. communication partner with the help of a telegram trace. Only if CP is client: A request was initiated prior to the completion of the previous one. The request is not executed. Wait with the initiation of a new request until the previous one was finished either with DONE/NDR = TRUE or ERROR = TRUE.

A083

A085

An error occurred during the license handling due to an Verify the project if there is any invalid write access. invalid write access to the license DB. The structure of REG_KEY must not be changed. Please contact the Product Support if necessary. The block MODBUSCP is not licensed for this CPU. This is a status information. The bit ERROR is not set. The Modbus communication runs without a license as well. Read the identification string IDENT_CODE for this CPU and order the registration key at IT4industry. See also section 5 Licensing.

A090

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

7-9

Diagnostics

Error messages of FB MODBUSCP STATUS Event text


(Hex)

Remedy The communication partner does not support the requested function. Correct LENGTH or START_ADDRESS at the call of the FB. The communication partner cant process the received request (e.g. doesnt support the requested length). The communication partner is in a state, in which the received request cant be processed. Check the error message of the communication partner and verify the data with a telegram trace if needed.

A091

An exception telegram with exception code 1 was received (only if CP is client) An exception telegram with exception code 2 was received (only if CP is client) An attempt to an invalid or non existing address at the communication partner was made.

A092

A093

An exception telegram with exception code 3 was received (only if CP is client)

A094

An exception telegram with exception code 4 was received (only if CP is client) An exception telegram with an unknown exception code was received (only if CP is client).

A095

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

7-10

Diagnostics

7.4

Diagnostic Messages of FC5/FC6 and FC50/FC60


Diagnostic messages of the included blocks AG_SEND/AG_RECV (FC5/FC6) and AG_LSEND/AG_LRECV (FC50/FC60) at the output STATUS STATUS Event text
(Hex)

Remedy See online help (SIMATIC manager -> mark block -> key F1 > Ethernet -> see also -> code evaluation ) See online help (SIMATIC manager -> mark block -> key F1 > Ethernet -> see also -> code evaluation )

7xxx

For detailed information please refer to the online help of SIMATIC Manager.

8xxx

For detailed information please refer to the online help of SIMATIC Manager.

7.5

Diagnostic Messages of included FCs/SFCs


Diagnostic messages of the included blocks RD_SINFO (SFC6), BLKMOV (SFC20) , SFC51 (RDSYSST), SFC52 (WR_USMSG) and AG_CNTRL at the output STATUS STATUS Event text
(Hex)

Remedy See online help (SIMATIC manager -> mark block -> key F1) See online help (SIMATIC manager -> mark block -> key F1)

7xxx 8xxx

For detailed information please refer to the online help of SIMATIC Manager. For detailed information please refer to the online help of SIMATIC Manager.

7.6

Diagnostic Messages of SFC24


Error messages of SFC24 STATUS Event text
(Hex)

Remedy Choose a valid DB number. All data blocks that are specified in db_x must be created and copied into the CPU. DB must not be created as UNLINKED.

80A1 80B1

DB Number = 0 or too large for the CPU The DB does not exist in the CPU.

80B2

DB UNLINKED

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

7-11

Application Sample

Application Samples
With the installation 2 sample projects are installed in \Program Files\Siemens\Step7\Examples. sample project MB_TCP_CP written in STL and sample project MB_TCP_CP_CFC written in CFC

General Information

The S7 programs are for information purposes only and are not to be understood as a solution for a customer specific installation configuration.

Programming Example

The programming examples consist of the blocks: Start-Up OB100 Programming error OB121 Cyclic program processing OB1 and OB35 respectively with call of FB 108 Global DB for job trigger (e.g. via a variable table) and for licensing Data blocks for register values

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

8-1

Application Sample

8.1

Sample project STL


General Information The sample project written in STL includes serveral Simatic stations for the different applications. Simatic Station is S7-300 or S7-400 Simatic Station is client or server Simatic Station supports or doesnt support AG_CNTRL

Used Blocks

The subsequent listed blocks are used in the provided example project for S7 stations with FB MODBUSCP. Block
OB 1 OB 100 OB 121 FB 108 FB 106 FB 107 DB 1 DB 3 DB 11 DB 12 DB 13 DB 14 DB 15 DB 16 DB 108

Symbol
CYCL_EXC COMPLETE RESTART PROG_ERR MODBUSCP MB_CPCLI MB_CPSRV CONTROL_DAT LICENSE_DB DATA_AREA_1 DATA_AREA_2 DATA_AREA_3 DATA_AREA_5 DATA_AREA_6 DATA_AREA_7 IDB_MODBUS

Comment
Cyclic program processing Start-Up OB for Re-Start Programming error OB User block FB MODBUSCP Internally called FB MB_CPCLI Internally called FB MB_CPSRV Work-DB CONTROL DAT for FB MODBUSCP License DB for FB MODBUSCP Value DB for area 1 Value DB for area 2 Value DB for area 3 Value DB for area 5 Value DB for area 6 Value DB for area 7 Instance DB for FB MODBUSCP

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

8-2

Application Sample

8.2

Sample project CFC


General Information The sample project written in CFC includes two Simatic S7-400 stations, one is parameterized as client, the other one as server.

Used Blocks

The subsequent listed blocks are used in the provided example project with FB MODBUSCP. The system functions, system function blocks and the blocks which are generated by CFC are not listed in the following table. Block
OB 35 OB 100 OB 121 FB 8 FB 24 FB 99 FB 106 FB 107 FB 108 FC 100 FC 500 FC 600 DB1 DB 3 DB 11 DB 12 DB 13 DB 14 DB 15 DB 16

Symbol
CYC_INT5 COMPLETE RESTART PROG_ERR R_TRIG CTU Save_STATUS MB_CPCLI MB_CPSRV MODBUSCP EQ_STRNG AG_LSEND AG_LRECV MEMORY_DB LICENSE_DB DATA_AREA_1 DATA_AREA_2 DATA_AREA_3 DATA_AREA_5 DATA_AREA_6 DATA_AREA_7

Comment
Cyclic program processing Start-Up OB for Re-Start Programming error OB Recognition of positive edge Upwards counter FB to save the error number and the name of the according function Internally called FB MB_CPCLI Internally called FB MB_CPSRV User block FB MODBUSCP Equal string FC to send data FC to receive data Help DB in server mode License DB for FB MODBUSCP Value DB for area 1 Value DB for area 2 Value DB for area 3 Value DB for area 5 Value DB for area 6 Value DB for area 7

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

8-3

A Literature
MODBUS IDA MODBUS APPLICATION PROTOCOL SPECIFICATION V1.1b, December 28, 2006

http://www.modbus-IDA.org

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

Appendix - 1

Glossary

A
Address The address identifies a physical storage location. If the address is known, the operand stored there can be directly accessed. An automation system is a programmable logic controller that contains at least a CPU, different input and output devices as well as HMI devices.

Automation System

B
Baud Rate Block Call - > transmission rate A block call occurs when program processing branches to the called block Block parameters are variables within multiple-use blocks, which are replaced with actual values when the relevant block is called. Blocks are elements of the user program which are defined by their function, structure, or purpose. With STEP7 there are Bus Segment Code blocks (FB, FC, OB, SFB, SFC) Data blocks (DB, SDB) User-defined data types (UDT)

Block Parameter

Blocks

Part of a -> subnet. Subnets can consist of bus segments and connectivity devices such as repeaters and bridges. Segments are transparent for addressing.

C
Client A client is a device or, in general terms, an object that requests a service from a -> server. Communications processors are modules for point-to-point connections and bus connections. The configuration is the set up of individual modules of the PLC in the configuration table.

Communications Processor

Configuration

Connection Parameterization The specification of a connection ID in the system function block. With the help of a connection ID the system function blocks can communicate between two communication points. CP Communications Processor. Module for communications tasks.

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

CPU

Central processing unit of the S7 programmable logic controller with control and arithmetic unit, memory, operating system, and interfaces to I/O modules. Cyclic Redundancy-Check = Checksum which guarantees a high probability of error recognition. The cycle time is the time the CPU needs to execute the user program once. In cyclic program processing, the user program is executed in a constantly repeating program loop, called a cycle.

CRC

Cycle Time

Cyclic Program Processing

D
Data Block (DB) These are blocks containing data and parameters with which the user program works. Unlike all other blocks, data blocks do not contain instructions. They are subdivided into global data blocks and instance data blocks. The data held in the data blocks can be accessed absolutely or symbolically. Complex data can be stored in structured form. Data types allow users to define how the value of a variable or constant is to be used in the user program. They are classified into elementary and structured data types. The default setting is a basic setting which is always used if no other value is specified. Every CPU has a diagnostic buffer, in which detailed information on diagnostic events are stored in the order in which they occur. Diagnostic events are, for example, errors on a module or system errors in the CPU, which are caused by, say, a program error or by operating mode transitions. The diagnostics functions cover the entire system diagnosis and include detection, analysis and reporting of errors within the automation system. Downloading means loading objects (e.g. code blocks) from the programming device into the load memory of the CPU.

Data Type

Default Setting

Diagnostic Buffer

Diagnostic Event

Diagnostic Functions

Download

F
Function Block (FB) Function blocks are components of the user program and, in accordance with the IEC standard, are blocks with memory. The memory for the function block is an assigned data block, a so called instance data block. Function blocks can be parameterized but can also be used without parameters.

H
Hardware Hardware is the term given to all the physical and technical equipment of a PLC.

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

I
Industrial Ethernet Instance Data Block A LAN system complying with IEEE 802.3 (ISO 8802-2) An instance data block is a block assigned to a function block and contains data for this special function block. On the interface module the physical conversion of signals takes place. By exchanging the pluggable interface module you can adapt the communications processor to the physical interface of the communications partner. Interrupt is a name for a break of the program processing in the processor of an automation system by an external alarm.

Interface Module

Interrupt

M
MAC-Address Address to distinguish between different stations connected to a common transmission medium (Industrial Ethernet).

Media Access Control (MAC) Mechanisms for controlling access by a station to a common transmission medium shared with other stations. Module Modules are pluggable printed circuit boards for programmable logic controllers Module parameters are used to set the module behaviors. A distinction is made between static and dynamic module parameters.

Module Parameters

N
NCM S7 for Industrial Ethernet Configuration software for configuration and diagnostic functions on an Ethernet CP.

O
Online / Offline Online means that a data connection exists between PLC and programming device. Offline means that no such data connection exists. STEP7 allows you to display contextual help texts on the screen while working with the programming software. An operand is part of a STEP7 instruction and states with what the processor is to do something. It can be both absolutely and symbolically addressed. The SIMATIC S7 programmable controllers have three different operating modes: STOP, START UP and RUN. The functionality of the CPUs varies in the individual operating modes. The operating system of the CPU organizes all functions and operations of the CPU which are not connected to a specific control task.

Online Help

Operand

Operating Mode

Operating System of the CPU

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

P
Parameter Parameters are values that can be assigned. A distinction is made between block parameters and module parameters. Parameterization means setting the behavior of a module. The execution of a data interchange operation according to a specific protocol is called a procedure. This is a special memory area in the PLC. At the beginning of the cyclic program, the signal states of the input modules are transferred to the process image input table. At the end of the cyclic program, the process image of the outputs is transferred to the output modules as output signals. The communications partners involved in a data interchange must abide by fixed rules for handling and implementing the data traffic. These rules are called protocols.

Parameterization Procedure

Process image

Protocol

R
Rack A rack is a rail containing slots for mounting modules.

S
Server A server is a device, or in general terms, an object that provides certain services. A service is started at the instigation of a -> client. Software is the term given to all programs used on a computer system. These include the operating system and the user programs. The operating mode START UP is active when the CPU transits from operating mode STOP to operating mode RUN. STEP7 is the programming software of SIMATIC S7. A subnet is part of a -> network whose parameters must be matched. The subnet includes bus components and all the attached stations. Subnets can, for example, be connected together by -> gateways to form a network. A system consists of several subnets with unique subnet numbers. A subnet consists of several stations with unique -> MAC addresses. System blocks differ from the other blocks in that they are already integrated into the S7-400 system and are available for already defined system functions. They are classified into system data blocks, system functions, and system function blocks. System functions are software modules without memory which are already integrated into the operating system of the S7-CPU and can be called by the user as required.

Software

START UP

STEP7 Subnet

System Block

System Function (SFC)

System Function Block (SFB) System function blocks are software modules with memory which are already integrated into the operating system of the S7-CPU and can be called up by the user as required.

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

T
Tool A tool is a piece of software that is capable of accessing operating system functions in a programming device. According to DIN 44302, this is the number of binary decisions transmitted per time unit. The unit is bps. he set or selected transmission rate depends on various conditions, for example the distance across

Transmission Rate

U
Upload Uploading means loading objects (e.g. code blocks) from the load memory of the CPU into the programming device. The user program contains all instructions and declarations for signal processing, by means of which a system or a process can be controlled. The user program for SIMATIC S7 is structured and is divided into smaller units called blocks.

User Program

V
Variable A variable is an operand (e.g. E 1.0) which can have a symbolic name and can therefore also be addressed symbolically.

W
Work Memory The work memory is a RAM on the CPU which the processor accesses while processing the user program.

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

Customer Support
Siemens AG Industry Sector I IS IN E&C Werner-von-Siemens-Str. 60 91052 Erlangen Tel: ++49 9131 7-46111 Fax: ++49 9131 7-44757 Mail: it4.industry@siemens.com
http://www.siemens.com/s7modbus

Siemens Aktiengesellschaft

Subject to change without prior notice.

Stand: 02/2010

OPEN MODBUS / TCP communication via CP343-1 and 443-1 2XV9450-1MB00; Manual edition 4.1

Das könnte Ihnen auch gefallen