Share this

Research on Real-time Communication Methods between PLC and PC

2026-04-06 04:32:40 · · #1
1. Overview In industrial control systems, PLCs, as stable and reliable controllers, have been widely used. However, due to the imperfect human-machine interface (HMI) functions of small and medium-sized PLCs, they cannot provide users with a user-friendly interface, thus hindering the tracking and monitoring of the field operation. In practical PLC operation, four devices are typically used to configure the HMI for the PLC: programming terminal, display terminal, workstation, and personal computer. The programming terminal is mainly used for programming and debugging, with relatively weak monitoring functions. The display terminal has a relatively simple function, mainly used for on-site display. Workstation systems are very popular with users; they are comprehensive in function and easy to use, but are relatively expensive due to the need for advanced configuration software. Personal computers can be equipped with various high-level languages, providing an excellent software platform for developing various application systems, especially dynamic screen displays. Combining them with PLCs to form a PC-PLC monitoring and management system can fully leverage their respective advantages. However, in this system, the key issue is communication, requiring users to perform considerable development work in this area. This article elaborates on the general methods of interconnecting and communicating between a PC and a PLC. Taking Siemens' S7-200 PLC as an example and using a real four-story elevator model monitoring system as an example, it introduces the communication process of realizing real-time communication between the PLC and the host computer using the familiar programming languages ​​Visual Basic and Step7. 2 Communication Methods Faced with various types of PLCs from numerous manufacturers, each with its own advantages and disadvantages, they can meet various user needs, but they differ in form, composition, function, programming, etc. There is no unified standard, and the communication protocols formulated by each manufacturer are also very different. At present, people mainly use the following three methods to realize the interconnection and communication between PLC and PC: (1) By using the system protocol and network adapter provided by the PLC developer, the interconnection and communication between the PLC and the PC can be realized. However, since its communication protocol is not public, the interconnection and communication must use the host computer configuration software provided by the PLC developer and use peripherals that support the corresponding protocol. It can be said that this method is tailored by the PLC developer for its own products, and therefore it is difficult to meet the needs of different users. (2) Use commonly used host computer configuration software, such as KingSCADA, InTouch, WinCC, ForceControl, etc., to realize the interconnection and communication between PLC and PC. Configuration software has been widely used in the PC monitoring field due to its powerful functions, user-friendly interface, and simple development, but it is generally expensive. Configuration software itself does not have the ability to directly access PLC registers or other intelligent instruments, and must rely on I/O drivers to achieve this. That is to say, I/O drivers are the bridge for information exchange between configuration software and PLC or other intelligent instruments, responsible for collecting real-time data from the device and issuing operation commands to the device. Its reliability will directly affect the performance of configuration software. However, in most cases, I/O drivers are device-dependent, that is, drivers for a certain type of PLC cannot drive other types of PLCs, so the flexibility of configuration software is also limited to a certain extent. (3) Use the standard communication ports provided by PLC manufacturers and user-defined free port communication methods to realize the interconnection and communication between PLC and PC. This method allows users to define communication protocols, does not require additional investment, has good flexibility, and is particularly suitable for small-scale control systems. From the above analysis, it is easy to conclude that mastering how to utilize the standard communication ports and free-port communication methods provided by PLC manufacturers, as well as familiar programming languages, to achieve real-time communication between a PC and a PLC is essential. 3. S7-200 PLC Communication Methods and Principles The S7-200 PLC's integrated PPI interface provides users with powerful communication capabilities, operating in multiple modes: PPI, Profibus-DP, and free-port mode. Among these, the free-port communication mode is the most distinctive, as the communication protocol can be completely controlled by the ladder diagram program. It allows the PLC to interconnect with any device possessing communication capabilities; therefore, the free-port communication mode is chosen in this system. Currently, there are two methods for linking and communicating between a PLC and a PC: one where the PC is always in a dominant position, with data transmission initiated by the PC through periodic commands; and another where the PLC always has priority. In this elevator model monitoring system, all control signals are switch signals. Considering that the host PC only displays the elevator's operating status in real time and does not need to send control commands to the PLC, the second communication method is adopted. Utilizing the characteristics of PLC cyclic scanning, once the device status changes, the PLC immediately detects it and stores the data reflecting the system status change in the designated data buffer. The data is sent to the host computer via the COM port through the XMT sending instruction. The status of each system corresponds to a designated byte in the data buffer. All stored data is in hexadecimal. To ensure the reliability of the communication process, the host computer performs a first and last character check on the received data. If the check is successful, it means that the data between the first and last bytes of the received data is correct and can be processed. Otherwise, the data is discarded and the other party is asked to resend it. 4 Application Examples and Program Design (1) System Composition The physical characteristics of the PPI interface integrated inside the S7-200 PLC are RS485, while the standard serial port of the host computer is RS232. In order to realize the communication between the two, protocol conversion must be performed. The PC/PPI cable provided by Siemens has an RS232/RS485 level converter. Therefore, without adding any hardware, the interconnection and protocol conversion between the two can be easily realized. The FATEK-FBS PLC, acting as the controller, utilizes the power cord of the elevator model to interconnect with the four-story elevator model. This elevator model is a teaching experimental device and possesses the basic functions of a general elevator. The hardware connection is shown in Figure 1. [align=center] Figure 1 Hardware Connection Diagram[/align] (2) PLC Programming ① Initialization of Free Port In free port communication mode, the baud rate, parity, and data bits are selected for free port communication by setting the special memory SMB30 (port 0). These settings must be consistent with the PC settings. The format is as follows: SMB30 pp is the parity selection, d is the data bit selection, and bbb is the baud rate selection. • 00 is no parity, 0 is 8 bits per character, 000 is 38,400 baud, 001 is 19,200 baud; • 01 is even parity, 1 is 7 bits per character, 010 is 9,600 baud, 011 is 4,800 baud; • 10 is no parity, 100 is 2,400 baud, 101 is 1,200 baud; • 11 is odd parity, 110 is 600 baud, 111 is 300 baud; mm is the protocol selection: 00 is PPI protocol, 01 is freeport protocol, 10 is PPI/master mode, 11 defaults to PPI/slave mode. ② S7-200PLC transmits data to the host PC in real time. In the elevator model control, all control signals are switch signals. Based on this characteristic, the change of system state is the change of these switch signal states. Therefore, the arrival of the rising edge and falling edge of these switch signals can be used as the basis for the change of system state. Accordingly, in this system, different hexadecimal numbers are defined for the rising edge and falling edge of the same switch signal to represent the generation and end of the signal. When these signals are detected, the data are stored in the specified data buffer bytes and sent to the host PC through the COM port. At the same time, a transmission completion interrupt is generated. The PLC delays and waits to receive the response signal from the host computer. By analyzing the data stored in the receive character buffer SMB2, it is determined whether it needs to be retransmitted. The lower computer program is shown in Figure 2. [align=center] Figure 2 Lower computer program flowchart[/align] (3) The upper computer part is programmed based on VB. The upper computer programming environment of this project is implemented using VB for convenient and fast processing of monitoring interface graphics, data reports and communication. VB not only provides the MSCOMM serial communication control, but also standard event handling functions for it. By setting some of its properties, the communication interface can be initialized, easily achieving serial communication. The following describes the properties of this control: Commport: Sets the communication connection port. The program must specify the number of the serial port to use; Windows uses the set communication port to communicate with the outside world. Settings: Sets the initialization parameters. Its format is "BBBB, P, D, S", where BBBB is the connection speed, P is the parity mode, D is the data bits, and S is the stop bits. The default value is "9600, n, 8, 1". PortOpen: Sets the state of the communication connection port. The serial port must be opened before use. Input: Returns and deletes the data stream in the receive buffer. InputLen: Sets the length of the string read from the serial port. Rthreshold: Sets the number of characters that trigger the receive event. InputMode: Sets the data format for receiving data. OnComm event: Used to handle all communication-related events. The advantage of using event-driven programming is that the program doesn't need to be constantly in a monitoring state. Once the program code is written beforehand, it will be executed directly when an event occurs. This event-driven approach provides the necessary conditions for real-time communication. The host computer program is shown in Figure 3. [align=center] Figure 3 Host Computer Program Flowchart[/align] The PC can easily identify the status of each switch based on the received information, thereby controlling the real-time display on the monitoring interface. 5 Conclusion The above is a simple application of real-time communication between the S7-200 PLC and a host PC using the free port communication method. Verification shows that this method is simple, has good real-time performance, and high reliability. For logic control systems, it is a simple and easy method to achieve real-time monitoring of the controlled object. References [1] Ma Guohua. Monitoring configuration software and its application [M]. Tsinghua University Press. [2] Li Zhihong, Du Juan, Zhang Ping, et al. Implementation method of PLC and host computer communication based on VB [J]. Basic Automation, 2002, 2. [3] SIMATIC S7-200 programmable controller [M]. System Manual, 2000, 11. [4] Fan Yizhi, et al. Implementation of serial and parallel communication technology using Visual Basic [M]. Tsinghua University Press
Read next

CATDOLL 136CM Miho (TPE Body with Hard Silicone Head)

Height: 136cm Weight: 23.3kg Shoulder Width: 31cm Bust/Waist/Hip: 60/54/68cm Oral Depth: 3-5cm Vaginal Depth: 3-15cm An...

Articles 2026-02-22