This article discusses how to build communication between two S7-1500 PLCs using Open User Communication (OUC) with the TCP/IP protocol in TIA Portal, complete with testing in PLCSIM Advanced. Unlike PUT/GET, which only needs a program on the client side, TCP requires active instructions on both sides: one PLC opens the connection (client), the other PLC waits for the connection (server), and then both can send and receive data to each other. OUC is vendor-independent, so the same method is also used to communicate with third-party devices or software that support TCP.
The system consists of two S7-1500 CPUs. PLC_1 acts as the client (active establishment), and PLC_2 acts as the server (passive establishment). Both use three instructions: TCON to open the connection, TSEND to send data, and TRCV to receive data.
The connection parameters (IP address, port, and active or passive role) are set through the Connection parameters panel on the TCON block, while the program handles opening the connection, latching the connection status, sending, and receiving data. The data sent is eight bytes, which in the test is used as a command code and a setpoint value. Two PLCSIM Advanced virtual CPUs are used for testing, so the whole flow can be tried without physical devices.
Prerequisites
- The reader already knows how to add a CPU and set the IP address in TIA Portal.
- The reader already understands how to create a Data Block and an SCL program in OB1.
- The reader already knows how to run a virtual CPU with PLCSIM Advanced and create a Watch table.
Open User Communication Concept
TCP is a connection-oriented protocol. Before data is sent, one party must open a connection to the other party. The party that opens the connection is called the client (active), and the party that waits is called the server (passive). After the connection is established, both parties can send and receive data. TCP sends data as a stream of bytes without message boundaries, so the data length must be agreed by both sides, which in this article is fixed at eight bytes.
On the S7-1500, the connection is managed by three main instructions. TCON creates and maintains the connection based on the connection data stored in a Data Block of type TCON_IP_v4. TSEND sends data, and TRCV receives data. All three use the same ID to point to that connection. The connection data contains the identity of the PROFINET interface, the connection type, the active or passive role, the partner IP address, as well as the local port and partner port. In this article, data is set through the Connection parameters panel in the properties of the TCON block, which automatically fills the connection Data Block Conn_DB.
PLCSIM Advanced can simulate TCP communication between two instances, as long as both run through the PLCSIM Virtual Ethernet Adapter and have different IPs in one subnet. With this setup, the OUC program can be tested as on a physical PLC.
Two Siemens S7-1500 PLCs TCP/IP Communication
Project Preparation
Step 1: Preparing the Devices and Network
- Create a new project in TIA Portal. In the project properties, check Support simulation during block compilation.
- Add two S7-1500 CPUs: PLC_1 (client) with IP 192.168.0.1 and PLC_2 (server) with IP 192.168.0.2, both with subnet mask 255.255.255.0.
- Open Devices & networks, then connect the PROFINET ports of both PLCs so they are in one local network.
Step 2: Creating the Communication Data Block
- On PLC_1 and PLC_2, create a Global Data Block DB_Comm (optimized) with the following variables.
- Control: Connect (Bool) as the trigger to open and close the connection, and Send (Bool) as the trigger to send data.
- Status: Connected, Send_Done, and Recv_Done (Bool), as well as Con_Status, Send_Status, and Recv_Status (Word) as block diagnostic codes.
- Data: Send_Data and Recv_Data, each of type Array[0..7] of Byte.

OUC Program Tutorial
Step 1: Setting the PLC_1 Connection (Client / Active Establishment)
- In OB1 of PLC_1, drag the TCON, TSEND, and TRCV instructions from Instructions > Communication > Open user communication, then accept the creation of their instance DBs (TCON_DB, TSEND_DB, TRCV_DB).
- Click the TCON block, then in the Inspector window open Properties > Configuration > Connection parameters.
- Set Local to PLC_1 and Partner to Unspecified. Select the connection type TCP and fill Connection ID with 1.
- Under Connection data click Add new and name it Conn_DB. The wizard creates the connection Data Block and fills it according to the following settings.
- On the Partner side, fill Address with 192.168.0.2 and Port with 2000. On the Local side, fill Port with 2000.
- On the Local side, check Active connection establishment, because PLC_1 is the one that will open the connection.

Step 2: PLC_1 Program (Client)
Write the following SCL program in OB1 of PLC_1. The instance DB names and the ID parameter follow the configuration result in Step 1.
// 1. Open the connection while Connect is TRUE (connection data comes from Conn_DB)
"TCON_DB"(REQ := "DB_Comm".Connect,
ID := W#16#1,
CONNECT := "Conn_DB");
// 2. Latch the connection status (TCON.DONE is only active for one scan)
IF "TCON_DB".BUSY OR "TCON_DB".ERROR THEN
"DB_Comm".Con_Status := "TCON_DB".STATUS;
END_IF;
IF "TCON_DB".DONE THEN
"DB_Comm".Connected := TRUE;
"DB_Comm".Con_Status := W#16#0000;
ELSIF NOT "DB_Comm".Connect THEN
"DB_Comm".Connected := FALSE;
"DB_Comm".Con_Status := W#16#7000;
END_IF;
// 3. Send 8 bytes on a rising edge of Send
"TSEND_DB".TSEND(REQ := "DB_Comm".Send,
ID := W#16#1, LEN := 8,
DATA := "DB_Comm".Send_Data,
DONE => "DB_Comm".Send_Done,
STATUS => "DB_Comm".Send_Status);
// 4. Receive 8 bytes continuously while connected
"TRCV_DB".TRCV(EN_R := "DB_Comm".Connected,
ID := W#16#1, LEN := 8,
DATA := "DB_Comm".Recv_Data,
NDR => "DB_Comm".Recv_Done,
STATUS => "DB_Comm".Recv_Status);
How does the PLC_1 program work?
The first part runs TCON. While Connect is TRUE, TCON opens the connection based on Conn_DB, namely the connection Data Block filled by the wizard in Step 1 (PROFINET interface, TCP type, active role, partner IP, and port). The ID parameter has the value W#16#1 and must be the same as the Connection ID set in the wizard. The program does not fill Conn_DB directly, but only triggers TCON through Connect.
The second part is the latching of the connection status. In testing, the DONE bit on TCON is only active for one scan cycle, so if it is used directly, the connection status drops immediately, and TRCV does not get a chance to run. Therefore, Connected is set TRUE when DONE appears and stays TRUE until Connect is changed to FALSE. While TCON is busy or in error, the TCON STATUS is copied to Con_Status, so values such as 16#7002 (connection being processed or waiting) or error codes are visible. When DONE appears, Con_Status is filled with 16#0000, and when Connect is FALSE, Con_Status returns to 16#7000.
The third part sends data: TSEND sends eight bytes of Send_Data every time Send changes from FALSE to TRUE, and Send_Done marks the sending as complete. The fourth part runs TRCV while Connected is TRUE. The eight bytes coming from the partner are placed in Recv_Data, and Recv_Done becomes TRUE for one cycle when new data arrives. All three instructions use the same ID (W#16#1), so they work on the same connection.

Step 3: Setting the PLC_2 Connection (Server / Passive Establishment)
- In OB1 of PLC_2, drag the TCON, TSEND, and TRCV instructions as in PLC_1, then click the TCON block and open Properties > Configuration > Connection parameters.
- Set Local to PLC_2 and Partner to Unspecified. Select the connection type TCP and fill Connection ID with 2.
- Under Connection data click Add new and name it Conn_DB.
- On the Partner side, fill Address with 192.168.0.1 and Port with 2000. On the Local side, fill Port with 2000. This local port is the port the server listens on, and it must be filled in.
- Do not check Active connection establishment on the Local side. Set the Partner side as the active party, because PLC_1 is the one that opens the connection and PLC_2 only waits.

Step 4: PLC_2 Program (Server)
Write the following SCL program in OB1 of PLC_2. This program is the same as PLC_1 except for the connection ID.
// 1. Wait for the client while Connect is TRUE (connection data comes from Conn_DB)
"TCON_DB"(REQ := "DB_Comm".Connect,
ID := W#16#2,
CONNECT := "Conn_DB");
// 2. Latch the connection status
IF "TCON_DB".BUSY OR "TCON_DB".ERROR THEN
"DB_Comm".Con_Status := "TCON_DB".STATUS;
END_IF;
IF "TCON_DB".DONE THEN
"DB_Comm".Connected := TRUE;
"DB_Comm".Con_Status := W#16#0000;
ELSIF NOT "DB_Comm".Connect THEN
"DB_Comm".Connected := FALSE;
"DB_Comm".Con_Status := W#16#7000;
END_IF;
// 3. Send 8 bytes on a rising edge of Send
"TSEND_DB".TSEND(REQ := "DB_Comm".Send, ID := W#16#2, LEN := 8,
DATA := "DB_Comm".Send_Data,DONE => "DB_Comm".Send_Done,
STATUS => "DB_Comm".Send_Status);
// 4. Receive 8 bytes continuously while connected
"TRCV_DB".TRCV(EN_R := "DB_Comm".Connected, ID := W#16#2, LEN := 8,
DATA := "DB_Comm".Recv_Data, NDR => "DB_Comm".Recv_Done,
STATUS => "DB_Comm".Recv_Status);
How does the PLC_2 program work?
The structure is the same as PLC_1, with one difference in the code, namely, the connection ID has the value 2 on all three instructions (W#16#2), according to the Connection ID set in the Step 3 wizard. The server role is not determined by the code, but by the wizard settings: because Active connection establishment is not checked on the Local side, TCON does not open the connection itself, but waits for the client on local port 2000.
When Connect is TRUE, Con_Status usually shows 16#7002 while PLC_2 is waiting. If the local port is left empty in the wizard, a parameter error can appear when the program runs. The status latching, sending, and receiving logic works exactly as on PLC_1.

PLC Testing with PLCSIM
Step 1: Running the Virtual CPUs and Download
- Open S7-PLCSIM Advanced Control Panel, then set Online Access to PLCSIM Virtual Eth. Adapter.
- Create two S7-1500 instances: PLC_1 with IP 192.168.0.1 and PLC_2 with IP 192.168.0.2. Run both.
- Perform Compile (Rebuild all) on PLC_1 and PLC_2, then download the program to each virtual instance, run the CPU, and Go online.
- On PLC_1 and PLC_2, create a Watch table containing all DB_Comm variables, then click Monitor all.
Step 2: Opening the Connection
- Make sure Connect is FALSE on both PLCs.
- Change Connect on PLC_2 (server) to TRUE first so that port 2000 starts being listened to. Con_Status changes to 16#7002.
- Change Connect on PLC_1 (client) to TRUE.
- Expected result: both PLCs connect immediately, Connected becomes TRUE, and Con_Status becomes 16#0000.Â

Step 3: Sending Data from PLC_1 to PLC_2
- On PLC_1, fill Send_Data[0] with 1 and Send_Data[1] with 150 via Modify now.
- Change Send from FALSE to TRUE.
- Expected result: on PLC_2, Recv_Data[0] = 1 and Recv_Data[1] = 150.

Step 4 (Optional): Sending Data from PLC_2 to PLC_1
- On PLC_2, fill Send_Data[0] with 2 and Send_Data[1] with 75, then change Send from FALSE to TRUE.
- Expected result: on PLC_1, Recv_Data[0] = 2 and Recv_Data[1] = 75.
