Siemens PLC Ethernet Communication with CPU1515: TCP Server Setup, Debugging Tips, and Connection Management



In our recent project, we implemented Ethernet communication with third-party devices using a Siemens CPU1515, leveraging TCP protocol. The debugging went pretty smoothly, and here are some technical details I'd like to share.


For Siemens PLC Ethernet communication, I typically use the command set from the communication instruction list: TCON, TSEND, TRCV, and TDISCON. If you're dealing with UDP instead, you'd use TUSEND in place of TSEND and TURCV instead of TRCV.


This project utilized TCP protocol. We know TCP involves two roles: server and client. In this setup, we configured the PLC as the TCP server, with the third-party device acting as the client initiating the connection. When configuring the TCON instruction, the "CONNECT" parameter's "active_established" should be set to false (0) even though it's acting as a server.


The "REQ" parameter in the TCON instruction triggers the action. It uses an edge signal internally, so you can use either an edge or a constant true (1) signal externally. When the PLC acts as a TCP server, the TCON instruction doesn't initiate the connection but merely opens the local port, waiting for a client to connect. Conversely, as a TCP client, the TCON instruction will actively connect to the target server, with the IP address and port number set in the "CONNECT" parameter under "remote_address" and "remote_port". For UDP, since it's not connection-oriented, this instruction just opens the port.


When the PLC is a TCP server and the "REQ" value is true (1) without any client connected, the instruction's output "BUSY" will be true (1), and the status code will be "16#7002", as shown in the diagram below:


Once a client successfully connects, the "BUSY" value turns to false (0). The "DONE" value becomes true (1), but this true state only lasts for one scan cycle.


Therefore, to maintain the state of a successfully established connection, you'd typically use a set coil instruction to set another variable, like this:


With the Connection_Established variable, you can enable reception in subsequent TRCV instructions.


Also, when acting as a TCP server, I initially thought that the remote_address and remote_port fields would capture the client's information upon successful connection. However, practical testing showed that no such data is stored there.


Once the TCON instruction establishes a connection, it's automatically maintained, and subsequent REQ requests for the same connection ID won't do anything. If you need to re-establish the connection, you should first use the TDISCON instruction to disconnect the current link, then use TCON again to reconnect. Here's an example of how to use the TDISCON instruction:


So, that's the technical detail I wanted to share about Siemens PLC Ethernet communication for now.