Reception of data:

Reading telegrams from the receive buffer is done using the ETH_UDP_REC block. If necessary, it is also possible to use several instances of the ETH_UDP_REC block within one program to enable faster reading of the telegrams. The block is processed if input EN = TRUE. The corresponding Communication Module has to be specified at input SLOT (0 = int. Communication Module, 1 = 1st ext. Communication Module slot, etc.). The variable to be used to store a receive telegram has to be applied to block input DATA via the ADR operator.

The following program can be used for our example (data exchange between two controllers):

../_images/459fe53362a093820a3313901cd633a7
../_images/c8d31dd562a0c1b20a3313907dcf7f53

The values TRUE at output DONE and 0 at output ERR indicate that a telegram has been successfully read from the buffer during the present cycle and copied to the area specified at input DATA. The user data length of the telegram is output at LEN. The block always reads the next receive telegram stored in the buffer without taking into account the IP address of its sender. The sender’s IP address of the respective telegram is output at IP_ADR.

The program for the second controller is almost identical.

../_images/38109df4e38bcfb30a33139000eba54e
../_images/6b9a75d3e38bd0010a33139000eba54e
../_images/cbcf6b47e38bd05e0a33139000eba54e

Instead of specifying the TCP/IP address as a hex value at block ETH_UDP_SEND, the function IP_ADR_STRING_TO_DWORD IP_ADR_STRING_TO_DWORD: IP_ADR_STRING_TO_DWORD IP_ADR_STRING_TO_DWORD contained in library “ETHERNET_AC500_V10.lib” (folder “IP conversions”) can also be used. In this case, the address is specified as string.

../_images/5b694a04e38bcf650a33139000eba54e

For output IP_ADR of block “ETH_UDP_REC”, an inverse function is available in order to obtain the TCP/IP address as string IP_ADR_DWORD_TO_STRING IP_ADR_DWORD_TO_STRING: IP_ADR_DWORD_TO_STRING IP_ADR_DWORD_TO_STRING.

If telegrams are received from different controllers and if the data received from the respective controller shall not be overwritten by the data received from another controller, it is furthermore required to copy the data to a specific area for the sender’s IP address.

The implementation of this distribution is easier to realize using an ST program.

../_images/0d2ed84de38bd0ac0a33139000eba54e
../_images/ef1b3572e38bd0fa0a33139000eba54e

Here, the data are copied to different areas according to the TCP/IP address using the “CASE” command.

16#0A31B5FE     10.49.91.254

16#0A31B5FD     10.49.91.253

In case of higher amounts of data, complete arrays can be created instead of an integer.

This example can be easily expanded for a higher number of stations.

If a telegram stored in the transmit buffer could not be transmitted to the target controller for any reason or if the target controller did not acknowledge the reception of the telegram within the specified send timeout of 100 ms, the information about this telegram specified during the initialization are stored in the timeout buffer. In case of a buffer overflow, the respective oldest entry is overwritten and the number of entries still stays at the maximum value.

If the individual controllers are started one after the other, it can happen that the value of LEVLTOS first increases in the controllers already started since the controllers, which are not yet in RUN state, are not yet able to process the protocol. Then, after all controllers are in RUN state and if the Ethernet network is connected correctly and not overloaded, the LEVLTOS values should no longer change in any controller.

If necessary, the information about the undeliverable transmit telegrams stored in the timeout buffer can be read via the ETH_UDP_STO block and evaluated. The figure below shows the corresponding block call for all controllers.

../_images/5497f7d2e38bd1480a33139000eba54e

If output DONE is TRUE and ERR is 0, a data record has been read from the buffer and stored in TIMEOUT_DATA. If necessary, it is now possible to further evaluate the data record. Furthermore, the number of entries in this buffer is decremented if no other timeout occurred in the meantime. According to the initialization of the protocol processing, TIMEOUT_DATA[1] to [7] contain the telegram header followed by the first bytes of the original user data, starting at TIMEOUT_DATA[8].

Download the projects to the corresponding controllers. The implementation of fast data communication via UDP/IP is now completed.