Programming With The SEND/RECEIVE Interface: Simatic Net
Programming With The SEND/RECEIVE Interface: Simatic Net
Programming With The SEND/RECEIVE Interface: Simatic Net
Contents Page
CP
CP
STEP
STEP77 database
user database
userprogram
program
User
Userdata
databuffer
buffer
User
Userdata
data
areas
areas
AG_SEND Send
Communication
connection
AG_RECV Receive
FCs 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.
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 exchange Data is exchanged between CPU and Ethernet CP as dictated by the
S7 CPU <-> calls to the FCs AG_SEND and AG_RECV in the CPU program.
Ethernet CP
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:
FC Calls Faster If an FC is called again in the user program before all the data has been
than the sent or received, the following happens at the FC interface:
Transmission Time
• 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.
FC Calls Slower If an FC is called again after the data has been completely transferred or
than the received, the procedure is as follows at the FC interface:
Transmission Time
• 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.
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.
• Process image
Alternative Different data areas in the CPU can be used for communication via
data areas configured connections. Your choice of data area depends on the type of CPU
and the task involved. The alternatives are:
• 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.
Principle of job The user program triggers the transfer of the user data areas
and data transfer by means of FC calls and monitors the execution by evaluating
the condition code bits returned by the FCs. The parameters
assigned to the FCs when they are called include:
- 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;
Note You must use the configured connection numbers (IDs) when programming.
AG_RECV
Connection
AG_RECV
Connection
AG_SEND
AG_RECV
Connection
AG_SEND
• The user program, which can consist of any number of blocks (OBs,
FBs or FCs), accesses several connections.
• 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.
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.
Note For TCP connections you can only use the FCs AG_LSEND and AG_LRECV,
regardless of the amount of data to be transferred.
Result:
The currently existing libraries are displayed.
Result:
The library “SIMATIC NET CP” is now created in the STEP 7 library.
In order to be able to use the FCs for writing your user program, follow the
procedure outlined above.
Specifying the When you call an FC, you assign the starting address of the CP module
CP Address to the LADDR parameter. You can obtain the starting address of the Ethernet CP
module from the hardware configuration.
Ascertaining the The module starting address can be determined from the slot-oriented
CP Address 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.
Specifying the When you call an FC you supply it with the address and length of the data
Data Area in the area in the CPU. Please note that the maximum length of the data area
CPU depends on the type of FC used.
• DONE = 0
• NDR = 0
• ERROR = 0
Error Response
CP address indicates a non-existent CPU remains in Stop mode due to a system error.
CP module or digital module.
If the S7 CPU cannot communicate with the Ethernet CP at the specified module
starting address, the result is as shown above.
Note:
ANY SEND
INT LEN
Example in STL
STL Explanation
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.
DONE OUTPUT BOOL 0: Job in This parameter indicates whether or not the
progress job has been completed without errors. As
1: Job long as DONE=0, no new job can be started.
completed The CP sets DONE to 0 when it accepts a
job.
For meanings in conjunction with the
ERROR and STATUS parameters, see the
Condition Codes table.
Supply AG_SEND
ACT = 0
AG_SEND Startup phase
0, 1, 8181 1)
AG_SEND
1, 0, 0000 1)
Supply AG_SEND
with data ‘X’
ACT = 1
AG_SEND
0, 0, 8181 1)
Supply AG_SEND
ACT = 0 Transmission of ‘X’
via Ethernet
AG_SEND active Key:
0, 0, 8181 1) 1) Parameter transfer
DONE, ERROR, STATUS
AG_SEND
1, 0, 0000 1)
The diagram above shows the normal execution sequence of a data transfer
initiated by AG_SEND in the user program.
The condition codes can be updated without issuing a new Send job by setting
the ACT parameter = 0.
BOOL
INT ID NDR
WORD BOOL
LADDR ERROR
ANY WORD
RECV STATUS
LEN INT
Example in STL
STL Explanation
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.
LEN INPUT INT 1..8192 for ISO Number of bytes transferred from the
and ISO-on-TCP Ethernet CP to the transport data area.
1..2048 for UDP
Accept/evaluate
received data ‘A’ Transmission of ‘B’
via Ethernet
AG_RECV in progress
0, 0, 8180 1)
AG_RECV
1, 0, 0000 1)
Accept/evaluate
received data ‘B’ Key:
Transmission of ‘C’ 1) Parameter transfer
via Ethernet NDR, ERROR, STATUS
AG_RECV
in progress
.
.
.
The diagram above shows the normal execution sequence for data acceptance
initiated by AG-RECV in the user program.
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.