Professional Documents
Culture Documents
Page 2 3 4 5 6 7 8 9 10 11 12 13 15 16 19 20 21 23 26
SEND-RECEIVE Interface in the CPU...................................................................................... CPU Cycle and Transmission Time.......................................................................................... Data Quantities per Job ....................................................................................................... User Data Area in the CPU....................................................................................................... Programming the SEND/RECEIVE Interface........................................................................... Typical Execution Sequence for the FCs in the CPU Cycle...................................................... The FCs..................................................................................................................................... Entering the FCs in the STEP 7 Library.................................................................................... General Notes on the FCs.......................................................................................................... Reactions to Incorrect Address Entries..................................................................................... FC AG_SEND/AG_LSEND...................................................................................................... Explanation of the Formal Parameters....................................................................................... Operation of the AG_SEND FC.................................................................................................. Condition Codes of AG_SEND.................................................................................................. FC AG_RECV/AG_LRECV ....................................................................................................... Explanation of the Formal Parameters....................................................................................... Operation of the AG_RECV FC.................................................................................................. Condition Codes of AG_RECV.................................................................................................. Job Header ...............................................................................................................................
Page 1
SEND/RECEIVE Interface
STEP 7 STEP 7 user program user program User data User data areas areas AG_SEND AG_RECV
Send Receive
Communication connection
CPU cycle
Transmission time
The following FCs (functions) are available for handling communication via configured connections: AG_SEND / AG_LSEND This function passes the user data from the specified user data area to the Ethernet CP for transmission. AG_RECV / AG_LRECV This function puts the user data received into the user data area specified in the call.
Note
The information given here applies to both AG_SEND and AG_LSEND and AG_RECV and AG_LRECV unless otherwise stated ! The diagram above illustrates this procedure: The user program uses the FCs AG_SEND/ AG_LSEND and AG_RECV / AG LRECV to instruct the Ethernet CP to send or receive data via the configured connection.
Data is exchanged between CPU and Ethernet CP as dictated by the calls to the FCs AG_SEND and AG_RECV in the CPU program. The Ethernet CP processes the Send and Receive jobs independently of the CPU cycle and the transmission takes a certain amount of time. The interface with the FCs in the user program is synchronized by means of acknowledgements. There are two possibilities: The CPU cycle is faster than the transmission time. The CPU cycle is slower than the transmission time.
Page 2
SEND/RECEIVE Interface
FC calls faster than the transmission time FC calls slower than the transmission time
If an FC is called again in the user program before all the data has been sent or received, the following happens at the FC interface: AG_SEND: No further job is accepted until the transmission of the data on the connection has been acknowledged by the Ethernet station. During this time, the user programm receives the message "job active" until the Ethernet CP can accept the next job on the same connection. AG_RECV: The job is acknowledged with the message no data available yet" if there is no received data on the Ethernet CP. The user program receives this message in the CPU cycle until the Ethernet CP has received all the data on the connection.
If an FC is called again after the data has been completely transferred or received, the procedure is as follows at the FC interface: AG_SEND: The job is positively acknowledged. The Ethernet CP is ready to receive a new send job. AG_RECV: The job is acknowledged with New data received when the data has been transferred to the user program. Following this, the FC call can be repeated.
Page 3
SEND/RECEIVE Interface
Send Receive
ISO-onTCP UDP TCP 8192 bytes 8192 bytes 2048 bytes 8192 bytes 8192 bytes 2048 bytes
Note:
With TCP you can only use the AG_LSEND and AG_LRECV functions, regardless of the quantity of data to be transferred.
Older CPs do not support transfer of more than 240 bytes of data. Please read the product information for your CP.
Page 4
SEND/RECEIVE Interface
Different data areas in the CPU can be used for communication via configured connections. Your choice of data area depends on the type of CPU and the task involved. The alternatives are: Data block (DB): Data blocks can be used for storing Send/Receive data. Process image: This choice is only possible if continuous Send and Receive areas can be reserved in the process image of the S7 CPU. The capacity may be restricted by the capabilities of the CPU and by the number of central signal modules. Bit memory address area: The bit memory address area can be used, for example, if there is not sufficient space in the process image because of the central signal modules.
Page 5
SEND/RECEIVE Interface
Purpose of the FCs Calling FC blocks results in the following action: The user data area is passed to the Ethernet CP or accepted from the Ethernet CP. Positive or negative confirmation of execution of the job is indicated in the status word.
Connections
Program the SEND-RECEIVE interface in the user program as follows: Use the following FCs for transferring data via configured connections: AG_SEND for passing the user data area to the Ethernet CP; AG_RECV for entering the data received from the Ethernet CP into the user data area;
Evaluate the condition codes issued by the FCs: For AG_SEND these are the parameters DONE, ERROR and STATUS, and For AG_RECV the parameters NDR, ERROR and STATUS
Note
You must use the configured connection numbers (IDs) when programming.
Page 6
SEND/RECEIVE Interface
Connection
We can observe the following: The user program, which can consist of any number of blocks (OBs, FBs or FCs), accesses several connections. The user program can send data via connections by means of AG_SEND calls at any point (event-driven and program-controlled execution). The user program can accept data received via connections by means of AG_RECV calls at any point in the CPU cycle.
Note:
The FCs can be called more than once in one cycle for the same connection.
Page 7
SEND/RECEIVE Interface
The FCs
The FCs are supplied with the NCM S7-Ethernet configuring software. The following list shows the block numbers used for these FCs on delivery. You can change these block numbers if you wish.
Block number 5 6 50 60
Purpose Send data <= 240 bytes Receive data <= 240 bytes Send data, max 8192 bytes Receive data, max 8192 bytes
For TCP connections you can only use the FCs AG_LSEND and AG_LRECV, regardless of the amount of data to be transferred.
Page 8
SEND/RECEIVE Interface
In order to be able to use the FCs for writing your user program, follow the procedure outlined above.
Page 9
SEND/RECEIVE Interface
Specification of the CP address - LADDR parameter - Starting address of module from hardware configuration table - Slot-oriented address assignment for Ethernet CP as for analog modules Specification of the data area in the CPU - Address and length - Max. length 8192 bytes, depending on the type of block used
When you call an FC, you assign the starting address of the CP module to the LADDR parameter. You can obtain the starting address of the Ethernet CP module from the hardware configuration. The module starting address can be determined from the slot-oriented address assignment for signal modules. The rules for analog modules apply to the Ethernet CP. When the CP is configured with the STEP 7 hardware configuration tool, the starting address of the module appears in the configuration table.
When you call an FC you supply it with the address and length of the data area in the CPU. Please note that the maximum length of the data area depends on the type of FC used. On complete restart/restart of the Ethernet CP (e.g. when the switch is operated), the output parameters of the FC are reset as follows:
DONE = 0 NDR = 0 ERROR = 0 STATUS = 8180H for AG_RECV and 8181H for AG_SEND
Page 10
SEND/RECEIVE Interface
Error CP address indicates a non-existent CP module or digital module. CP address indicates a module with analog I/Os.
Possible error codes in STATUS: 8184H System error 80B0H Data record unknown to module. 80C0H Data record cannot be read. 80C3H Resource (memory) occupied. 80D2H Incorrect logical base address.
If the S7 CPU cannot communicate with the Ethernet CP at the specified module starting address, the result is as shown above. Note: The SIMATIC S7 addresses the Ethernet CP like an analog module. If an incorrect address is specified, this can result in error codes which are not derived from error messages from the FCs themselves.
Page 11
SEND/RECEIVE Interface
FC AG_SEND / AG_LSEND
Call interface in LAD BOOL INT WORD ANY INT ACT ID LADDR SEND LEN DONE ERROR STATUS BOOL BOOL WORD
Example in STL STL call fc 5 ACT ID LADDR SEND LEN DONE ERROR STATUS Explanation //AG-SEND FC call := := := := := := := := M 10.0 MB 11 W#16#0100 P#db99.dbx10.0 byte 240 MW 12 M 10.0 M 10.7 MW 14 =LADDR 256 dec. in hardware configuration
The FC AG_SEND passes on data to the Ethernet CP for transmission via a configured connection. The data area specified can be an area in the process image, a bit memory address area or a data block area. Successful execution is signalled when the complete user data area has been transmitted via Ethernet.
Page 12
SEND/RECEIVE Interface
LADDR
INPUT
WORD
Page 13
SEND/RECEIVE Interface
DONE
OUTPUT
BOOL
ERROR
OUTPUT
BOOL
0: 1: Error
STATUS
OUTPUT
WORD
Page 14
SEND/RECEIVE Interface
The diagram above shows the normal execution sequence of a data transfer initiated by AG_SEND in the user program. The Ethernet CP acknowledges every AG_SEND job in the user program by setting the DONE, ERROR and STATUS output parameters. The condition codes can be updated without issuing a new Send job by setting the ACT parameter = 0.
Page 15
SEND/RECEIVE Interface
8303H
8304H
Page 16
SEND/RECEIVE Interface
0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1
Page 17
SEND/RECEIVE Interface
Page 18
SEND/RECEIVE Interface
FC AG_RECV / AG_LRECV
Call interface in LAD
INT WORD ANY BOOL BOOL WORD INT
ID LADDR RECV
Example in STL STL call fc 6 ID LADDR RECV NDR ERROR STATUS LEN := := := := := := := DB 100.DBW 1 W#16#0100 P#M 0.0 BYTE 100 DB 100.DBX 0.6 DB 100.DBX 0.7 DB 100.DBW 2 DB 100.DBW 4 Explanation //AG-RECV FC call
The FC AG_RECV receives the data transferred via a configured connection from the Ethernet CP. The data area specified as the data destination can be an area in the process image, a bit memory address area or a data block area. Successful execution is signalled when the data has been received from the Ethernet CP.
Page 19
SEND/RECEIVE Interface
LADDR
INPUT
WORD
Page 20
SEND/RECEIVE Interface
ERROR
OUTPUT
BOOL
0: 1: Error
STATUS
OUTPUT
WORD
Page 21
SEND/RECEIVE Interface
Time
Time
The diagram above shows the normal execution sequence for data acceptance initiated by AG-RECV in the user program. The Ethernet CP acknowledges every AG-RECV job in the user program by setting the NDR, ERROR and STATUS output parameters.
Page 22
SEND/RECEIVE Interface
Page 23
SEND/RECEIVE Interface
Page 24
SEND/RECEIVE Interface
Page 25
SEND/RECEIVE Interface
Job Header
Byte
Port IP address
Data byte 0
User data
6,7 2046,2047
The address and job parameters for a specified connection are defined in the connection configuration. The user program only needs to provide the user data area by means of AG_SEND/AG_LSEND and AG_RECV/AG_LRECV. Job Header Free UDP connections need a job header in the user data area. The diagram shows the structure of the job buffer and the position and meaning of the parameters in the job header. The user data area can be up to 2048 bytes long. 6 bytes are reserved for the job header and up to 2042 bytes of user data can be transferred.
Page 26
SEND/RECEIVE Interface