Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014....

68
A documentation by: Siemens. © Siemens AG 2014. All rights reserved. Modbus TCP/IP PCS 7 driver blocks Documentation Driver block library for the SIMATIC S7-400 or S7-400H / PCS7 automation systems for coupling with a Modbus slave via TCP/IP Version: 2.3

Transcript of Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014....

Page 1: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

Modbus TCP/IP PCS 7 driver blocks

Documentation Driver block library for the SIMATIC S7-400 or S7-400H / PCS7 automation systems for coupling with a Modbus slave via TCP/IP

Version: 2.3

Page 2: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

Documentation | Modbus TCP/IP PCS 7 driver blocks | 2

Table of contents

1 System requirements ............................................................................ 5

1.1 License ............................................................................................... 5

1.2 Software ............................................................................................ 5

1.3 Hardware ........................................................................................... 5

2 General information .............................................................................. 6

2.1 Step 7 block library ............................................................................ 6

2.2 Supported functionalities .................................................................. 6

2.3 Communication principle ................................................................... 6

2.4 Quantity structure ............................................................................. 8

2.5 Performance ...................................................................................... 8

2.6 Communication blocks used ............................................................ 11

3 Configuring the hardware ................................................................... 12

3.1 General configuration instructions .................................................. 12

3.2 HW Config ........................................................................................ 12

3.3 NetPro-Config .................................................................................. 15

4 Description of the function blocks ....................................................... 18

4.1 MODTCP_COMRED/_T – communication block .................................. 18

4.1.1 Function and mode of operation ..................................................... 18

4.1.2 Parameterizing and interconnecting ................................................ 18

4.1.3 Calling OBs .................................................................................... 25

4.1.4 Configuration of Scheduling ........................................................... 25

4.1.5 Error handling................................................................................ 28

4.1.6 Signaling behavior ......................................................................... 29

4.1.7 CFC block representation FB510 ..................................................... 30

4.1.8 Parameter list for FB510 ................................................................. 30

4.1.9 CFC block representation FB516 ..................................................... 33

Page 3: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

Documentation | Modbus TCP/IP PCS 7 driver blocks | 3

4.1.10 Parameter list for FB516 ................................................................. 34

4.2 MODTCP_WRITE - request block ....................................................... 36

4.2.1 Function and mode of operation ..................................................... 36

4.2.2 Parameterizing and interconnecting ................................................ 36

4.2.3 Calling OBs .................................................................................... 38

4.2.4 Error handling................................................................................ 39

4.2.5 Signaling behavior ......................................................................... 39

4.2.6 CFC block representation ................................................................ 40

4.2.7 Parameter list ................................................................................ 40

4.3 MODTCP_READ - request block ......................................................... 42

4.3.1 Function and mode of operation ..................................................... 42

4.3.2 Parameterizing and interconnecting ................................................ 42

4.3.3 Calling OBs .................................................................................... 44

4.3.4 Error handling................................................................................ 44

4.3.5 Signalling behavior ........................................................................ 45

4.3.6 CFC block representation ................................................................ 46

4.3.7 Parameter list ................................................................................ 46

4.4 Example applications in CFC ............................................................ 48

4.4.1 Communication via CP ................................................................... 48

4.4.2 Open IE communication via CPU PN (only possible with FB510) ........ 51

4.4.3 Using RMS Scheduling .................................................................... 54

4.5 W1R_SCALE - Conversion block ........................................................ 56

4.5.1 Function and mode of operation ..................................................... 56

4.5.2 Parameterizing and interconnecting ................................................ 56

4.5.3 Calling OBs .................................................................................... 56

4.5.4 Error handling................................................................................ 56

4.5.5 Signaling behavior ......................................................................... 57

4.5.6 CFC block representation ................................................................ 57

4.5.7 Parameter list ................................................................................ 57

4.6 W2R_SCALE - conversion block......................................................... 58

4.6.1 Function and mode of operation ..................................................... 58

Page 4: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

Documentation | Modbus TCP/IP PCS 7 driver blocks | 4

4.6.2 Parameterizing and interconnecting ................................................ 58

4.6.3 Calling OBs .................................................................................... 58

4.6.4 Error handling................................................................................ 59

4.6.5 Signaling behavior ......................................................................... 59

4.6.6 CFC block representation ................................................................ 59

4.6.7 Parameter list ................................................................................ 59

4.7 R1W_SCALE – conversion block ........................................................ 61

4.7.1 Function and mode of operation ..................................................... 61

4.7.2 Parameterizing and interconnecting ................................................ 61

4.7.3 Calling OBs .................................................................................... 61

4.7.4 Error handling................................................................................ 61

4.7.5 CFC block representation ................................................................ 62

4.7.6 Parameter list ................................................................................ 62

4.8 R2W_SCALE - conversion block......................................................... 63

4.8.1 Function and mode of operation ..................................................... 63

4.8.2 Parameterizing and interconnecting ................................................ 63

4.8.3 Calling OBs .................................................................................... 63

4.8.4 Error handling................................................................................ 64

4.8.5 CFC block representation ................................................................ 64

4.8.6 Parameter list ................................................................................ 64

4.9 W2R_T - transportation block ........................................................... 66

4.9.1 Function and mode of operation ..................................................... 66

4.9.2 Parameterizing and interconnecting ................................................ 66

4.9.3 Calling OBs .................................................................................... 66

4.9.4 CFC block representation ................................................................ 66

4.9.5 Parameter list ................................................................................ 66

4.10 R2W_T - transportation block ........................................................... 67

4.10.1 Function and mode of operation ..................................................... 67

4.10.2 Parameterizing and interconnecting ................................................ 67

4.10.3 Calling OBs .................................................................................... 67

4.10.4 CFC block representation ................................................................ 67

4.10.5 Parameter list ................................................................................ 67

Page 5: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

5

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

1.1 License

A license is required for the driver library.

1.2 Software

This library requires one of the following PCS7 Versions:

PCS7 V7.1 SP1

PCS7 V7.1 SP2

PCS7 V7.1 SP3

PCS7 V7.1 SP4

PCS7 V8.0 (Update 1)

PCS7 V8.0 SP1

PCS7 V8.0 SP2

PCS7 V8.1

For usage of the library with higher versions than listed above clearance from [email protected] is necessary.

1.3 Hardware

The blocks can be executed in S7-41x (non redundant) or S7-41xH CPUs with connected CP443-1 EX20 and in PROFINET IO-CPU’s with an integrated PROFINET-interface (without a separate CP).

1 System requirements

Page 6: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

6

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

2.1 Step 7 block library

The driver blocks are installed with a setup as STEP 7 library.

The target directory

<installation directory>SIEMENS\STEP7\S7libs

is specified by default.

Following the installation, the driver blocks are available in the block library.

In the SIMATIC Manager, you can then open the library via

File Open Library

and thus access the function blocks.

Remark: Are the library block numbers already in use and you need the blocks in another number range, please contact our support.

2.2 Supported functionalities The current library supports the following functionalities:

Integration of the driver blocks in a S7-400 or S7-400H CPU

Modbus communication with remote Modbus slave devices via a TCP/IP connection

The "Public Function Codes" 1 to 6 and 15 to 16 are supported

The entire theoretic scope of external registers can be addressed, i.e. registers with the numbers 40001 to 105536 can be addressed if the Modbus slave device provides them

No CPU restart is required after making changes to the parameters of the Modbus TCP/IP blocks

The following functions are not supported:

Other codes besides the above-mentioned "Public Function Codes", "User-Defined Function Codes", and "Reserved Function Codes" are not supported

2.3 Communication principle The Modbus communication between the S7-400 system and the devices is based on the Request/Response communication principle between client and servers.

The S7-400 system acts as client and every Modbus slave device behaves like a server. The S7-400 system (the Modbus master) sends the requests to the connected devices (the Modbus slaves) and receives the responses to the requests and evaluates their content.

2 General information

Page 7: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

7

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

Modbus Master(TCP Client)

Modbus Slave(TCP Server)

Ethernet TCP/IP

Request 1Response 1

Request 2Response 2

Request NResponse N

The request/response or send/receive communication is implemented based on the con-nection type TCP.

The communication is processed sequentially. The Master sends a request and expects the respective response before sending the next request to the slave. If a request times out, the next request is send out. The number of request blocks connected to the communica-tion block determines the length of the request list. After the last request block from the list has been processed the cycle starts all over.

With redundant utilization, the communication of an S7-400H with a Modbus Slave can take place via both the CP in Rack0 and in Rack1, regardless of which CPU is currently the master.

A redundant communication layout can be implemented in various forms. Thus, for exam-ple, one slave can be used with 2 connections or a slave pair can be used with one con-nection each.

Example of a redundant communications layout

Page 8: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

8

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

2.4 Quantity structure

Max. number of Modbus slave partners per S7-400:

16 were tested; up to 64 are theoretically possible

Max. number of Modbus slave partners per S7-400H:

8 were tested; up to 64 are theoretically possible

Maximum number of data points:

10*127 words or 10*2032 coils per slave

2.5 Performance An S7-400H CPU with the MLFB 6ES7 417-4HL01-0AB0 and firmware V3.1.4 was used for the performance tests via CP. A CP 443-1 (6GK7 443-1EX20-0XE0) was used as CP.

8 logical connections from the CPU to 4 different PCs were configured. Two Modbus TCP slave simulation programs with different ports were started on each PC.

Furthermore a S7-400 CPU417-5H PN/DP with the MLFB 6ES7 417-5HT06-0AB0 and firm-ware V6.0 was used for communication via CPU PN interface.

Refresh speed

During normal operation the MODTCP_COMRED/_T block requires four cycles per request / response telegram pair (per request block). This means that four cycles pass by between two outgoing request telegrams. The request is sent, and the response telegram is re-ceived and evaluated within the four cycles.

Example with function blocks in 100 ms cycle:

Count of orders Read update every Confirmed write update every

1 400 ms 400 ms

2 800 ms 800 ms

N N*400 ms N*400 ms

with N <= 10

If it is necessary to process as many requests as possible with a high update rate, multiple connections between Modbus Master and Modbus Slave can be used. The slave has to support multiple parallel connections. The respective logical connections have to be con-figured and their respective ID’s have to be used at the communication blocks when using CP or different TCON_ID’s must be used when using CPUs with integrated PN interface.

Page 9: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

9

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

If a watchdog is used for monitoring the functionality of the Modbus slave (see 4.1.2.1), additional requests are necessary, which must be sent and which must each await a re-sponse. The use of a watchdog will also cause additional delays until a request message frame is sent again, because all of the message frames are processed sequentially.

Example: Function blocks in a 100ms cycle and watchdog being used

Number of requests

Update cycle of one Read value

Confirmed WRITE of one val-ue

1 1200 ms 1200 ms

2 1600 ms 1600 ms

M 2*M*400 ms 2*M*400 ms

N (2*N+1)*400 ms (2*N+1)*400 ms

with M is even and N is odd and <= 10

Multiple connections can improve performance. The Watchdog could be used with a com-pletely separate communication block.

Page 10: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

10

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

Cycle time required per block instance

function block Needed cycle time

MODTCP_COMRED/_T max. 6 ms

MODTCP_WRITE 0,4 ms

MODTCP_READ 0,4 ms

The MODTCP_COMRED/_T block requires max. 6 ms of cycle time independent of the amount of used connections and connected request blocks. Meanwhile the needed cycle time is obvious less than 1ms, if the open IE-Communication with TSEND and TRCV is used.

Memory requirement per block

function block work- memory load-memory local data

MODTCP_COMRED 5646 Byte 7458 Byte 60 Byte

MODTCP_COMRED_T 10936 Byte 13414 Byte 330 Byte

MODTCP_WRITE 5118 Byte 5778 Byte 90 Byte

MODTCP_READ 5382 Byte 6548 Byte 80 Byte

Reconfiguration time

The reconfiguration time is the time required for the telegram traffic to start after a specif-ic event.

Event needed time

after starting the communication via the block input STRT_COM 10 s

after a RESET 10 s

after loss of connection/reestablishing the connection 10 s

after complete failure and restart of the entire PCS7 system 10 s

after redundancy- including communication switchover as the result of an HCiR 10 s

after redundancy- including communication switchover as the result of an stop of the previously active CPU

10 s

after communication switchover as the result of an LAN failure on the previous active connection including the use of the watchdog functionality

10 s

after communication switchover as the result of an LAN failure on the previous active connection excluding the use of the watchdog functionality

40 s

Page 11: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

11

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

Influence:

Due to their limited communications performance, each CPU can only process a certain number of parallel operator control and monitoring tasks with sufficient performance. If the resulting communication load is correspondingly high, a high number of send/receive connections operated in parallel can increase this operator control and monitoring load. This overloads the CPU and all requests (Send/Receive and operator control and monitor-ing requests) are processed slower. (The communication load can be set at the CPUs).

With H systems, additional synchronizations are required to maintain synchronous opera-tion. This increases the block runtime and reduces the communication performance. Therefore, the performance limit is reached earlier. If the redundantly operating H system is no longer operating at the performance limit, the rule that the performance is 2 to 3 times less than the standard system applies.

2.6 Communication blocks used Communication via CP (FB516 and FB510)

Data is sent from a CP via the LAN to a partner station or received from a partner station and then it must be transmitted from the CP to the CPU. If the user data length is 241 bytes or higher, the AG_LSEND and AG_LRECV FCs must be used to execute this task.

The following blocks of the SIMATIC_NET_CP library were therefore used for implementing the Modbus TCP/IP block library (S7-400H):

AG_CNTRL (Version 1.0)

AG_LSEND (Version 3.1)

AG_LRECV (Version 3.1)

Information about which CP supports the AG_CNTRL with which firmware version can be found under Ethernet-CP and AG_CNTRL.

Note:

The CP443-1 (EX11) does not support the AG_CNTRL functionality. However, test with STEP7 V5.4 SP3 (PCS7 V7.0) have proven successful when the CP443-1 (EX11) was in the S7/PCS 7 project but the physical hardware was a CP443-1 (EX20).

Open IE-Communication via CPU PN (FB510 only)

By using the PROFINET IO-CPU’s with an integrated PROFINET-interface (firmware V2.4 or higher), data is sent directly from the CPU to a partner station over LAN. The following blocks of the Standard library were used for implementing the Modbus TCP/IP block library (S7-400):

TCON (Version 2.4)

TDISCON (Version 2.1)

TSEND (Version 2.1)

TRCV (Version 2.2)

TCON_PAR (Version 2.2)

Page 12: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

12

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

3.1 General configuration instructions

The deployment of the communication library is possible in S7-400 CPU’s with or without an integrated PROFINET-interface. Please take into account that different function blocks have to be used (see description communication blocks).

A configuration of TCP connections between the SIMATIC station and the Modbus slaves with NetPro is only necessary if the communication runs over a CP with TCON=0, but not if the communication runs over the integrated PROFINET-interface with TCON=1.

3.2 HW Config

Communication via CP

Example of hardware configuration for the connection of Modbus slave partners

3 Configuring the hardware

Page 13: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

13

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

Example of CP 443-1 settings in the hardware configuration

Example of configuration with a 417H CPU and an Ethernet CP 443-1

Page 14: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

14

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

Communication via CPU PN

Example of hardware configuration for the connection of Modbus slave partners

Example of configuration with a CPU 417-5H PN/DP with integrated PROFINET-interface

Page 15: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

15

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

3.3 NetPro-Config Communication via CP

The hardware must be configured properly in NetPro to be able to establish a connection via Ethernet.

Example of NetPro configuration (CPU in Rack0 is selected)

Example of NetPro configuration (CPU in Rack1 is selected)

For the SIMATIC station, the TCP connections must then be configured using NetPro. This permits the CPU to address the Modbus slaves. The figure below shows an example of a logical connection. This is how it must be configured between a Modbus slave and an S7 CPU per communication connection.

Example of a logical connection of the CPU above marked in blue (in Rack0)

Example of a logical connection of the CPU above marked in blue (in Rack1)

Create a new connection to an "unspecified station" and select "TCP connection" as con-nection type. Confirm with OK to create the connection and to open the properties dialog of the new connection.

Page 16: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

16

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

Inserting a new logical connection

In the properties dialog, the checkbox for the "Active connection establishment" must be set if the S7-400 as TCP/IP client is to communicate with the Modbus slaves as socket serv-er.

Setting the "Active connection establishment" with important parameters for the subsequent block parameterization

Page 17: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

17

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

The IP address of the Modbus slave (the remote partner) and its port must be entered un-der the "Addresses" tab (the standard port for the Modbus slave is 502).

Setting the IP address and ports of the remote partner

For the redundant scenario, the TCP connections of both CPUs of an S7-400H station must be configured with the Modbus slaves in this manner.

After that you can compile and load the NetPro configuration into the CPU.

Page 18: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

18

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

4.1 MODTCP_COMRED/_T – communication block

Type/number FB 516 MODTCP_COMRED (for CPU without PN interface)

FB 510 MODTCP_COMRED_T (for CPU with PN interface)

4.1.1 Function and mode of operation

The block FB510/FB516 serves as central header block for controlling the communication via Modbus TCP/IP. FB516 is valid only for CPUs without integrated PN interface and use of CP. FB510 is valid only for CPUs with integrated interface/CP. Please note that, if you use FB510 for a CPU without integrated interface, a failure message will be displayed and downloading of the PCS7 project will not be allowed. FB510 has the same parameters as FB516 but extended by additional parameters for the use of CPUs with integrated inter-face. Therefore FB510 should be used for CPUs with integrated PN interface but can also be used with CPs as communication interface.

The function block handles the communication between an S7-400H and a Modbus slave (communication partner) and must be interconnected with further blocks (the request telegram blocks). The communication block can only be used on a SIMATIC S7-41x or S7-41xH CPU with TCP/IP CPs (CP443-1 EX20) or SIMATIC S7-41X CPU with an integrated PROFINET-interface. Furthermore, the CPU must be capable of signalling via ALARM_8P.

Max. 10 possible request blocks, which are sequentially processed, are connected to the MODTCP_COMRED/_T block.

4.1.2 Parameterizing and interconnecting

In the CFC, the MODTCP_COMRED/_T block is interconnected via it’s CONNECT output with the CONNECT inputs of the MODTCP_WRITE and/or MODTCP_READ request blocks to be processed. A defined processing sequence of the individual requests might be required in certain ap-plications. The processing sequence can be configured through the run sequence of the request blocks in the CFC.

If more than 10 request blocks are connected, any connected blocks from the eleventh position on are not considered. These unconsidered request blocks can be recognized by their set error output QLNKF.

Incorrectly parameterized request blocks are also not considered for communication.

The number of valid connected request blocks is indicated at the QBLOCKS output. The actual request or the block number (see runtime editor) are set in QACTREQID (0 based). When using the Watchdog further requests are added (refer 2.5).

The important parameters for communication with CP (FB516 resp. FB510 for CPU with integrated PN interface) must be entered at the inputs LADDR0, LADDR1, CONN_ID0, CONN_ID1. The logical address of the CPs (LADDRx) and the value of the CONN_IDx pa-

4 Description of the function blocks

Page 19: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

19

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

rameters can be obtained from the block parameters in the properties dialog of the NetPro connection. The inputs of FB510 i.e. CPU_ID, REM_IP0/1, REM_PORT0/1, and TCON_ID0/1 are irrelevant for TCON=0 and can be set to invisible.

Pay attention: In case multiple communication blocks are used, each block should have its own logical connection (CONN_ID).

By using the internal interface of the CPU (only possible with FB510) the important pa-rameters are the inputs CPU_ID, REM_IP0/1, REM_PORT0/1 and TCON_ID0/1. The input TCON=1 should be set. The inputs of FB510 i.e. LADDR0, LADDR1, CONN_ID0, CONN_ID1 are irrelevant and can be set to invisible. FB516 can not be used for a CPU with integrated interface.

Pay attention: Each connection has its own connection identifier (TCON_ID0 and TCON_ID1).

The communication can be started and stopped via the STRT_COM switch. A reinitializa-tion of the program run or restart of the communication can be enforced with the input RESET.

The inputs CPUERR0 and CPUERR1 must be connected with the outputs CPUERR_0 and CPUERR_1 of the OB_BEGIN from the PCS7 Basis Library in order to detect and take into consideration any CPU errors in Rack0 or Rack1 for a required switchover of the communi-cation connection being used as the result of a loss of CPU redundancy.

The block OB_BEGIN is automatically inserted into a system chart using the "generate rack" function, but the connection between the OB_BEGIN and the MODTCP_COMRED/_T must be drawn manually (see 4.1.2.3).

The DEV_ID parameter is the device ID (frequently also referred to as slave address or unit identifier) of the Modbus slave device.

Page 20: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

20

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

Setting the LADDR0, LADDR1, CONN_ID0 und CONN_ID1 block parameters with the values from NetPro the CPs from Rack0 and Rack1 (for FB510 TCON=0)

Page 21: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

21

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

Drawing the two connections between the MODTCP_COMRED/_T and the OB_BEGIN blocks

Page 22: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

22

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

FB510 only: Setting parameters CPU_ID, REM_IP0/1, REM_PORT0/1 and TCON_ID0/1 (TCON=1)

4.1.2.1 Further configurations

The parameter TIMEOUT specifies the time (in msec) to wait for a response after a request has been send. The Parameter RETRYREQ specifies the number of retries before alarming a timeout. All requests of the request list are processed sequentially, even if the requests have timed out and have already been alarmed.

If a watchdog is required for monitoring the connected Modbus slaves, this can be param-eterized on the MODTCP_COMRED/_T block. For this purpose, the frequency (WD_COUNT > 0) with which a previously written value may be unequal to the read value in the respec-tive register (or coil) of the slave until a watchdog error is reported must be specified. In addition, the function code WD_FCTCOD and the address WD_ADDR of the watchdog reg-ister or number of the watchdog coil must be specified. The watchdog monitoring func-tionality is defined for exactly one register or one coil and can also be used for monitoring the active connection. This allows a quicker response to the loss of a connection. The de-tection of a lost connection by the CP alone with AG_CNTRL (i.e. without the use of a watchdog) takes approximately 30 seconds.

When a watchdog error occurs, the communication is switched over <= 10s from the cur-rently active connection to the standby connection, assuming that the standby connection has not already been reported as faulted at this time.

The parameter ACTCONIN forces the active connection (0 for CP0 and 1 for CP1) for com-munication. Automatic switch over of connections is only activated when ACTCON = -1.

The MODTCP_COMRED/_T block can also be used for a non-redundant system. To this end, the redundancy can be disconnected via the input RED. When doing this, ensure that the block parameters with a 0 at the end of their names are the relevant parameters for this

Page 23: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

23

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

application, and the parameters with a 1 at the end of their names are not taken into con-sideration. Only CP0 is used for communication.

4.1.2.2 Additional information

If there is no response to the request telegrams for all connected request blocks within the specified timeout and the specified number of retries, or if responses cannot be interpret-ed because there are unexpected data in the receive buffer of the CP, the connection to the Modbus slave will be restarted. This automatic reset is only carried out, however, if this condition continues for double the timeout value during the program run.

The following outputs are used for analyzing

o the internal program sequence QSTATEF and QSTATE

o for alerting QMSG_ERR, QMSG_DONE, QMSG_SUP, QMSG_STAT and QMSG_ACK

o for indicating the slots QRACK_NO0, QRACK_NO1, QSLOT_NO0 and QSLOT_NO1

o for analyzing the communication. QSNDACT, QSNDDIAG, QRCVDAT and QRCVDIAG

o and for analyzing the connection status (for CP only) ACTCON, STATCON0 and STATCON1

QSNDACT =1 means that 'data are being sent' and QRCVDAT = 1 means that 'data are being received'. ACTCON indicates an active connection. With 0, communication with the Mod-bus slave takes place via the connection from the CP in Rack0; with 1, via the CP in Rack1.

In QSNDDIAG, the STATUS of AG_LSEND or TSEND is displayed and in QRCVDIAG, the STA-TUS of AG_LRECV or TRCV is displayed. In STATCON0, the connection status of the CP in Rack0 with the communication partner is indicated with the aid of the AG_CNTRL and in STATCON1, a corresponding indication is given for the connection from the CP in Rack1. The information is returned in RESULT1 for CMD=1 by calling up AG_CNTRL.

Information regarding the STATUS and RESULT values are available in the respective online help of AG_ LSEND, AG_LRECV and AG_CNTRL or in the SIMTIC NET Manual.

Changing values of the following parameters LADDR0, LADDR1, CONN_ID0 and CONN_ID1 (use of CP) or CPU_ID, REM_IP0/1, REM_PORT0/1 and TCON_ID0/1 (use of CPU with inte-grated PN interface) require a restart of the communication or RESET.

Page 24: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

24

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

Blocks called from the interface are:

o FB511 (MODTCP_BuildReq)

o FB512 (MODTCP_ParseReq)

o FB513 (MODTCP_ProgLogic)

o FB514 (MODTCP_Link)

o FB521 (MODTCP_ConnStat)

o FB522 (MODTCP_ConnRes)

o SFB35 (ALARM_8P)

Blocks called from the code are:

o FC10 (AG_CNTRL)*

o FC50 (AG_LSEND)

o FC60 (AG_LRECV)

o SFC6 (RD_SINFO)

o SFC20 (BLKMOV)*

o SFC49 (LGC_GADR)

*MODTCP_COMRED/_T uses AG_CNTRL indirectly via FB521 and FB522.

*MODTCP_COMRED/_T uses BLKMOV indirectly via FB511 and FB512.

4.1.2.3 Creating module drivers

When compiling a CFC, the function "Generate module drivers" must be used for signal processing in PCS 7. This function generates new system charts (with names assigned by the system "@..."), in which only driver blocks are inserted by the driver generator.

After the hardware is configured using HW Config and the technological functions are configured in the CFC, this function automatically generates, interconnects and parame-terizes the necessary module drivers. These module drivers are responsible for the diag-nosing and reporting of errors during signal processing.

With the setup for the MODTCP_COMRED/_T block, an object list and an action list are in-stalled in the form of two XML files. This allows the driver generator to also automatically insert the necessary OB_BEGIN block (into a system chart).

The two installed metafiles (here for PCS7 V8.0) are:

<ProgramFiles>\SIEMENS\STEP7\S7DATA\driver\action\08000000\al_chn_modtcp_comred.xml

<ProgramFiles>\SIEMENS\STEP7\S7DATA\driver\object\08000000\chn_modtcp_comred.xml

The connections between the OB_BEGIN and the MODTCP_COMRED/_T block must, how-ever, still be drawn manually, because the assignment of the "channel" block to its associ-ated diagnostic block cannot be made known to the driver generator.

Generating the module driver the warning ‘Cannot find driver block for the signal pro-cessing block %blockname%’ will be shown for each MODTCP_COMRED/_T block. This warning can be ignored.

After a change to the HW configuration, the driver generator must be restarted.

Page 25: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

25

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

4.1.3 Calling OBs

The calling OB is the cyclic interrupt OB3x, into which you integrate the block (e.g. OB 35) and the following OBs, into which the block is also integrated (automatically in the CFC):

o OB100 Restart (warm restart)

o OB102 Restart (cold restart)

4.1.4 Configuration of Scheduling

The following chapter explains the use of the scheduling modes provided by the library.

To activate Scheduling the "SCHEDULER" inputs of the communication blocks as well as the request blocks are to be set to either RMS or EDF.

Pay attention:

When using Scheduling the WDCOUNT input on the communication block is not used. The block will behave as if it was set to zero.

A communication block and all attached request blocks are to be configured with the same SCHEDULER

Configured execution rates have to be checked for their practicability (also refer to 4.1.4.4 Estimating the communication load)

4.1.4.1 Use cases for Scheduling

When using scheduling the execution rates of different request blocks attached to a com-munication block can be configured.

In normal operation mode (SCHEDULING = NONE) all attached request blocks are executed in a cyclic way without any priorities. In this operation mode performance and execution rate behave as described in "Fehler! Verweisquelle konnte nicht gefunden werden. Fehler! Verweisquelle konnte nicht gefunden werden.".

When choosing a scheduled operation mode the rate of execution is no longer determined by the count of attached request blocks. Instead it is configured by setting the EXECRATE parameter on each request block individually. Keep in mind that this does not increase the total available communication capacity. For every request block running faster than nor-mal other blocks have to be slowed down.

Therefore using scheduling is advisable when only specific requests are of increased inter-est and should be processed more often.

Scheduling only offers a system to balance execution rates of different requests. Whenev-er the data rate is to be increased as a whole additional communication blocks should be used instead or in addition. When increasing the amount of communication blocks two limitations should be considered:

Additional communication blocks also increase CPU load

A single gateway can only support up to ten connections at once

Page 26: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

26

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

Typical performance limits of PCS7 as well as the used hardware (CP cards, CPU) apply

4.1.4.2 Rate monotinic scheduling (RMS)

To enable RMS the SCHEDULER input on the communication block as well as all attached request blocks are set to "RMS".

RMS uses priorities based on the execution rate. The more often a request is to be pro-cessed the higher the priority.

Therefore RMS is best suited when there is a special focus on a subset of the attached re-quest blocks which are to be executed faster. In cases of communication overload caused by transmission errors or delayed slave responses RMS ensures these blocks will be priori-tized.

Under normal conditions (no transmission errors or delayed slave responses) RMS can guarantee stable scheduling for a workload of 69%.

RMS is a good choice when faster request blocks are to be prioritized and enough work-load reserve is given.

Pay attention: with workloads exceeding 69% RMS scheduling will get increasingly less reliable. On communication overload (>69%, by the latest when > 100%) the slowest re-quest blocks will start to fail on their configured timing and are not executed any more at all worst case.

Special use case: it is possible to enable RMS for specific request blocks but leaving the communication blocks scheduler set to NONE. In this case the request block will initiate a read/write request based on the configured EXECRATE. However no priorities will apply. Instead the request is queued for normal cyclic execution. It is not possible to speed up (compared to the normal cycle time) a request this way but slowing down execution of some of the request blocks can be a viable means to optimize typical execution rate of the other blocks that are in cyclic operation mode. This behavior could also be achieved by using RDRQ/SNDRQ and external timers.

4.1.4.3 Earliest deadline first (EDF)

To enable EDF the SCHEDULER input on the communication block as well as all attached request blocks are set to "EDF".

Unlike RMS EDF does not use static priorities to solve conflicts between pending requests. Instead the request is chosen which is closest to its next planned execution ( Deadline) or in case of overload has violated the deadline the most.

Therefore EDF does not only communicate when a request is pending but constantly checks for deadlines and executes a request then. For this reason the EXECRATE parame-ter configures the minimum target execution rate rather than trying to make an exact tim-ing.

Hence in contrast to RMS workloads up to 100% are possible. With increasing or decreas-ing workload the actually achieved timing will vary. If the configured requests demand less than 100% workload execution rate will be faster than configured. For increasing workload timing will get slower accordingly.

As EDF has no static priorities all requests will be delayed randomly when in an overload state (Overload states can happen due to bad configuration, transmission errors or de-layed slave responses).

Page 27: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

27

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

EDF is a good choice when the workload is too high for reliable RMS scheduling.

4.1.4.4 Estimating the communication load

When configuring scheduling it is mandatory to estimate the communication load. The load of a communication block is determined by the request blocks that are attached to a specific communication block.

In general the percental workload with N attached request blocks can be computed with the following formula:

In normal operation (no transmission errors, no significant delay due to slow slave re-sponses) the execution time is

Execution time = OB Cycle Time * Number of cycles needed

The OB cycle time is taken from the OB the communication block is run in. The CPU needs four cycles to finish processing a communication task. For example if a communication block is run in OB35 every 100 ms on a redundant CPU the execution time would be 400 ms.

The period matches the configured EXECRATE.

Example of calculation:

A communication block features 5 request blocks read request, 4 s period read request, 2 s period read request, 20 s period write request, 6 s period write request, 2 s period

The communication block as well as the request blocks run in OB35 every 100 ms.

In this case the workload is computed as followed:

Pay attention: when communication errors occur the execution time increases dependent on the configured Timeouts and Retries. Furthermore slow reacting Modbus slaves can have a negative effect on execution time.

4.1.4.5 Monitoring execution rate with WDTIMER

By configuring the WDTIMER input and evaluating the corresponding QWDTIMER output the execution rate of each request block can be monitored individually.

This feature saves the time of the last execution of a request. If the difference to the cur-rent system time exceeds the configured WDTIMER an error will be indicated by setting QWDTIMER to 1.

WDTIMER is only active when EDF or RMS is activated on the request block. This feature can be used to detect communication overload.

Page 28: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

28

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

4.1.4.6 List of parameters: scheduling

Communication block: IO Parameter IO-Typ Default Kommentar

I SCHEDULER BYTE NONE Choose by the criteria outlined above

Request block: IO Parameter IO-Typ Default Kommentar

I SCHEDULING BYTE NONE Choose by the criteria outlined above

I EXECRATE TIME 4 s Be aware of the workload when configuring

I WDTIMER TIME 6 s Detection of communication overloads

O QWDTIMER BOOL FALSE Shows errors when violating configured WDTIMER

4.1.5 Error handling

The following error statuses are specified as flags:

A general error status is displayed in QERR0 and QERR1. If both are set, then QERR_TOT is set. This summarizing general error status is forwarded to the request blocks so that their output can be set corresponding to QBAD. If you dispense with the redundancy using RED = 0, only the status of QERR0 is taken into consideration for this. QERRx is set by one of the following errors.

QCOMF0 and QCOMF1 signals faulty communication.

QWDF indicates a watchdog error.

Possible incorrect parameterizations are indicated via QPARF0 and QPARF1.

QPARFx Output Description

0 0 No error

1 Spare Reserved

2 Dev_Id DEV_ID invalid (valid are 1 - 255)

3 WDFctCod WD_FCTCOD invalid (valid are 1 and 3)

4 WDCount WD_COUNT invalid (valid are values >= 0)

5 WDAddr WD_ADDR invalid

6 LAddr Incorrect LADDR module start address

7 Conn_Id Invalid CONN_ID

8° Timeout TIMEOUT must be at least 5*cycle time of the OB

9° RetryReq RETRYREQ is invalid (values >= 0 are valid)

10° RunupCyc RUNUPCYC is invalid (values >= 0 are valid)

11 WrongIP Invalid String for IP Address

° only applies for QPARF0

Page 29: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

29

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

4.1.6 Signaling behavior

The input EN_MSG = 1 activates the messaging capability (default setting=0). Individual signals for the messaging capability are activated or hidden via the input EN_SIGS (default setting =16#7E, with 6 of 7 possible signals activated). A number of cycles can be set using the parameter RUNUPCYC for which no messages are generated during the start.

The MODTCP_COMRED/_T block generates control messages via the ALARM_8P for the OS with the following assignments of the message texts, including the auxiliary values for its block parameters.

Assigning the message text to the block parameters

Message block Alarm_8P

Msg. no.

Predefined message text Can be acti-vated by resp. bit in EN_SIGS

Respective parameter

MSG_EVID 1 Timeout for Request No. @7%d@ on connection @8%d@

xxxx xxx0 (default is OFF)

-

2 Spare [Rack@3%d@/Slot@4%d@ error with connection @8%d@]

xxxx xx1x -

3 Parameter error (@5%d@) for connection 0

xxxx x1xx QPARF0

4 Parameter error (@6%d@) for connection 1

xxxx 1xxx QPARF1

5 Communication error (LADDR=0x@1W%X@, CONN_ID=@2%d@) for connection @8%d@

xxx1 xxxx QCOMF0 or QCOMF1

6 Watchdog error xx1x xxxx QWDF

7 Redundant communication connection failed

x1xx xxxx QRED_LOST*

8

*With message number 7, the failure of the redundant communication connection is re-ported. There does not have to be a redundancy failure for this (stop or failure of a CPU). The time of this message can be delayed compared to the actual cause. A redundancy fail-ure can be reported using standard blocks (e.g. OB_BEGIN), if necessary.

Message number 1 is switched off by default, because it occurs frequently for a failed (last active) communication connection until the communication is switched over to another intact connection.

Assigning the associated values to the block parameters

Melde-baustein Alarm_8P

Begleitwert Bausteinparameter

MSG_EVID 1 Logical CP I/O address

2 Connection ID

3 Rack Number

4 Slot Number

Page 30: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

30

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

Melde-baustein Alarm_8P

Begleitwert Bausteinparameter

5 Parameter error number for connection 0

6 Parameter error number for connection 1

7 Current Request Number

8 Active connection

4.1.7 CFC block representation FB510

4.1.8 Parameter list for FB510

IO Parameter IO-Typ Default Comment

I CPUERR0 BOOL Must be connected with OB_BEGIN CPUERR_0

I CPUERR1 BOOL Must be connected with OB_BEGIN CPUERR_1

I RED BOOL 1 1: redundant; 0: non redundant

I LADDR0 WORD 16#3FF7 Logical CP I/O address from CP0

I LADDR1 WORD 16#3FF6 Logical CP I/O address from CP1 (not used if RED=0)

I CONN_ID0 INT 1 Connection ID from CP0

I CONN_ID1 INT 1 Connection ID from CP1 (not used if RED=0)

I DEV_ID INT 1 Device ID / slave address

Page 31: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

31

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

IO Parameter IO-Typ Default Comment

I TIMEOUT DINT 1000 Timeout in milliseconds

I EN_MSG BOOL 0 1 = enable alarm

I EN_SIGS BYTE 16#7E Alarm_8P enable or disable each of the 7 signals

I MSG_EVID DWORD 2 System input for alarming

I RUNUPCYC INT 3 Count startcyles (hide messages during start)

I RETRYREQ INT 3 Max. attempts for a request before signal a timeout

I WD_COUNT INT 0 Watchdog Counter

I WD_FCTCOD INT 3 Function code for watchdog: 1or 3

I WD_ADDR DINT 127 Register or coil number used for watchdog

I EN_TCON BOOL 0 1 = enable TCON communication

I CPU_ID BYTE 0 CPU type

I REM_IP0 STRING[15] ‚XXX’ remote IP0 address

I REM_PORT0 INT 502 remote IP0 Port

I TCON_ID0 WORD 16#1 connection ID0 for TCON communication

Range of values: W#16#0001 to W#16#0FFF

I REM_IP1 STRING[15] ‚XXX’ remote IP1 address

I REM_PORT1 INT 503 remote IP1 Port

I TCON_ID1 WORD 16#1 connection ID1 for TCON communication

Range of values: W#16#0001 to W#16#0FFF

I ACTCONIN INT -1 CP number (0 or 1) where the connection should be active, -1 means automatic

I SCHEDULER BYTE 0 Sets the scheduling mechanism

IO STRT_COM BOOL 0 1 = start communication

IO RESET BOOL 0 1 = reset function block

O CONNECT DWORD 0 Connection to input CONNECT of Telegramm blocks

O QERR_TOT BOOL 0 1 = total error (no connection alive)

O QERR0 BOOL 0 1 = general error in connection 0

O QERR1 BOOL 0 1 = general error in connection 1

O QPARF0 INT 0 Parameter error at connection 0

O QPARF1 INT 0 Parameter error at connection 1

O QCOMF0 BOOL 0 1 = communication error at connection 0

O QCOMF1 BOOL 0 1 = communication error at connection 1

O QRED_LOST BOOL 0 1 = redundancy lost

O QWDF BOOL 0 1 = watchdog error

O QSTATEF INT 0 Internal state error

O QSTATE INT 0 Internal state

Page 32: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

32

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

IO Parameter IO-Typ Default Comment

O QSNDACT BOOL 0 1 = data sent

O QSNDDIAG WORD 0 Detailed send status

O QRCVDAT BOOL 0 1 = data received

O QRCVDIAG WORD 0 Detailed receive status

O QMSG_ERR BOOL 0 1 = ALARM_8P Error

O QMSG_DONE BOOL 0 1 = ALARM_8P Done

O QMSG_SUP BOOL 0 1 = Message suppression active

O QMSG_STAT WORD 0 ALARM_8P: STATUS Output

O QMSG_ACK WORD 0 ALARM_8P: ACKNOWLEDGE Output

O QRACK_NO0 INT 0 CP0 Rack-Number

O QRACK_NO1 INT 0 CP1 Rack-Number

O QSLOT_NO0 INT 0 CP0 Slot-Number

O QSLOT_NO1 INT 0 CP1 Slot-Number

O ACTCON INT 1 CP number where the connection is active

O STATCON0 WORD 0 Status of Connection 0

O STATCON1 WORD 0 Status of Connection 1

O QBLOCKS INT 0 Count of connected valid blocks

O QACTREQID INT -1 Actual request D / block number (look at sequence editor)

O WD_VAL WORD 0 Value read because of watchdog

Page 33: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

33

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

4.1.9 CFC block representation FB516

Page 34: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

34

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

4.1.10 Parameter list for FB516

IO Parameter IO-Typ Default Kommentar

I CPUERR0 BOOL Must be connected with OB_BEGIN CPUERR_0

I CPUERR1 BOOL Must be connected with OB_BEGIN CPUERR_1

I RED BOOL 1 1: redundant; 0: non redundant

I LADDR0 WORD 16#3FF7 Logical CP I/O address from CP0

I LADDR1 WORD 16#3FF6 Logical CP I/O address from CP1 (not used if RED=0)

I CONN_ID0 INT 1 Connection ID from CP0

I CONN_ID1 INT 1 Connection ID from CP1 (not used if RED=0)

I DEV_ID INT 1 Device ID / slave address

I TIMEOUT DINT 1000 Timeout in milliseconds

I EN_MSG BOOL 0 1 = enable alarm

I EN_SIGS BYTE 16#7E Alarm_8P enable or disable each of the 7 signals

I MSG_EVID DWORD 2 System input for alarming

I RUNUPCYC INT 3 Count startcyles (hide messages during start)

I RETRYREQ INT 3 Max. attempts for a request before signal a timeout

I WD_COUNT INT 0 Watchdog Counter

I WD_FCTCOD INT 3 Function code for watchdog: 1or 3

I WD_ADDR DINT 127 Register or coil number used for watchdog

I ACTCONIN INT -1 CP number (0 or 1) where the connection should be active, -1 means automatic

I SCHEDULER BYTE 0 Sets the scheduling mechanism

IO STRT_COM BOOL 0 1 = start communication

IO RESET BOOL 0 1 = reset function block

O CONNECT DWORD 0 Connection to input CONNECT of Telegram blocks

O QERR_TOT BOOL 0 1 = total error (no connection alive)

O QERR0 BOOL 0 1 = general error in connection 0

O QERR1 BOOL 0 1 = general error in connection 1

O QPARF0 INT 0 Parameter error at connection 0

O QPARF1 INT 0 Parameter error at connection 1

O QCOMF0 BOOL 0 1 = communication error at connection 0

O QCOMF1 BOOL 0 1 = communication error at connection 1

O QRED_LOST BOOL 0 1 = redundancy lost

O QWDF BOOL 0 1 = watchdog error

O QSTATEF INT 0 Internal state error

Page 35: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

35

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

IO Parameter IO-Typ Default Kommentar

O QSTATE INT 0 Internal state

O QSNDACT BOOL 0 1 = data sent

O QSNDDIAG WORD 0 Detailed send status

O QRCVDAT BOOL 0 1 = data received

O QRCVDIAG WORD 0 Detailed receive status

O QMSG_ERR BOOL 0 1 = ALARM_8P Error

O QMSG_DONE BOOL 0 1 = ALARM_8P Done

O QMSG_SUP BOOL 0 1 = Message suppression active

O QMSG_STAT WORD 0 ALARM_8P: STATUS Output

O QMSG_ACK WORD 0 ALARM_8P: ACKNOWLEDGE Output

O QRACK_NO0 INT 0 CP0 Rack-Number

O QSLOT_NO0 INT 0 CP0 Slot-Number

O QRACK_NO1 INT 0 CP1 Rack-Number

O QSLOT_NO1 INT 0 CP1 Slot-Number

O ACTCON INT 1 CP number where the connection is active

O STATCON0 WORD 0 Status of Connection 0

O STATCON1 WORD 0 Status of Connection 1

O QBLOCKS INT 0 Count of connected valid blocks

O QACTREQID INT -1 Actual request D / block number (look at sequence editor)

O WD_VAL WORD 0 Value read because of watchdog

Page 36: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

36

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

4.2 MODTCP_WRITE - request block

Type/number FB 518

4.2.1 Function and mode of operation

The MODTCP_WRITE block is used to compile Modbus write requests and its attached data are sent to the Modbus slave.

The MODTCP_WRITE block is used together with the MODTCP_COMRED/_T block for writing data into so-called coils (bits) or registers (words) of the Modbus slave device via a TCP/IP connection using the Modbus protocol.

It writes the pending data at the inputs and any data in a parameterized data block into the corresponding register(s) or coil(s).

4.2.2 Parameterizing and interconnecting

The input CONNECT of the request block MODTCP_WRITE must be connected to the CON-NECT output of the MODTCP_COMRED/_T block. The FCTCODE parameter of the request block determines the type of data access as follows:

FCTCODE Function name Description

5 Write single coil Write a bit

6 Write single register Write a register

15 Write multiple coils Write up to 2032 bits

16 Write multiple registers Write up to 127 registers

STRTADD specifies the start address of the register or coil, and QUANTITY specifies the number of coils or registers to be written.

The parameter DEV_ID is the device Id (often named as slave address or unit identifier) from the Modbus RTU Slave device. If DEV_ID = -1 at the MOD_READ block the correspond-ing modbus telegram will be created with the DEV_ID from the MOD_COM block.

4.2.2.1 Further configurations

If the values to be sent are not obtained from the inputs VAL1 - VAL127 but instead from a data block, the number of the data block and the start address must be specified in DB_STRTADD via the parameter DB_NO. If DB_NO = 0, the values from the inputs are used.

Byte and word sequence

Since it is not exactly specified in the Modbus specification how data is to be stored in the registers, some manufacturers implement their Modbus devices such that first the High byte and then the Low byte is stored and transferred. Other devices, on the other hand, save and transfer the Low byte first.

Page 37: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

37

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

The same applies to words if registers were combined in 32-bit data types. Some devices save the High word in the first register and the Low word in the second register. In other devices, on the other hand, this is implemented in the reverse order.

An example is the 32-bit unsigned integer 2923517522, which can be arranged in four different ways:

AE41 5652 : high byte first, high word first 5652 AE41 : high byte first, low word first 41AE 5256 : low byte first, high word first 5256 41AE : low byte first, low word first

It does not matter in which order the bytes or words are sent as long as this can be con-sidered at the receiver end.

Therefore, the values can be adapted at the outputs with the MODTCP_WRITE block with the CHG_BYTE and CHG_WORD switches.

With CHG_BYTE = TRUE, the High byte and Low byte of an output value (also in any speci-fied DB) are interchanged. With CHG_WORD = TRUE, the High word and Low word of a double word are interchanged. The double word is then put together through two consec-utive outputs. The same applies to values in any specified DB. When using CHG_WORD, make sure that an even number of registers or Coils (QUANTITY DIV 16) to be read is avail-able.

4.2.2.2 Additional information

The number of bytes to be written can be determined via the output BYTECNT.

Blocks called from the code are:

o FC29 (NE_STRING)

o SFC20 (BLKMOV)

o

Information is stored in a standard Modbus slave device in four different tables. Two tables store on/off discrete values (coils) and two store numerical values (registers). The coils and registers each have a read-only table and read-write table.

Coil/Register Numbers

Data Addresses

Type Table Name

1-09999 0000 to 270E Read-Write Discrete Output Coil

10001-19999 0000 to 270E Read-Only Discrete Input Contacts

30001-39999 0000 to 270E Read-Only Analog Input Registers

40001-49999 0000 to 270E Read-Write Analog Output Holding Registers

Page 38: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

38

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

With the MODTCP_WRITE block data can be written in following tables in a modbus slave:

FCTCODE Action Table Name

5 Write single Discrete Output Coil

6 Write single Analog Output Holding Register

15 Write multiple Discrete Output Coils

16 Write multiple Analog Output Holding Registers

4.2.2.3 Send on Request

Per default all request blocks attached to a communication block will be executed cyclical-ly. By setting SOR_EN an alternative mode of operation can be selected. Blocks configured with SOR_EN are not executed cyclically any more. Instead they are triggered by a raising edge on the SNDRQ input. The output CLRTS ("Clear to send") indicates if the last request was already processed. While CLRTS is zero the SNDRQ input is ignored.

Once a send request is triggered execution follows the configured TIMEOUT and RETRYREQ settings. In case of an error during sending QBAD is set to 1 but no automatic follow-up request will be created.

As shown in the graph the data sent is taken from the moment when the raising edge is detected. Execution of a request can be delayed by the communication block when other requests are pending as well.

Mixed mode of operation (SOR_EN 0/1) on one communication block is possible. In this case requests triggered by SNDRQ are queued by the communication block within its nor-mal cyclic operation.

4.2.3 Calling OBs

The calling OB is the cyclic interrupt OB3x in which you integrate the block (e.g. OB 35).

Page 39: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

39

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

4.2.4 Error handling

QLNKF indicates an error when the connection to the MODTCP_COMRED/_T block is faulty or when the MODTCP_WRITE block itself could not be registered internally, e.g. because more than 10 request blocks are already connected.

QBAD indicates that the write request was invalid. It is TRUE when QLNKF is TRUE or QERR at the MODTCP_COMRED/_T block is TRUE. Furthermore it is TRUE when the write request came back with a response code <> 0 and <> 15 (refer QRESPCOD).

Possible incorrect parameterizations are indicated via QPARF.

QPARF Output Description

0 0 No error

1 Spare Reserved

2 Spare Reserved

3 Fctcode FCTCODE invalid (valid are 5,6,15,16)

4 StartAdd STRTADD invalid (valid are values >= 0 and < 0xFFFF)

5 CoilQnty For FCTCODE 5 or 15, QUANTITY is invalid (valid are values > 0 and <= 2032)

6 RegQnty For FCTCODE 6 or 16, QUANTITY is invalid (valid are values > 0 and <= 127)

7 Db_No Data block with DB_NO is not loaded

8 Db_Strta DB_STRTADD is invalid

Status information received in the response is displayed via QRESPCOD.

QRESPCOD Output Description

0 OK No error

1 ILLEGAL FCT Illegal function call

2 ADDR ERR Illegal address

3 DATA ERR Illegal data value

4 DEV ERR Error in the device that cannot be eliminated

5 TIMEOUT Timeout

15 Waiting for Response

4.2.5 Signaling behavior

The block has no signaling behavior.

Page 40: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

40

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

4.2.6 CFC block representation

4.2.7 Parameter list

IO Parameter IO type Default Comment

I CONNECT ANY CFC connection to MODTCP_COMRED/_T block

I DEV_ID INT -1 Device ID /Slave address 1-255; -1 ID adopted from COM block

I FCTCODE INT 16 Function code: [5, 6, 15, 16]

I STRTADD DINT 0 Register starting address [0..0xFFFF]

I QUANTITY INT 1 Quantity of outputs (coils or registers)

I DB_NO INT 0 DB number with data to be copied; if 0 does not copy

I DB_STRTADD INT 0 In the DB, start address of the data

I CHG_BYTE BOOL 0 Interchange Low- and High-bytes in each word from the input values

I CHG_WORD BOOL 0 Interchange Low- and High-words in each doubleword from the input values (QUANTITY should be even)

I VAL1 WORD 0 1st word value to write (single value, if FC is 5 or 6)

...

I VAL127 WORD 0 127th word value to write

I SNDRQ BOOL 0 Initiate send request with raising edge

I SOR_EN BOOL 0 Enable “Send on request”; if 0 ignore SNDRQ

I EXECRATE TIME 4s Execution rate when scheduling is used

Page 41: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

41

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

IO Parameter IO type Default Comment

I WDTIMER TIME 6s Create warning whn execution rate drops below this value

I SCHEDULER BYTE 0 Sets the scheduling mechanism

O QBAD BOOL 0 General error / quality code

O QLNKF BOOL 0 Link failure

O QPARF INT 0 Parameter error

O QRESPCOD INT 0 See Table in error handling

O BYTECNT BYTE 0 Count of bytes used to write

O CLRTS BOOL 0 Block is clear to send. SNDRQ only taken when 1.

O QWDTIMER BOOL 0 Indicates violation of the configured WDTIMER

Page 42: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

42

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

4.3 MODTCP_READ - request block

Type/number FB 517

4.3.1 Function and mode of operation

The MODTCP_READ block is used to compile Modbus read requests and to process the data received via the TCP connection in the associated response.

The MODTCP_READ block is used together with the MODTCP_COMRED/_T block for reading data from so-called coils (bits) or registers (words) of the Modbus slave device via a TCP/IP connection using the Modbus protocol.

The received data are displayed at the block outputs or can be transferred to an optionally specified data block.

4.3.2 Parameterizing and interconnecting

The input CONNECT of the request block MODTCP_READ must be connected to the CON-NECT output of the MODTCP_COMRED/_T.

The FCTCODE parameter of the request block determines the type of data access as fol-lows:

FCTCODE Function name Description

01 Read coils Reading of up to 2032 bits (output status)

02 Read discrete inputs Reading of up to 2032 bits (input status)

03 Read holding registers Reading of up to 127 output registers

04 Read inputs registers Reading of up to 127 input registers

STRTADD specifies the start address of the register or coil, and QUANTITY specifies the number of coils or registers to be read.

The parameter DEV_ID is the device Id (often named as slave address or unit identifier) from the Modbus RTU Slave device. If DEV_ID = -1 at the MOD_READ block the correspond-ing modbus telegram will be created with the DEV_ID from the MOD_COM block.

4.3.2.1 Further configurations

Output of values

If the received values are not written at the outputs VAL1 - VAL127 but instead into a data block, the number of the data block and the start address must be specified in DB_STRTADD via the parameter DB_NO. If DB_NO = 0, the values at the outputs are writ-ten.

Page 43: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

43

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

Substitute values

Substitute values can be specified for the MODTCP_READ block via the inputs SUB_VAL1 – SUB_VAL127. If SUB_ACT = TRUE in the event of communication problems QBAD = TRUE, these values can be copied to the outputs. Only as many values as specified via QUANTITY (considering the FCTCODE) are copied.

Simulation values

Simulation values can be specified for the MODTCP_READ block via the inputs SIM_VAL1 – SIM_VAL127. If SIM_ACT = TRUE, these values are copied to the outputs. Only as many values as specified via QUANTITY (considering the FCTCODE) are copied. Values that may have been read from the Modbus slave or replacement values are overwritten by the simu-lation values.

Byte and word sequence

Since it is not exactly specified in the Modbus specification how data is to be stored in the registers, some manufacturers implement their Modbus devices such that first the High byte and then the Low byte is stored and transferred. Other devices, on the other hand, save and transfer the Low byte first.

The same applies to words if registers were combined in 32-bit data types. Some devices save the High word in the first register and the Low word in the second register. In other devices, on the other hand, this is implemented in the reverse order.

An example is the 32-bit unsigned integer 2923517522, which can be arranged in four different ways:

AE41 5652 : high byte first, high word first 5652 AE41 : high byte first, low word first 41AE 5256 : low byte first, high word first 5256 41AE : low byte first, low word first

It does not matter in which order the bytes or words are sent as long as this can be con-sidered at the receiver end.

Therefore, the values can be adapted at the outputs with the MODTCP_READ block with the CHG_BYTE and CHG_WORD switches. The switches are only considered if FCTCODE = 3 or 4. Substitute values and simulation values are not modified.

With CHG_BYTE = TRUE, the High byte and Low byte of an output value (also in any speci-fied DB) are interchanged. With CHG_WORD = TRUE, the High word and Low word of a double word are interchanged. The double word is then put together through two consec-utive outputs. The same applies to values in any specified DB. When using CHG_WORD, make sure that an even number of registers or coils (QUANTITY DIV 16) to be read is avail-able.

4.3.2.2 Additional information

Blocks called from the code:

o FC29 (NE_STRING)

o SFC20 (BLKMOV)

Page 44: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

44

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

Information is stored in a standard Modbus slave device in four different tables. Two tables store on/off discrete values (coils) and two store numerical values (registers). The coils and registers each have a read-only table and read-write table.

Coil/Register Numbers

Data Addresses

Type Table Name

1-09999 0000 to 270E Read-Write Discrete Output Coil

10001-19999 0000 to 270E Read-Only Discrete Input Contacts

30001-39999 0000 to 270E Read-Only Analog Input Registers

40001-49999 0000 to 270E Read-Write Analog Output Holding Registers

With the MODTCP_READ block data could be read from following tables in a Modbus slave:

FCTCODE Action Table Name

1 Read Discrete Output Coils

2 Read Discrete Input Contacts

3 Read Analog Output Holding Registers

4 Read Analog Input Registers

4.3.2.3 Read on Request

Also refer to 0

Send on Request.

Setup of "Read on Request" is analogue to "Send on Request". The input ROR_EN ("Read on Request Enable") enables the feature.

RDRQ will trigger a request on raising edges when CLRTR ("Clear to read") indicates clear-ance.

4.3.3 Calling OBs

The calling OB is the cyclic interrupt OB3x in which you integrate the block (e.g. OB 35).

4.3.4 Error handling

QLNKF indicates an error when the connection to the MODTCP_COMRED/_T block is faulty or when the MODTCP_READ block itself could not be registered internally, e.g. because more than 10 request blocks are already connected.

QBAD indicates that the read request was invalid. It is TRUE when QLNKF is TRUE or QERR at the MODTCP_COMRED/_T block is TRUE. Furthermore it is TRUE when the read request came back with a response code <> 0 and <> 15 (refer QRESPCOD).

Possible incorrect parameterizations are indicated via QPARF.

Page 45: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

45

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

QPARF Output Description

0 0 No error

1 Spare Reserved

2 Spare Reserved

3 Fctcode FCTCODE invalid (1,2,3,4 are valid)

4 StartAdd STRTADD invalid (valid are values >= 0 and < 0xFFFF)

5 CoilQnty For FCTCODE 1 or 2, QUANTITY is invalid (valid are values > 0 and <= 2032)

6 RegQnty For FCTCODE 3 or 4, QUANTITY is invalid (valid are values > 0 and <= 127)

7 Db_No Data block with DB_NO is not loaded

8 Db_Strta DB_STRTADD is invalid

Status information received in the response is displayed via QRESPCOD.

QRESPCOD Output Description

0 OK No error

1 ILLEGAL FCT Illegal function call

2 ADDR ERR Illegal address

3 DATA ERR Illegal data value

4 DEV ERR Error in the device that cannot be eliminated

5 TIMEOUT Timeout

15 Waiting for Response

A quality code is shown for all output values together via QC.

QC Description

16#80 Valid value

16#60 Simulation value

16#48 Substitute value

16#00 Invalid value

4.3.5 Signalling behavior

The block has no signalling behavior.

Page 46: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

46

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

4.3.6 CFC block representation

4.3.7 Parameter list

IO Parameter IO type Default Comment

I CONNECT ANY CFC connection to MODTCP_COMRED/_T block

I DEV_ID INT -1 Device ID /Slave address 1-255; -1 ID adopted from COM block

I FCTCODE INT 4 Function code [1, 2, 3, 4]

I STRTADD DINT 0 Register starting address [0..0xFFFF]

I QUANTITY INT 1 Quantity of coils (<=2032 bits) or registers (<=127 words)

I DB_NO INT 0 Number of the DB where to copy the data; if 0 don't copy

I DB_STRTADD INT 0 In the DB, start address for the data

I CHG_BYTE BOOL 0 Interchange Low and High bytes in each word from the output values (allowed with FCTCODE 3 and 4)

I CHG_WORD BOOL 0

Interchange Low and High words in each double word from the output values (allowed with FCTCODE 3 and 4, QUANTITY should be even)

I SUB_ACT BOOL 0 Activate substitution values, if QBAD is true

I SUB_VAL1 WORD 0 1st word substitution value

I ...

I SUB_VAL127 WORD 0 127th word substitution value

I SIM_ACT BOOL 0 Activate simulation values (overrides normal and substitution values)

Page 47: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

47

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

I SIM_VAL1 WORD 0 1st word simulation value

I ...

I SIM_VAL127 WORD 0 127th word simulation value

I ROR_EN BOOL 0 Enables the „read on request” feature

I RDRQ BOOL 0 Initiates a read request on raising edge

I EXECRATE TIME 4s Execution rate when scheduling is used

I WDTIMER TIME 6s Create a warning when execution rate drops below this value

I SCHEDULER BYTE 0 Sets the scheduling mechanism

O QC BYTE 0 Quality code (one for all values)

O QBAD BOOL 0 General error / quality code

O QLNKF BOOL 0 Link failure

O QPARF INT 0 Parameter error

O QRESPCOD INT 0 See Table in error handling

O VAL1 WORD 0 1st word value read

O ...

O VAL127 WORD 0 127th word value read

O CLRTR BOOL 0 “Clear to read”; indicates if the block is ready to process read request

O QWDTIMER BOOL 0 Indicates violation of the configured WDTIMER

Page 48: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

48

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

4.4 Example applications in CFC

4.4.1 Communication via CP

Example 1 where 6 values from address 0 in a Modbus slave, here this corresponds to the register numbers 40001 to 40006, are written and read again. IF using FB510, TCON=0 has to be set (the parameters for use of internal PN interface is set to invisible in this example).

Page 49: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

49

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

Example 2 using an additional communication block to increase update speed (Ref. 2.5).

Page 50: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

50

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

Example 3 - Using an additional communication block to explicitly monitor the connection with the watchdog. In case of a connection failure a connection switch over will be forced.

Attention: In example 3, with the forwarding of the ACTCON to the ACTCONIN parameter for connection switching, the same physical connections must be used for both communi-cation blocks. Be careful in setting the LADDRx and CONN_IDx parameters. The parameters LADDRx have to be identical on both blocks as seen in this example LADDR0=16#3FF7 and LADDR1=16#3FF6. The logical connection for x=0 must start from the same CP (normally CP0). This is also valid for x=1 (normally CP1). COMRED1 handles the actual data commu-nication using two connections. In this case they both have ID=1. COMRED2 handles only the watchdog communication using two connections with ID=2.

If you are using more than one communication block like in example 2 and 3 each block requires a separate logical connection between Modbus Master and Slave for communica-tion (see highlighted parameters). CONN_ID0 and CONN_ID1 don’t have to be the same as in the examples.

The connections for CPUERR0 and CPUERR1 are interconnected with the outputs CPUERR_0 and CPUERR_1 of the CPU Function Blocks 'OB_BEGIN', which have been automatically in-serted in a system chart via the "Generate module driver" function.

Page 51: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

51

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

4.4.2 Open IE communication via CPU PN (only possible with FB510)

Example 1 where 6 values from address 0 in a Modbus slave, here this corresponds to the register numbers 40001 to 40006, are written and read again. Each connection has its own ID (ex. TCON_ID0=1 and TCON_ID2=2).

Page 52: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

52

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

Example 2 using an additional communication block to increase update speed (Ref. 2.5). Each con-nection has its own ID (ex. COMRED1 block TCON_ID0=1 and TCON_ID2=2, COMRED2 block TCON_ID0=3 and TCON_ID2=4).

Page 53: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

53

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

Example 3 - Using an additional communication block to explicitly monitor the connection with the watchdog. In case of a connection failure a connection switch over will be forced.

Attention: In example 3, with the forwarding of the ACTCON to the ACTCONIN parameter for connection switching, the same physical connections must be used for both communi-cation blocks. COMRED1 handles the actual data communication using two connections. In this case they both have ID=1. COMRED2 handles only the watchdog communication using two connections with ID=2.

The parameters TCON0/1 should have different values

The connections for CPUERR0 and CPUERR1 are interconnected with the outputs CPUERR_0 and CPUERR_1 of the CPU Function Blocks 'OB_BEGIN', which have been automatically in-serted in a system chart via the "Generate module driver" function.

Page 54: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

54

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

4.4.3 Using RMS Scheduling

Example 1: Communication block in RMS scheduling operation mode. For each block RMS is configured as scheduler. The attached request blocks in this configuration create a workload of 69%. For request blockst he inputs SCHEDULER, EXECRATE and WDTIMER are relevant. This example uses redundant open communication via the integrated PN Inter-face.

Configuration of EDF is analogue but allows for higher workloads.

Page 55: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

55

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

Example 2: Using RMS on specific request blocks to speed up the average cycle time. The scheduler on the communication block is disabled. All request blocks where SCHEDULING is set to NONE are executed cyclically. By slowing down less important requests the aver-age cycle time can be reduced significantly.

Page 56: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

56

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

4.5 W1R_SCALE - Conversion block

Type/number FB 519

4.5.1 Function and mode of operation

This block is used for converting a 16-bit value (provided by a word) into a REAL value, taking into account a specified linear scaling. The values processed by this block are usual-ly analog values.

The algorithm is as follows:

PV_OUT := ((HI_RANGE - LO_RANGE)*((X - MIN_RAW)* 1/(MAX_RAW-MIN_RAW)) + LO_RANGE)* FACTOR;

X stands for the input value (PV_IN) that was converted into the REAL data type.

4.5.2 Parameterizing and interconnecting

The 16-bit input value (the measured variable) is specified in PV_IN.

The range of the input value corresponds to the range of values of a 16-bit integer (-32768 [8000] to +32767 [7FFF]).

The limit value for the upper range of the measuring signal is specified in HI_RANGE.

The limit value for the lower range of the measuring signal is specified in LO_RANGE.

The upper limit of the measuring range is specified in MAX_RAW.

The lower limit of the measuring range is specified in MIN_RAW.

An amplification factor can be specified in FACTOR.

The calculated output variable (measuring signal) is output to PV_OUT.

The values at the input can be adapted by means of the CHG_BYTE switch. With CHG_BYTE = TRUE, the High byte and Low byte of the input word are interchanged.

4.5.3 Calling OBs

The calling OB is the cyclic interrupt OB3x into which you integrate the block (e.g. OB 35) and the following OB into which the block is also integrated (automatically in the CFC):

o OB100 Restart (warm restart)

4.5.4 Error handling

Possible incorrect parameterizations are indicated via QPARF.

QPARF Output Description

0 0 No error

1 InvRange Invalid range indicated

Page 57: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

57

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

QPARF Output Description

(HI_RANGE must be greater than LO_RANGE)

2 InvRawLi

Invalid limits for the raw values

(MAX_RAW must be greater than MIN_RAW and MAX_RAW <= 32767.0 and MIN_RAW >= -32768.0 apply)

4.5.5 Signaling behavior

The block has no signaling behavior.

4.5.6 CFC block representation

4.5.7 Parameter list

IO Parameter IO type Default Comment

I PV_IN WORD 0 Input value

I HI_RANGE REAL 100 High range of process value

I LO_RANGE REAL 0 Low range of process value

I MAX_RAW REAL 100 Max. raw value of process value

I MIN_RAW REAL 0 Min. raw value of process value

I FACTOR REAL 1 Scaling factor

I CHG_BYTE BOOL 0 1: Interchange Low and High byte in PV_IN

O PV_OUT REAL Process value as real

O QPARF INT 0 Parameter error

Page 58: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

58

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

4.6 W2R_SCALE - conversion block

Type/number FB 520

4.6.1 Function and mode of operation

This block is used for converting a 32-bit value (comprising two words) into a REAL value, taking into account a specified linear scaling. The values processed by this block are usual-ly analog values.

The algorithm is as follows:

PV_OUT := ((HI_RANGE - LO_RANGE)*((X - MIN_RAW)* 1/(MAX_RAW-MIN_RAW)) + LO_RANGE)* FACTOR;

X stands for the input value (comprising PV_IN1 as high word and PV_IN2 as low word) that was converted into the REAL data type.

4.6.2 Parameterizing and interconnecting

The 32-bit input value (the measured variable) is specified in PV_IN (as high word) and PV_IN2 (as low word).

The range of the input value (given by the 2 words in PV_IN1 and PV_IN2) corresponds to the range of values of a 32-bit integer (-2 147 483 648 [8000 FFFF] to +2 147 483 647 [7FFF FFFF]).

The limit value for the upper range of the measuring signal is specified in HI_RANGE.

The limit value for the lower range of the measuring signal is specified in LO_RANGE.

The upper limit of the measuring range is specified in MAX_RAW.

The lower limit of the measuring range is specified in MIN_RAW.

An amplification factor can be specified in FACTOR.

The calculated output variable (measuring signal) is output to PV_OUT.

The values at the inputs can be adapted with the switches CHG_BYTE and CHG_WORD. With CHG_BYTE = TRUE, the High byte and Low byte of both input words are interchanged. With CHG_WORD = TRUE, the High word and Low word in the double word are inter-changed. The double word is put together using the two words at the input. Usually the word at the PV_IN1 input is the high word and the word at the PV_IN2 input is the low word.

4.6.3 Calling OBs

The calling OB is the cyclic interrupt OB3x into which you integrate the block (e.g. OB 35) and the following OB into which the block is also integrated (automatically in the CFC):

o OB100 Restart (warm restart)

Page 59: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

59

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

4.6.4 Error handling

Possible incorrect parameterizations are indicated via QPARF.

QPARF Output Description

0 0 No error

1 InvRange Invalid range indicated

(HI_RANGE must be greater than LO_RANGE!)

2 InvRawLi

Invalid limits for the raw values

(MAX_RAW must be greater than MIN_RAW and MAX_RAW <= 2 147 483 647.0 and MIN_RAW >= -2 147 483 648.0 apply

4.6.5 Signaling behavior

The block has no signaling behavior.

4.6.6 CFC block representation

4.6.7 Parameter list

IO Parameter IO type Default Comment

I PV_IN1 WORD 0 Input value1 (High Word)

I PV_IN2 WORD 0 Input value2 (Low Word)

I HI_RANGE REAL 100 High range of process value

I LO_RANGE REAL 0 Low range of process value

I MAX_RAW REAL 100 Max. raw value of process value

I MIN_RAW REAL 0 Min. raw value of process value

I FACTOR REAL 1 Scaling factor

I CHG_BYTE BOOL 0 1: Interchange Low and High byte in PV_IN1 and PV_IN2

Page 60: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

60

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

IO Parameter IO type Default Comment

I CHG_WORD BYTE 0 1: Interchange High (PV_IN1) and Low Word (PV_IN2)

O PV_OUT REAL Process value as real

O QPARF INT 0 Parameter error

Page 61: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

61

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

4.7 R1W_SCALE – conversion block

Type/number FB 539

4.7.1 Function and mode of operation

This block is used for converting a REAL-value to a WORD, taking into account a specified linear scaling. The values processed by this block are usually analog values.

The algorithm is as follows:

X := ((HI_RANGE - LO_RANGE)*((PV_IN - MIN_RAW)* 1/(MAX_RAW-MIN_RAW)) + LO_RANGE)* FACTOR;

X stands for the output value (PV_OUT) that was converted into the WORD data type.

4.7.2 Parameterizing and interconnecting

The REAL input value (the measured variable) is specified in PV_IN. The range of the input value corresponds to the range of values of a 16-bit integer (-32768 [8000] to +32767 [7FFF]).

The limit value for the upper range of the measuring signal is specified in HI_RANGE.

The limit value for the lower range of the measuring signal is specified in LO_RANGE.

The upper limit of the measuring range is specified in MAX_RAW.

The lower limit of the measuring range is specified in MIN_RAW.

An amplification factor can be specified in FACTOR.

The calculated output variable (measuring signal) is output to PV_OUT.

The values at the output can be adapted by means of the CHG_BYTE switch. With CHG_BYTE = TRUE, the High byte and Low byte of the output word are interchanged.

4.7.3 Calling OBs

The calling OB is the cyclic interrupt OB3x into which you integrate the block (e.g. OB 35) and the following OB into which the block is also integrated (automatically in the CFC):

o OB100 Restart (warm restart)

4.7.4 Error handling

Possible incorrect parameterizations are indicated via QPARF.

QPARF Output Description

0 0 No error

1 InvRange Invalid range indicated

(HI_RANGE must be greater than LO_RANGE)

Page 62: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

62

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

QPARF Output Description

2 InvRawLi

Invalid limits for the raw values

(MAX_RAW must be greater than MIN_RAW and MAX_RAW <= 32767.0 and MIN_RAW >= -32768.0 apply)

3 InvScalV Invalid limits for the values which should be converted

(-32768.0 < PV_IN < 32767.0)

4.7.5 CFC block representation

4.7.6 Parameter list

IO Parameter IO type Default Comment

I PV_IN REAL 0 Input value

I HI_RANGE REAL 100 High Range of process value

I LO_RANGE REAL 0 Low Range of process value

I MAX_RAW REAL 100 Max Raw value of process value

I MIN_RAW REAL 0 Min Raw value of process value

I FACTOR REAL 1 Scaling factor

I CHG_BYTE BOOL 0 1: Interchange Low- and High-byte in PV_IN

O PV_OUT WORD Process value as word

O QPARF INT 0 Parameter error

Page 63: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

63

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

4.8 R2W_SCALE - conversion block

Type/number FB 540

4.8.1 Function and mode of operation

This block is used for converting a REAL-value to a 32-bit value comprising two words, tak-ing into account a specified linear scaling. The values processed by this block are usually analog values.

The algorithm is as follows:

X := ((HI_RANGE - LO_RANGE)*((PV_IN - MIN_RAW)* 1/(MAX_RAW-MIN_RAW)) + LO_RANGE)* FACTOR;

X stands for the output value (PV_OUT) that was converted into the WORD data type (comprising PV_OUT1 as high word and PV_OUT2 as low word).

4.8.2 Parameterizing and interconnecting

The REAL input value (the measured variable) is specified in PV_IN. The range of the input value corresponds to the range of values of a 32-bit integer (-2 147 483 648 [8000 FFFF] to +2 147 483 647 [7FFF FFFF]).

The limit value for the upper range of the measuring signal is specified in HI_RANGE.

The limit value for the lower range of the measuring signal is specified in LO_RANGE.

The upper limit of the measuring range is specified in MAX_RAW.

The lower limit of the measuring range is specified in MIN_RAW.

An amplification factor can be specified in FACTOR.

The calculated output variable (measuring signal) is output to PV_OUT1 and PV_OUT2.

The values at the outputs can be adapted with the switches CHG_BYTE and CHG_WORD. With CHG_BYTE = TRUE, the High byte and Low byte of both output words are inter-changed. With CHG_WORD = TRUE, the High word and Low word in the double word are interchanged. The double word is put together using the two words at the output. Usually the word at the PV_OUT1 input is the high word and the word at the PV_OUT2 input is the low word.

4.8.3 Calling OBs

The calling OB is the cyclic interrupt OB3x into which you integrate the block (e.g. OB 35) and the following OB into which the block is also integrated (automatically in the CFC):

o OB100 Restart (warm restart)

Page 64: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

64

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

4.8.4 Error handling

Possible incorrect parameterizations are indicated via QPARF.

QPARF Output Description

0 0 No error

1 InvRange Invalid range indicated

(HI_RANGE must be greater than LO_RANGE)

2 InvRawLi

Invalid limits for the raw values

(MAX_RAW must be greater than MIN_RAW and MAX_RAW <= 2 147 483 647.0 and MIN_RAW >= -2 147 483 648.0 apply)

3 InvScalV Invalid limits for the values which should be converted

(-2 147 483 648.0 < PV_IN < 2 147 483 647.0)

4.8.5 CFC block representation

4.8.6 Parameter list

IO Parameter IO type Default Comment

I PV_IN REAL 0 Input value

I HI_RANGE REAL 100 High Range of process value

I LO_RANGE REAL 0 Low Range of process value

I MAX_RAW REAL 100 Max Raw value of process value

I MIN_RAW REAL 0 Min Raw value of process value

I FACTOR REAL 1 Scaling factor

I CHG_BYTE BOOL 0 1: Interchange Low- and High-Byte in PV_OUT1 and PV_OUT2

I CHG_WORD BYTE 0 1: Interchange High- (PV_OUT1) and Low-Word (PV_OUT2)

O PV_OUT1 WORD Process value as word1 (H)

Page 65: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

65

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

IO Parameter IO type Default Comment

O PV_OUT2 WORD Process value as word2 (L)

O QPARF INT 0 Parameter error

Page 66: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

66

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

4.9 W2R_T - transportation block

Type/number FB 541

4.9.1 Function and mode of operation

This block is used for transporting a 32-bit value (comprising two words) to a REAL value. The block just moves the binary contents of the DWORD to the REAL, no format conversion takes place.

4.9.2 Parameterizing and interconnecting

The 32-bit input value is specified in V_IN1 and V_IN2. The output value is given at PV_OUT.

4.9.3 Calling OBs

The calling OB is the cyclic interrupt OB3x into which you integrate the block (e.g. OB 35) and the following OB into which the block is also integrated (automatically in the CFC):

o OB100 Restart (warm restart)

4.9.4 CFC block representation

4.9.5 Parameter list

IO Parameter IO type Default Comment

I V_IN1 WORD 0 Input value as word from Register 1

I V_IN2 WORD 0 Input value as word from Register 2

O V_OUT REAL output value as real

Page 67: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

67

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

4.10 R2W_T - transportation block

Type/number FB 542

4.10.1 Function and mode of operation

This block is used for transporting a REAL-value to a 32-bit value (comprising two words). The block just moves the binary contents of the REAL to the DWORD, no format conversion takes place.

4.10.2 Parameterizing and interconnecting

The REAL input value is specified in V_IN. The output value is given at V_OUT1 and V_OUT2.

4.10.3 Calling OBs

The calling OB is the cyclic interrupt OB3x into which you integrate the block (e.g. OB 35) and the following OB into which the block is also integrated (automatically in the CFC):

o OB100 Restart (warm restart)

4.10.4 CFC block representation

4.10.5 Parameter list

IO Parameter IO type Default Comment

I V_IN REAL 0 Input value

O V_OUT1 WORD Output value as word in Register 1

O V_OUT2 WORD Output value as word in Register 2

Page 68: Modbus TCP/IP PCS 7 driver blocks - Siemens · 6 A documentation by: Siemens. © Siemens AG 2014. All rights reserved. 2.1 Step 7 block library The driver blocks are installed with

68

A documentation by: Siemens. © Siemens AG 2014. All rights reserved.

www.siemens.com [email protected] Tel: +49 (0) 721/595 - 7522 All rights reserved. All trademarks used are owned by Siemens or their respective own-ers. © Siemens AG 2013

Siemens AG I CS VS CMR DEL-3 Siemensallee 84 76187 Karlsruhe GERMANY