An S7-300 station sends/receives data to/from multiple communication partners using the UDP protocol.
The advantages of the connectionless UDP protocol are:
- Very rapid data transfer
- Very flexible, can be well implemented with third-party systems
- Multicast-compatible / broadcast-compatible
- Suitable for small to medium volumes of data (<= 2048 bytes)
The disadvantages of the connectionless UDP protocol are:
- Data is transferred packet-oriented (not stream-oriented)
- Send and receive jobs are not acknowledged by the communication partners. This has to be done in the user program.
- Lost data packets are not sent again
- Multiple deliveries of individual packets is possible
- The order of arrival of the packets at the receiver's end cannot be predicted
- Broadcast function can only be used in send direction
Entry ID 26484229 gives you detailed information on the properties and special features of the UDP protocol.
In this example, only one local UDP endpoint is configured in the S7-300 station. UDP datagrams can be sent/received via this local UDP endpoint to/from multiple remote UDP endpoints.
Fig. 01: Configuration
Configuring the local UDP endpoint:
Proceed as follows to configure the local UDP endpoint.
Open the STEP 7 project with the configuration of your S7-300 station. In NetPro you configure an unspecified UDP connection for the S7-300 station.
Fig. 02: Configuring an unspecified UDP connection
In the Properties dialog of the UDP connection you switch to the "Addresses" tab. Here you enable the option "Address assignment in block". Now it is no longer possible to assign the target parameters like IP address and port of the partner at this point.
Fig. 03: Properties dialog of the UDP connection -> "Addresses" tab
The UDP endpoint must be configured in both the sending and the receiving station.
The S7 program:
The IP address and the port of the partner are specified in the user program, i.e. the target parameters are defined in the first 6 bytes of the user data to be transferred. The user data is transferred with the function FC5 "AG_SEND" or FC50 "AG_LSEND" as the case may be.
In this way, the data can be sent via a local UDP endpoint to multiple remote UDP endpoints (i.e. to multiple communication partners). Since only one UDP endpoint is configured, only one connection resource of the IE CP is occupied. Consequently, the resources saved can be used to configure other communication connections.
The IE CP takes the IP address and port data of the communication partner from the first 6 bytes of the user data sent by the CPU. The data delivered is not checked for plausibility.
The structure of the user data to be transferred is explained below taking the example of a data block (DB10) as the data source.
Fig. 04: Data structure in the send station user program
In this example, the data is sent to port 2001 of the IP address 126.96.36.199.
The target IP address 188.8.131.52 is an IP address of a class B network, i.e. the first two bytes are relevant for the subnetwork address and the last two for the computer address.
In this example, the IE CP that sends the UDP datagrams via a configured local UDP endpoint has the IP address 184.108.40.206. If the user program transfers the target IP address 220.127.116.11 to the IE CP, then communication works without errors.
Furthermore, in the S7 program you call function FC6 "AG_RCV" or FC60 "AG_LRCV" as the case may be to have the UDP datagrams received by one or multiple remote UDP endpoints via the local UDP endpoint. The following entries include a detailed sample program for communication blocks FC5 "AG_SEND" and FC6 "AG_RCV" or FC50 "AG_LSEND" and FC60 "AG_LRCV" as the case may be: 17853532 and 18513371.
FC6 "AG_RCV" or FC60 "AG_LRCV" is only called once in the user program, even if the UDP datagrams are received by multiple remote UDP endpoints. The address data of the sender (source port and source IP address) is transferred by the send station to the receive station in the first 6 bytes of the user data.
The structure of the user data received then looks like this:
Fig. 05: Structure of the user data received