show the entry list

ET 200pro -- Configuring and programming communication -- Using communication blocks 
What restrictions are there for active jobs when communicating with SFC 58 / SFC 59 and SFB 52 / SFB 53 via PROFIBUS DP and PROFINET IO? 
How do you program the communication blocks FB63 "TSEND", FB64 "TRCV", FB65 "TCON" and FB66 "TDISCON" in order to use the TCP protocol for data exchange by means of the integrated PROFINET interface of an S7-300/S7-400 CPU? 
How do you program the communication blocks FB63 "TSEND", FB64 "TRCV", FB65 "TCON" and FB66 "TDISCON" in order to use the ISO-on-TCP protocol for data exchange via the integrated PROFINET interface of an S7-300/S7-400 CPU or via the CP443-1 Advanced? 
How do you program the communication blocks FB67 "TUSEND", FB68 "TURCV", FB65 "TCON" and FB66 "TDISCON" in order to use the UDP protocol for data exchange via the integrated PROFINET interface of an S7-300/S7-400 CPU? 

What restrictions are there for active jobs when communicating with SFC 58 / SFC 59 and SFB 52 / SFB 53 via PROFIBUS DP and PROFINET IO?Go to beginning
Part number:

Configuration Notes:
System functions and blocks SFB52 "RDREC" / SFC59 "RD_REC" (read record) are used to read data records of a component (module) of a DP slave/PROFINET IO device. System functions and blocks SFB53 "WRREC" / SFC58 "WR_REC" (write record) are used to write data records to a component (module) of a DP slave/PROFINET IO device.

Depending on the CPU used, the number of active jobs of the system functions and blocks SFB53/SFC58 and SFB52/SFC59 is limited.

The following table provides information about how many active jobs of the system functions and blocks SFB53/SFC58 and SFB52/SFC59 your CPU supports simultaneously.
 
System function/
system block
SFB 52 "RDREC"/
SFB 53 "WRREC"
SFC 59 "RD_REC"/
SFC 58 "WR_REC"
Explanation Data record from DP slave, PROFINET IO device Data record from DP slave
IM154 (ET 200pro)
IM151 (ET 200S)
IM147 (ET 200X)
4 jobs together with SFC 58/59 4 jobs together with SFB 52/53
CPU 312, CPU 313, CPU 314
CPU 315, CPU 316
4 jobs together with SFC 58/59 4 jobs together with SFB 52/53
CPU 317, CPU 319
CPU 318-2
8 jobs together with SFC 58/59 8 jobs together with SFB 52/53
CPU 41x1) 8 jobs each per PROFIBUS DP segment and PROFINET IO system 8 jobs each per PROFIBUS DP segment and PROFINET IO system
1) The number of simultaneous jobs on external PROFIBUS DP segments or PROFINET IO systems must not exceed 32 jobs per SFC/SFB.

Example:
With a CPU 414-2DP, a maximum of 48 jobs per SFC/SFB can be executed at the same time (8 each on the two PROFIBUS DP segments that are connected to the integrated interfaces of the CPU, and 32 on external PROFIBUS DP segments and PROFINET IO systems).

Rules:

  • There are no restrictions for simultaneous jobs in the subracks (CR, ER). The SFCs run synchronously via the backplane bus. Any number of synchronous SFCs can be called.
  • If you are operating multiple communication partners on the PROFIBUS network, then please make sure that never more than the specified jobs are active at the same time. Here one SFC/SFB can run several CPU cycles long.
  • The restrictions listed in this entry for the active jobs of the system functions and blocks SFB53/SFC58 and SFB52/SFC59 also apply to the blocks that call these system functions and blocks internally. These include the blocks FM_CS, PID_FM and FMCS_PID, for example.
    Example:
    When communicating with an FM 355 (4 channels parameterized) via the FMCS_PID block, 4 read jobs are occupied.

Note:
System functions SFC58/59 are available on all CPUs.

How do you program the communication blocks FB63 "TSEND", FB64 "TRCV", FB65 "TCON" and FB66 "TDISCON" in order to use the TCP protocol for data exchange by means of the integrated PROFINET interface of an S7-300/S7-400 CPU?Go to beginning
Part number:

Description
The CPUs with integrated PROFINET interface and the WinAC RTX support open IE communication.

Entry ID 18909487 gives you an overview of the communication services that are supported by the CPUs with integrated PROFINET interface and by the WinAC RTX. This overview gives you information about which protocols of open IE communication are supported by the CPUs with integrated PROFINET interface and by the WinAC RTX.

The following communication blocks are available for "Open User Communication" via Industrial Ethernet using TCP Protocol:

  • FB65 "TCON" for establishing the connection
  • FB66 "TDISCON" for ending the connection
  • FB63 "TSEND" for sending data
  • FB64 "TRECV" for receiving data

These communication blocks are available in the Standard Library -> Communication Blocks.
Copy the latest versions of the above-mentioned communication blocks from the standard library into your user program and then call them in your user program.
The connection data for setting up the TCP connection is saved in a data structure. The data structure "OUCW_2" will be used in this example. This is stored in the DB1 data block and is parameterized by the user.

Note

  • Use the "Open Communication Wizard" for simple creation of connection data. This is available for downloading in Entry ID 98957840.
  • The TCP connection is not configured in NetPro.

Table 01 shows the "OUCW_2" data structure in which the connection data is stored.
 
Byte Parameter Data type Description
0 to 1 block_length WORD Length of the "OUCW_2" data structure
2 to 3 id BYTE Reference to this connection
Value range: w#16#0001 to w#16#0FFF
You must specify the value of this parameter for the ID in the block concerned.
4 connection_type BYTE TCP protocol version: B#16#11
5 active_est BOOLEAN ID for how the connection is established.
  • FALSE: connection established passively
  • TRUE: connection established actively
6 local_device_id BYTE Communication through the integrated PN interface of the CPU 315-2 PN/DP: B#16#02
7 local_tsap_id_len BYTE Length used for the local_tsap_id parameter
Possible values if connection_type = B#16#11: 0 or 2
(active side: 0 or 2, passive side: 2)
8 rem_subnet_id_len BYTE This parameter is not used currently. It has the value B#16#00.
9 rem_staddr_len BYTE Length of the address of the remote connection end point:
  • 0: unspecified, which means that the rem_staddr parameter is irrelevant
  • 4: valid IP address in the rem_staddr parameter.
10 rem_tsap_id_len BYTE Length used for the rem_tsap_id parameter
Possible values if connection_type = B#16#11: 0 or 2
11 next_staddr BYTE Length used for the next_staddr parameter
12 to 27 local_tsap_id ARRAY [1..16] of BYTE Local port number: 2000, for example
local_tsap_id[1] = B#16#7 (high byte of the port number in hexadecimal format)
local_tsap_id[2] = B#16#D0 (low byte of the port number in hexadecimal format)
local_tsap_id[3-16] = B#16#00
28 to 33 rem_subnet_id ARRAY [1..6] of BYTE This parameter is not used currently. It has the value B#16#00.
34 to 39 rem_staddr ARRAY [1..6] of BYTE IP address of the remote connection end point: 192.168.0.30
rem_staddr[1] = B#16#C0
rem_staddr[2] = B#16#A8
rem_staddr[3] = B#16#00
rem_staddr[4] = B#16#1E
rem_staddr[5-6] = B#00 (reserved)
40 to 55 rem_tsap id ARRAY [1..16] of BYTE Port number of the remote connection end point: 2000, for example
local_tsap_id[1] = B#16#7 (high byte of the port number in hexadecimal format)
local_tsap_id[2] = B#16#D0 (low byte of the port number in hexadecimal format)
local_tsap_id[3-16] = B#16#00
56 to 61 next_staddr ARRAY [1..6] of BYTE next_staddr[1-6] = B#16#00
62-63 spare WORD Reserve, the parameter has the value W#16#0000.
Table 01

Description of the sample program
The S7 program contains the call of the FB65 "TCON" and the DB1 data block of the "OUCW_2" data structure in which the connection data for setting up the TCP connection are stored. The S7 program also includes the call of the function blocks FB63 "TSEND" and FB64 "TRECV" from the Standard Library -> Communication Blocks. The FB63 "TSEND" is for sending data to an S7 station or to an S5 station, to a PC station or to a third-party system. The FB64 "TRECV" is for receiving data from another S7 station or an S5 station, from a PC station or from a third-party system.

First create the hardware configuration for the S7-300 station. Configure Marker byte 100 as clock marker. The send job is triggered by this clock marker. Save and compile the hardware configuration of your S7-300 station and load it into the CPU.

The STEP 7 program consists of the blocks OB100, OB1, FB1, DB11, DB1, DB100, DB200 and FB63, FB64, FB65 and FB66.

OB100
The OB100 is a restart OB and is run when the CPU is restarted (warm start). In this OB the first communication trigger is enabled with marker M0.3.

OB1
OB1 is called cyclically. The FB1 is called in OB1 with the instance data block DB11, with the marker M0.3 as INIT_COM parameter and with the marker 10.0 as ABORT parameter. The marker M0.3 is reset in OB1 after the FB1 has been called.


Fig. 01

FB1
The FB1 is called cyclically in OB1. The following function blocks are called in FB1.

  • FB65 "TCON"
  • FB63 "TSEND",
  • FB64 "TRCV"
  • FB66 "TDISCON"

Define connection number
You can change the connection number separately. Change the connection number in network 2 of FB1 in accordance with your configuration. The connection number is stored in a static tag and so in the instance data block DB11.
The connection number "2" is defined in this example.


Fig. 02

Connection setup
Establishing a connection is started by a positive edge in the "REQ" input parameter of the FB65 "TCON". The "OUCW_2" data structure with the connection parameters is incorporated in the data block DB1.
On the input parameter "CONNECT" of the FB65 "TCON", the memory area is specified that contains the connection parameterization.
The connection is set up at system start and remains until it is disabled with FB66 "TDISCON", or the CPU goes into STOP mode, or the power supply is switched off.


Fig. 03

The send request is triggered by a positive edge at the input parameter "REQ" of the FB63 "TSEND". The send request trigger is controlled by clock marker M100.6 and the variable "SEND_BUSY". If the send request is running, "SEND_BUSY" is set. It is then not possible to trigger a new send request.
You specify the memory area that contains the data to be sent at the input parameter "DATA".
You enter the number of bytes to be sent at the input parameter "LEN".
In this example the Send data is stored in DB100. 100 bytes of data is sent to the communication partner.
The output parameters "DONE", "ERROR" and "STATUS" are required for job evaluation.


Fig. 04

If the send request is successfully completed, "SEND_BUSY" is reset. A new send job can now be triggered.
If the send request is completed with an error, then "SEND_BUSY" is likewise reset and the value of the output parameter "STATUS" of the FB63 is saved for an error analysis.


Fig. 05


Fig. 06

The data can be received as soon as the TCP connection is established.
At the input parameters "DATA" and "LEN" you specify the address and length of the data area where the received data is saved.
In this example 100 bytes of data are received and stored in DB200.


Fig. 07

The output parameter "NDR" is for showing that new data has been received. The "RCVD_LEN" output parameter indicates the length of the data received. If the data is received successfully, then the value of the "RCVD_LEN" output parameter is saved.


Fig. 08

If the data is not received successfully, then the value of the "STATUS" output parameter is saved and evaluated.


Fig. 09

You can clear down the TCP connection specifically with the FB66 "TDISCON". You start the request to clear down the TCP connection with a positive edge at the "REQ" input parameter of the FB66 "TDISCON".


Fig. 10

Note
The TCP protocol is used in this sample program for data transfer, which means that in the "OUCW_2" data structure the "connection_type" parameter is defined with the value "B#16#11".
The S7-300 CPUs V2.3 support the TCP Compatibility Mode. If you want to run the sample program on an S7-300 CPU V2.3, then in the "OUCW_2" data structure you change the value of the "connection_type" parameter to "B#16#01".

The STEP 7 project as a download
The STEP 7 project contains a sample program for calling FB1 and the function blocks FB65 "TCON", FB66 "TDISCON", FB63 "TSEND" and FB64 "TRECV" with status evaluation. It was created with STEP 7 V5.5 SP3.

Sample_open_TCP.zip ( 286 KB )

Configuring additional TCP connections
To configure additional TCP connections, you copy the FB1 so that you receive another function block (such as FB101). Change the parameters and generate a new instance data block.

Further Information

  • Detailed information on open communication over Industrial Ethernet is available in the manual "System and Standard Functions for S7-300/400 Volume 1 and Volume 2" in Entry ID: 44240604.
  • Instructions for configuring a TCP connection for communication by way of S7-300 and S7-400 Industrial Ethernet CPs are available in Entry ID: 22385024.
How do you program the communication blocks FB63 "TSEND", FB64 "TRCV", FB65 "TCON" and FB66 "TDISCON" in order to use the ISO-on-TCP protocol for data exchange via the integrated PROFINET interface of an S7-300/S7-400 CPU or via the CP443-1 Advanced?Go to beginning
Part number:

Description
You can use, for example, the "Open User Communication" over Industrial Ethernet for data exchange via the integrated PROFINET interface of a CPU or via CP4431 Advanced. The protocols below are supported for this:

  • TCP
  • ISO-on-TCP
  • UDP

The following communication blocks are available for "Open User Communication" via Industrial Ethernet using the ISO-on-TCP Protocol:

  • FB65 "TCON" for establishing the connection
  • FB66 "TDISCON" for ending the connection
  • FB63 "TSEND" for sending data
  • FB64 "TRECV" for receiving data

These communication blocks are available in the Standard Library -> Communication Blocks.
Copy the latest versions of the above-mentioned communication blocks from the standard library into your user program and then call them in your user program.
The connection data for establishing the ISO-on-TCP connection are saved in a data structure. The data structure "OUCW_1" will be used in this example. This is stored in the DB1 data block and is parameterized by the user.

Note

  • Use the "Open Communication Wizard" for simple creation of connection data. This is available for downloading in Entry ID 98957840.
  • The ISO-on-TCP connection is not configured in NetPro.

Table 01 shows the "OUCW_1" data structure in which the connection data is stored.
 
Byte Parameter Data type Description
0 to 1 block_length WORD Length of the "OUCW_1" data structure
2 to 3 id BYTE Reference to this connection
Value range: W#16#0001 to W#16#0FFF
You must specify the value of this parameter for the ID in the block concerned.
4 connection_type BYTE ISO-on-TCP protocol version: B#16#12
5 active_est BOOLEAN ID for how the connection is established.
  • FALSE: connection established passively
  • TRUE: connection established actively
6 local_device_id BYTE Communication through the integrated PROFINET interface of the CPU 315-2 PN/DP: B#16#02
7 local_tsap_id_len BYTE Length used for the local_tsap_id parameter
Possible values if connection_type = B#16#12: 2 to 16
8 rem_subnet_id_len BYTE This parameter is not used currently. It has the value B#16#00.
9 rem_staddr_len BYTE Length of the address of the remote connection end point:
  • 0: unspecified, which means that the rem_staddr parameter is irrelevant
  • 4: valid IP address in the rem_staddr parameter.
10 rem_tsap_id_len BYTE Length used for the rem_tsap_id parameter
Possible values if connection_type = B#16#12: 0 or 2 to 16
  • active side: 2 to 16
  • passive side: 0 or 2 to 16 (0 means unspecified)
11 next_staddr_len BYTE Length used for the next_staddr parameter
12 to 27 local_tsap_id ARRAY [1..16] of BYTE Local TSAP, such as ISO1:
local_tsap_id[1] = B#16#49
local_tsap_id[2] = B#16#53
local_tsap_id[3] = B#16#4F
local_tsap_id[4] = B#16#31
local_tsap_id[5-16] = B#16#00

Note
In the case of CPUs that do not support the ASCII format for the TSAPs, then the first two bytes of the TSAP must be defined with the values B#16#E0 and B#16#02.

28 to 33 rem_subnet_id ARRAY [1..6] of BYTE This parameter is not used currently. It has the value B#16#00.
34 to 39 rem_staddr ARRAY [1..6] of BYTE IP address of the remote connection end point, such as 192.168.0.30:
rem_staddr[1] = B#16#C0
rem_staddr[2] = B#16#A8
rem_staddr[3] = B#16#00
rem_staddr[4] = B#16#1E
rem_staddr[5-6] = B#00 (reserved)
40 to 55 rem_tsap_id ARRAY [1..16] of BYTE TSAP of the remote connection end point, such as ISO1:
rem_tsap_id[1] = B#16#49
rem_tsap_id[2] = B#16#53
rem_tsap_id[3] = B#16#4F
rem_tsap_id[4] = B#16#31
rem_tsap_id[5-16] = B#16#00

Note
In the case of CPUs that do not support the ASCII format for the TSAPs, then the first two bytes of the TSAP must be defined with the values B#16#E0 and B#16#02.

56 to 61 next_staddr ARRAY [1..6] of BYTE next_staddr[1-6] = B#16#00

Note
If local_device_id=B#16#00, then here you specify the rack and slot of the (local) CP.

62-63 spare WORD Reserve, the parameter has the value W#16#0000.
Table 01

The CPUs below support the ASCII format for the TSAPs.

  • CPU 314C-2 PN/DP
  • CPU 315(F)-2 PN/DP, CPU 317(F)-2 PN/DP V3.1 and later
  • CPU 315T-3 PN/DP, CPU 317T-3 PN/DP, CPU 317TF-3 PN/DP
  • CPU 319(F)-3 PN/DP
  • CPU 414-3 PN/DP, CPU 416(F)-3 PN/DP V5.2 and later
  • CPU 414F-3 PN/DP, CPU 412-2 PN
  • CPU 412-5H PN/DP, CPU 414-5H PN/DP, CPU 416-5H PN/DP, CPU 417-5H PN/DP
  • IM 151(F)-8 PN/DP CPU V2.7 and later
  • IM 154(F)-8 CPU V3.2 and later

Description of the sample program
The S7 program contains the call of the FB65 "TCON" and the DB1 data block of the "OUCW_1" data structure in which the connection data for setting up the ISO-on-TCP connection are stored. The S7 program also includes the call of the function blocks FB63 "TSEND" and FB64 "TRECV" from the Standard Library -> Communication Blocks. The FB63 "TSEND" is for sending data to an S7 station or to an S5 station, to a PC station or to a third-party system. The FB64 "TRCV" is for receiving data from another S7 station or an S5 station, from a PC station or from a third-party system.

First create the hardware configuration for your S7-300 station. Configure Marker byte 100 as clock marker. The send job is triggered by this clock marker. Save and compile the hardware configuration of your S7-300 station and load it into the CPU.

The STEP 7 program consists of the blocks OB100, OB1, FB1, DB11, DB1, DB100, DB200 and FB63, FB64, FB65 and FB66.

OB100
The OB100 is a restart OB and is run when the CPU is restarted (warm start). In this OB the first communication trigger is enabled with marker M0.3.

OB1
OB1 is called cyclically. The FB1 is called in OB1 with the instance data block DB11, with the marker M0.3 as INIT_COM parameter and with the marker 10.0 as ABORT parameter. The marker M0.3 is reset in OB1 after the FB1 has been called.


Fig. 01

FB1
The FB1 is called cyclically in OB1. The following function blocks are called in FB1.

  • FB65 "TCON"
  • FB63 "TSEND"
  • FB64 "TRCV"
  • FB66 "TDISCON"

Define connection number
You can change the connection number separately. Change the connection number in network 2 of FB1 in accordance with your configuration. The connection number is stored in a static tag and so in the instance data block DB11.
The connection number "1" is defined in this example.


Fig. 02

Connection setup
Establishing a connection is started by a positive edge in the "REQ" input parameter of the FB65 "TCON". The "OUCW_1" data structure with the connection parameters is incorporated in the data block DB1.
On the input parameter "CONNECT" of the FB65 "TCON", the memory area is specified that contains the connection parameterization.
The connection is set up at system start and remains until it is disabled with FB66 "TDISCON", or the CPU goes into STOP mode, or the power supply is switched off.


Fig. 03

The send request is triggered by a positive edge at the input parameter "REQ" of the FB63 "TSEND". The send request trigger is controlled by clock marker M100.6 and the variable "SEND_BUSY". If the send request is running, "SEND_BUSY" is set. It is then not possible to trigger a new send request.
You specify the memory area that contains the data to be sent at the input parameter "DATA".
You enter the number of bytes to be sent at the input parameter "LEN".
In this example the Send data is stored in DB100. 100 bytes of data is sent to the communication partner.
The output parameters "DONE", "ERROR" and "STATUS" are required for job evaluation.


Fig. 04

If the send request is successfully completed, "SEND_BUSY" is reset. A new send job can now be triggered.
If the send request is completed with an error, then "SEND_BUSY" is likewise reset and the value of the output parameter "STATUS" of the FB63 is saved for an error analysis.


Fig. 05


Fig. 06

The data can be received as soon as the ISO-on-TCP connection is established.
At the input parameters "DATA" and "LEN" you specify the address and length of the data area where the received data is saved.
In this example 100 bytes of data are received and stored in DB200.


Fig. 07

The output parameter "NDR" is for showing that new data has been received. The "RECV_LEN" output parameter indicates the length of the data received.
If the data is received successfully, then the value of the "RCVD_LEN" output parameter is saved.


Fig. 08

If the data is not received successfully, then the value of the "STATUS" output parameter is saved and evaluated.


Fig. 09

You can disable the ISO-on-TCP connection with the FB66 "TDISCON". You start the request to disable the ISO-on-TCP connection via a positive edge on the input parameter "REQ" of the FB66 "TDISCON".


Fig. 10

The STEP 7 project as a download
The STEP 7 project contains a sample program for calling FB1 and the function blocks FB65 "TCON", FB66 "TDISCON", FB63 "TSEND" and FB64 "TRECV" with status evaluation. It was created with STEP 7 V5.5 SP3.

Sample_open_IoT.zip ( 285 KB )

Configuring additional ISO-on-TCP connections
To configure additional ISO-on-TCP connections you copy the FB1 so that you receive another function block (such as FB101). Change the parameters and generate a new instance data block.

Further Information

  • Detailed information on open communication over Industrial Ethernet is available in the manual "System and Standard Functions for S7-300/400 Volume 1 and Volume 2" in Entry ID: 44240604.
  • Instructions for configuring an ISO-on-TCP connection for communication via S7-300 and S7-400 CPs are available in Entry ID: 47885440.

How do you program the communication blocks FB67 "TUSEND", FB68 "TURCV", FB65 "TCON" and FB66 "TDISCON" in order to use the UDP protocol for data exchange via the integrated PROFINET interface of an S7-300/S7-400 CPU?Go to beginning
Part number:

Description
You can use the open communication of the PROFINET for data exchange via the integrated Industrial Ethernet interface of a CPU, for example. The protocols below are supported for this:

  • TCP
  • ISO-on-TCP
  • UDP

The following communication blocks are available for "Open User Communication" via Industrial Ethernet using UDP Protocol:

  • FB65 "TCON" for connecting the UDP end point
  • FB66 "TDISCON" for disconnecting the UDP end point
  • FB67 "TUSEND" for sending data
  • FB68 "TURCV" for receiving data

These communication blocks are available in the Standard Library -> Communication Blocks.
Copy the latest versions of the above-mentioned communication blocks from the standard library into your user program and then call them in your user program.
The parameters for connecting the UDP end point are saved in a data structure. The data structure "OUCW_2" will be used in this example. This is stored in the DB1 data block and is parameterized by the user.

Note

  • Use the "Open Communication Wizard" for easy establishment of the UDP end point. This is available for downloading in Entry ID 98957840.
  • The TCP connection is not configured in NetPro.

Table 01 shows the "OUCW_2" data structure in which the parameters for establishing the UDP end point are stored.
 
Byte Parameter Data type Description
0 to 1 block_length WORD Length of the "OUCW_2" data structure
2 to 3 id BYTE Reference to this connection between user program and communication layer of the operating system
Value range: w#16#0001 to w#16#0FFF
You must specify the value of this parameter for the ID in the block concerned.
4 connection_type BYTE UDP protocol version: B#16#13
5 active_est BOOLEAN ID for how the connection is established
You must give the value FALSE to this parameter.
6 local_device_id BYTE Communication through the integrated PN interface of the CPU 315-2 PN/DP: B#16#02
7 local_tsap_id_len BYTE Length used for the local_tsap_id parameter: 2 bytes
8 rem_subnet_id_len BYTE This parameter is not used currently. It has the value B#16#00.
9 rem_staddr_len BYTE This parameter is not used currently. It has the value B#16#00.
10 rem_tsap_id_len BYTE This parameter is not used currently. It has the value B#16#00.
11 next_staddr_len BYTE This parameter is not used currently. It has the value B#16#00.
12 to 27 local_tsap_id ARRAY
[1 ..16] of BYTE
Local port number: 2000, for example
local_tsap_id[1] = B#16#7 (high byte of the port number in hexadecimal format)
local_tsap_id[2] = B#16#D0 (low byte of the port number in hexadecimal format)
local_tsap_id[3-16] = B#16#00
28 to 33 rem_subnet_id ARRAY
[1 ..6] of BYTE
This parameter is not used currently.
rem_subnet_id[1-6] = B#16#00
34 to 39 rem_staddr ARRAY
[1 ..6] of BYTE
This parameter is not used currently.
rem_staddr[1-6] = B#16#00
40 to 55 rem_tsap_id ARRAY
[1 ..16] of BYTE
This parameter is not used currently.
rem_tsap_id[1-16] = B#16#00
56 to 61 next_staddr ARRAY
[1 ..6] of BYTE
This parameter is not used currently.
next_staddr[1-6] = B#16#0
62 to 63 spare WORD Reserve, the parameter has the value W#16#0000.
Table 01

Description of the sample program
The S7 program contains the call of the FB65 "TCON" and the data structure "OUCW_2", in which the parameters for establishing the UDP end point are stored. The S7 program also includes the call of the function blocks FB67 "TUSEND" and FB68 "TURCV" from the Standard Library -> Communication Blocks. The FB67 "TUSEND" is for sending data to an S7 station, to a PC station, or to a third-party system. The FB68 "TURCV" is for receiving data from an S7 station, from a PC station or from a third-party system.

First create the hardware configuration for your S7-300 station. Configure Marker byte 100 as clock marker. The send job is triggered by this clock marker. Save and compile the hardware configuration of your S7-300 station and load it into the CPU.

The STEP 7 program consists of the blocks OB100, OB1, FB1, DB11, DB1, DB100, DB200 and FB63, FB64, FB67 and FB68.

OB100
The OB100 is a restart OB and is run when the CPU is restarted (warm start). In this OB the first communication trigger is enabled with marker M0.3.

OB1
OB1 is called cyclically. The FB1 is called in OB1 with the instance data block DB11, with the marker M0.3 as INIT_COM parameter and with the marker M10.0 as ABORT parameter. The marker M0.3 is reset in OB1 after the FB1 has been called.


Fig. 01

FB1
The FB1 is called cyclically in OB1. The following function blocks are called in FB1.

  • FB65 "TCON"
  • FB67 "TUSEND"
  • FB68 "TURCV"
  • FB66 "TDISCON"

Define connection number
You can change the connection number separately. Change the connection number in network 2 of FB1 in accordance with your configuration.
The connection number is stored in a static tag and so in the instance data block DB11.
The connection number "3" is defined in this example.


Fig. 02

Establishing the connection
Connection of the UDP endpoint is started by a positive edge at the input parameter "REQ" of FB65 "TCON". The "OUCW_2" data structure with the parameters of the local UDP end point is incorporated in the data block DB1.
On the input parameter "CONNECT" of the FB65 "TCON", the memory area is specified that contains the parameterization of the local UDP endpoint.
The connection of the UDP endpoint is set up at system start and remains until it is disabled with FB66 "TDISCON", the CPU goes into STOP mode, or the power supply is switched off.


Fig. 03

The send job is triggered by a positive edge on the input parameter "REQ" of the FB67 "TUSEND". The send request trigger is controlled by clock marker M100.6 and the variable "SEND_BUSY". If the send request is running, "SEND_BUSY" is set. It is then not possible to trigger a new send request.
You specify the memory area that contains the data to be sent at the input parameter "DATA".
You enter the number of bytes to be sent at the input parameter "LEN".
In this example the Send data is stored in DB100. 100 bytes of data is sent to the communication partner.
At the input parameter "ADDR" you specify the address of the data area where the recipient's IP address is stored. In this example, the address parameters of the communication partner are stored in the data structure "OUCW_3". This is incorporated in the data block DB1.
The output parameters "DONE", "ERROR" and "STATUS" are required for job evaluation.


Fig. 04

Table 01 shows the "OUCW_1" data structure in which the connection data is stored.
 
Byte Parameter Data type Description
0 to 3 rem_ip_addr ARRAY
[1 .. 4] of BYTE
IP address of the remote partner, such as 192.168.0.30
rem_ip_addr[1] = B#16#C0
rem_ip_addr[2] = B#16#A8
rem_ip_addr[3] = B#16#00
rem_ip_addr[4] = B#16#1E
4 to 5 rem_port_nr ARRAY
[1 .. 2] of BYTE
Remote number: 2000, for example
local_tsap_id[1] = B#16#7 (high byte of the port number in hexadecimal format)
local_tsap_id[2] = B#16#D0 (low byte of the port number in hexadecimal format)
6 to 7 spare ARRAY
[1 .. 2] of BYTE
Reserve, the parameter has the value W#16#0000.
Table 02

If the send request is successfully completed, "SEND_BUSY" is reset. A new send job can now be triggered.
If the send request is completed with an error, then "SEND_BUSY" is likewise reset and the value of the output parameter "STATUS" of the FB67 is saved for an error analysis.


Fig. 05


Fig. 06

The data can be received as soon as the UDP endpoint is connected.
With the input parameter "DATA", you specify the address and length of the data area where the received data is saved.
In this example 100 bytes of data are received and stored in DB200.
At the input parameter "ADDR" you specify the address of the data area where the sender's IP address is stored. In this example, the address parameters of the communication partner are stored in the data structure "OUCW_3". This is incorporated in the data block DB1. Table 02 shows the "OUCW_3" data structure.


Fig. 07

The output parameter "NDR" is for showing that new data has been received. The "RECV_LEN" output parameter indicates the length of the data received.
If the data is received successfully, then the value of the "RCVD_LEN" output parameter is saved.


Fig. 08

If the data is not received successfully, then the value of the "STATUS" output parameter is saved and evaluated.


Fig. 09

You can disconnect the UDP end point specifically with the FB66 "TDISCON". You start the job to disconnect the UDP endpoint with a positive edge at the input parameter "REQ" of FB66 "TDISCON".


Fig. 10

The STEP 7 project as a download
The STEP 7 project contains a sample program for calling FB1 and the function blocks FB65 "TCON", FB66 "TDISCON", FB67 "TUSEND" and FB68 "TURCV" with status evaluation. It was created with STEP 7 V5.5 SP3.

Sample_open_UDP.zip ( 290 KB )

Configuring additional TCP connections
To configure additional UDP endpoints, you copy the FB1 so that you receive another function block (such as FB101). Change the parameters and generate a new instance data block. Using the Open Communication Wizard you create a new data structure in which parameters of the new UDP end point are stored.

Further Information

  • Detailed information on open communication over Industrial Ethernet is available in the manual "System and Standard Functions for S7-300/400 Volume 1 and Volume 2" in Entry ID: 44240604.
  • Instructions for configuring a UDP connection for communication by way of S7-300 and S7-400 Industrial Ethernet CPs are available in Entry ID: 47885893.

 Entry ID:30143683   Date:2014-11-20 
I regard this article....as helpfulas not helpful                                 






























mySupport
My Documentation Manager 
Newsletter 
CAx-Download-Manager 
Support Request
To this entry
Print
Create PDF 
Send to a friend
QuickLinks
Compatibility tool 
Topics
Help
Online Help
Guided Tour