Application Overview
Hello everyone, I am Bao Ge! Today I bring you a super friendly communication upgrade tutorial for the S7-1200 PLC. As an experienced PLC user, I know that many friends encounter communication issues when first dealing with Siemens PLCs.This S7-1200 is, in my opinion, the most suitable PLC for beginners; it is not only easy to operate but also particularly user-friendly..
If you are a newcomer to industrial automation or an advanced user looking to enhance your PLC programming skills, this tutorial will definitely help you..
Hardware Configuration
First, let’s talk about the hardware we need to prepare:
-
S7-1200 CPU 1214C DC/DC/DC
-
Ethernet switch (recommended TP-LINK)
-
Two network cables
-
24V power supply
-
A PC (with TIA Portal V15 installed)
The most commonly overlooked aspect during configuration is the IP address setting; make sure the PLC and the computer are on the same subnet. I personally recommend setting the PLC’s IP to 192.168.0.1 and the computer’s IP to 192.168.0.2, as this configuration is least likely to cause issues..
Program Design Approach
Before we start programming, let’s clarify our approach. The communication upgrade mainly includes the following steps:
-
Hardware configuration
-
Communication parameter settings
-
Writing the communication program
-
Online testing
Remember a little tip: before configuration, it is best to test the network connection using the PING command to ensure it is functioning properly..
Program Implementation
Variable Definition
VAR
Send_Data: ARRAY[0..255] OF BYTE; // Send data buffer
Recv_Data: ARRAY[0..255] OF BYTE; // Receive data buffer
TCON_1: TCON; // Communication connection control block
TSEND_1: TSEND; // Send control block
TRCV_1: TRCV; // Receive control block
END_VAR
Main Program Implementation
// Network 1: Establish connection
"TCON_1"(
REQ := TRUE,
ID := 1,
CONNECT := "Connection_1",
DONE => #Done,
BUSY => #Busy,
ERROR => #Error,
STATUS => #Status);
// Network 2: Send data
"TSEND_1"(
REQ := #Send_Trigger,
ID := 1,
LEN := #Send_Length,
DATA := #Send_Data,
DONE => #Send_Done,
BUSY => #Send_Busy,
ERROR => #Send_Error,
STATUS => #Send_Status);
// Network 3: Receive data
"TRCV_1"(
EN_R := TRUE,
ID := 1,
LEN := #Recv_Length,
DATA := #Recv_Data,
NDR => #Recv_Done,
BUSY => #Recv_Busy,
ERROR => #Recv_Error,
STATUS => #Recv_Status);
Communication Function Blocks
In this program, I chose the three most basic and practical function blocks: TCON, TSEND, and TRCV. They are responsible for establishing connections, sending data, and receiving data, forming the core of our communication program..
Function Expansion
If you want to make the program more practical, I suggest adding data verification and error retry mechanisms.
This can greatly improve communication reliability and prevent interruptions due to network fluctuations..
Debugging Methods
Debugging can be the most frustrating part, but don’t worry, I will teach you a few tricks:
-
Use the online monitoring feature to check variable statuses.
-
Observe the STATUS word; it can tell you exactly where the problem lies.
-
Check the system logs through project diagnostics.
Application Expansion
Once you master basic communication, we can:
-
Implement multi-device communication.
-
Develop a simple data acquisition system.
-
Build a small SCADA system.
Troubleshooting
Don’t panic when encountering issues; 90% of communication problems arise from these few areas: incorrect IP configuration, unstable network connections, and logical errors in the program.
Conclusion
That’s it for today’s tutorial! I hope this tutorial helps everyone better understand and utilize the communication functions of the S7-1200. Remember: the most important part of learning PLCs is hands-on practice; just watching won’t help you learn. If you encounter any problems, feel free to ask me in the comments; Bao Ge will always be your technical support!