Share this

Implementation of PLC serial communication in measurement and control devices

2026-04-06 07:41:05 · · #1
Abstract: This paper introduces the measurement and control object and structural design of the HG-2003 temperature rise measurement and control device. The design and implementation of the serial communication program between the Siemens S7-200 PLC and the PC used in the device are discussed in detail, specifically the details and difficulties in the design and implementation of the S7-200 ladder diagram communication program. The design of the upper PC communication program is briefly introduced. The implementation of this communication function ensures that the device has a simple structure, high reliability, and is easy for secondary development. Keywords: RS-232 serial communication, programmable controller, free port mode, data buffer, PC/PPI cable. The HG-2003 temperature rise measurement and control device is a measurement and control device specifically developed by the author in conjunction with a scientific research institute in Beijing, my country, for the temperature rise detection test of high-voltage thyristor valves. Considering that PLCs and their networks are recognized as one of the pillars of modern measurement and control device development, and that statistics from recent years show that PLC products rank first in production and sales volume among various measurement and control devices worldwide, the author decided to use a programmable controller (PLC) as the core device of this measurement and control system, whose basic functions can be implemented through software programming. The three highlights of PLC are: (1) integrating electrical control, electrical transmission and electrical instrumentation; (2) high performance-price ratio of network; (3) high reliability. These highlights make the entire measurement and control equipment simple in structure and highly reliable, and also lay a good technical foundation for the secondary development of system control functions. This article mainly discusses the serial communication problem between the Siemens S7-200 PLC and the PC used in the equipment. 1. Overall introduction of temperature rise measurement and control system 1.1 Measurement and control object and structure of HG-2003 measurement and control device Let's first introduce the basic working process of the temperature rise test measurement and control device. The 10kV power supply line passes through the high voltage circuit breaker CB in the incoming line frame and the disconnecting switch G in the high voltage disconnecting switch cabinet (used to form a clear break point during equipment maintenance or repair) and is then applied to the 10kV conversion transformer T1. The transformer converts three-phase power into single-phase power. This is mainly because the load current is very large when doing the experiment. If three-phase power is used, it is easy to cause an imbalance in the load current, which will cause the test failure. A single-phase temperature rise test transformer T2 is connected to the output (secondary side) of the conversion transformer. A capacitor bank for reactive power compensation should be installed on the primary side of this temperature rise transformer, while the secondary side is directly connected to the test specimen (i.e., the high-voltage thyristor valve) via an on-load tap changer for temperature rise testing. From the basic workflow, it is easy to identify the measurement and control objects of the device. The specific measurement and control objects of this device are shown in Table 1. Table 1: Measurement and Control Objects. The physical structure of the measurement and control device consists of two parts: the operation control console and the test area control box. The test area control box, i.e., the PLC control box, is installed within the isolating switch frame of the test area. The operation control console, i.e., the PC-based human-machine interface, is installed in the control room. Since the two are approximately 40m apart, a repeater is required when using a PC/PPI cable to transmit the measurement and control signals. 1.2 Basic Functions of the HG-2003 Measurement and Control Device The basic functions of this measurement and control system include: switch opening and closing control indication function; overcurrent, overvoltage, and overheat alarm and protection functions for equipment and samples; various operation interlocking functions, such as interlocking protection functions between the 10kV power circuit breaker in the power switch cabinet and the manual disconnecting switch in the disconnecting switch cabinet, the control room door contacts, and the test hall door contacts, etc., and related alarm prompt screens are provided. These functions can prevent errors in the operation sequence. 2. Design and Implementation of the S7-200 Communication Program 2.1 Communication Method between PC and S7-200 The Siemens S7-200 PLC has strong communication capabilities and offers multiple communication methods for users to choose from, such as: single master station mode, multi-master station mode, and remote communication mode using a modem, etc. In this measurement and control device, the author adopts the single master station mode. After installing STEP 7-Micro/WIN32 programming software on a personal computer (PC) running Windows or Windows NT, the PC can act as the master station in the communication. It can connect to one or more slave stations. The STEP 7-Micro/WIN 32 communicates with one S7-200 CPU at a time, but can access all CPUs on the network. The hardware configuration for this communication method is a PLC-to-PC communication port cable connector, specifically an isolated PC/PPI cable with an RS-232 port, using five DIP switches to set the baud rate and other configuration items. It supports baud rates of 9.6kbps or 19.2kbps and the PPI protocol. However, the PPI protocol is not used here; instead, the PC/PPI cable and freeport communication function are used to achieve communication between the S7-200 CPU and the PC. Freeport mode is a cheap and flexible method for communication between a computer or other devices with serial communication interfaces and the S7-200 CPU. Based on a user-defined communication protocol, it controls the operating mode of the S7-200 CPU communication port using relevant interrupt instructions and dedicated communication instructions, enabling connection to various intelligent devices. Specifically, the so-called free communication port mode refers to a communication operation mode where the CPU's serial communication interface can be controlled by the user program. Its ladder logic program can use receive completion interrupts, character receive interrupts, transmit completion interrupts, transmit instructions (XMT), and receive instructions (RCV) to control the communication process. In this mode, the communication protocol is entirely controlled by the user program. When the CPU is in STOP mode, free communication port mode is disabled, and the CPU re-establishes communication using other protocols, such as communication with the programming device. Free communication port mode can only be used when the CPU is in RUN mode. The communication port can be set to free port mode by setting the protocol selection field (mm) of the special register byte SM30 or SM130 to 1. In this mode, communication with the programming device is not possible. The entry into free port mode can be controlled using the special memory bit SM0.7, which reflects the current position of the operating mode switch on the CPU module. When SM0.7 is 1, the operating mode switch is in the RUN position, and free port mode can be selected; when SM0.7 is 0, the operating mode switch is in the TEM position, and the PC/PPI protocol mode should be selected for monitoring or controlling the operation of the CPU module by the programming device. 2.2 Key Points of PLC Serial Communication Programming in Free Port Mode When a computer communicates with a programmable controller (PLC), to avoid contention for the communication line, a master-slave working mode is generally adopted, where the computer is the master and the PLC is the slave. Only the master has the right to actively send request messages, and the slave returns a response message upon receiving it. The following mainly discusses several issues that should be noted during programming. First, the handling of cable switching time. Because a PC/PPI cable is used, the cable switching time should be considered in the S7-200 CPU user program. The delay time from when the S7-200 CPU receives a request message from the RS232 device to when it sends a response message must be greater than or equal to the cable switching time. For baud rates of 9600bps and 19200bps, the cable switching times are 2ms and 1ms respectively. The switching delay can be implemented using a timer interrupt in the ladder diagram program. Secondly, the handling of communication reliability is crucial. The use of a checksum is one of the most common measures to improve communication reliability. The most commonly used method is XOR checksum, which involves performing an XOR operation on the first character (excluding the start character) to the last character of the text in each frame, and sending the result (exhibition or checksum) as part of the message to the receiving end. After receiving the data, the receiver calculates the exhibit or checksum of the received data and compares it with the checksum sent by the sender. If they are different, a communication error can be identified. Finally, it is important to prevent confusion between the start character, end character, and data characters. Because the start and end characters of a message are only 8 bits, the probability of receiving data characters that are identical to the start or end characters is high, which can cause character confusion. The data can be processed before transmission, for example, by selecting special values ​​for the start and end characters and converting numeric characters to BCD or ASCII codes before transmission. This can avoid the above situation, but it will increase the programming workload and data transmission time. 2.3 Use and Explanation of Key Instructions in the Communication Program The transmit instruction XMT (Transmit) is used to initiate the transmission of data in the data buffer (TBL) in free port mode. The instruction format is shown in Figure 1. The information stored in the data buffer (TBL) is sent through the specified communication port (PORT). Error conditions that cause ENO=0 are: SM4.3 (runtime), 0006 (indirect addressing), 009 (XMT/RCV simultaneously on port 0), and 000B (XMT/RCV simultaneously on port 1). The XMT instruction can easily send 1 to 255 characters. If an interrupt routine is connected to the end-of-transmission event, port 0 will generate interrupt event 9, and port 1 will generate interrupt event 26 when the last character in the buffer is sent. The changes in the transmission completion status bits SM4.5 and SM4.6 can be monitored instead of using interrupts for transmission. The start and end characters in the data buffer are optional; the "character count" of the first byte is the number of bytes to be sent, but it is not sent itself. The receive instruction RCV (Receive) can easily receive one or more characters, up to a maximum of 255 characters. The received information is stored in the data buffer (TBL) through the instruction's communication port (PORT). The first byte in the data buffer is used to accumulate the number of bytes received; it cannot receive bytes itself. The start and end characters are optional. If an interrupt routine is connected to the receive end event, port 0 generates interrupt event 23 and port 1 generates interrupt event 24 when the last character is received. Error conditions that cause ENO=0: SM86.6 and SM186.6 (RCV parameter error), SM4.3 (runtime), 0006 (tone addressing), 009 (simultaneous XMT/RCV on port 0), 000B (simultaneous XMT/RCV on port 1). The CPU is not in free port mode. Changes in SM86.6 or SM186.6 can be monitored instead of using interrupts for message reception. When SM86.6 or SM186.6 is non-zero, the RCV instruction is not activated or reception has ended. They are 0 when receiving messages. Message reception should be automatically stopped when a timeout or checksum error occurs. A start condition and an end condition must be defined for message reception. The RCV instruction allows setting parameters to select the message start and end conditions, i.e., setting special memory bytes SM86~SM94 (for port 0) and SM186~SM194 (for port 1). Two other important instructions are the get and set communication port address instructions. The get port address instruction (GET ADDR instruction) reads the station address of the CPU port specified by PORT and places the value into the address specified by ADDR. The set port address instruction (SET ADDR instruction) sets the communication port (PORT) station address to the value specified by ADDR. The new address is not permanently saved; after power failure and power restoration, the communication port address will revert to the previous address value (the address downloaded using the system block). Figure 2 shows the flowchart of the communication program using the RCV instruction and receiving interrupt data. 3. Design and Implementation of Computer Communication Programs 3.1 PC Communication Program in Windows Environment In the Windows environment, the operating system controls various hardware resources through drivers, preventing users from directly performing low-level operations on the serial port as in the DOS environment. Therefore, Visual Basic provides a serial communication control: the MSComm control. Programmers can easily implement serial communication by simply setting and monitoring the properties and events of the MSComm control. 3.2 Properties of the MSComm control The main properties of the MSComm control are as follows: (1) Comm Port: Sets and returns the communication port number. (2) Settings: Sets and returns the baud rate, parity bit, data bits and stop bits in the form of characters. The characters n, o and e represent no parity, odd parity and even parity, respectively. (3) Port Open: Sets and returns the communication port status. When set to True, the port is opened; when set to False, the port is closed. In addition, there are Input, Output, Input Mode, In Buffer Count and other properties, which will not be introduced here. 3.2 How the MSComm control handles received information The MSComm control provides two processing methods: (1) Event-driven method: When the RTHreshold property is not 0, a serial port event On Comm will be generated when a character is received or the transmission line changes. These communication events can be captured and processed by querying the CommEvent property. (2) Query method: The received information is processed by querying the Iuput Buffer Count (number of bytes in the receive buffer) attribute value. This device adopts an event-driven approach. Designing a serial communication program using Visual Basic is simple and practical; the key is how to create a user-friendly interface. The programming details will not be elaborated here. With the introduction of industrial PCs, the reliability problem of personal computers in industrial field operations has also been solved. Therefore, realizing serial communication between PLCs and PCs in various measurement and control equipment is of great significance. On the one hand, this helps to develop personal computers into simple workstations or work terminals to achieve centralized display and centralized alarm functions; on the other hand, it also allows personal computers to be developed into PLC programming terminals, connected to the PLC network through the programmer interface for programming, debugging, and monitoring, and ultimately achieving the technical characteristics of simple structure, reliable operation, easy maintenance, and convenient secondary development of PLC measurement and control equipment.
Read next

CATDOLL 102CM Li (TPE Body with Soft Silicone Head)

Height: 102cm Weight: 15.5kg Shoulder Width: 26cm Bust/Waist/Hip: 51/46/66cm Oral Depth: 3-5cm Vaginal Depth: 3-13cm An...

Articles 2026-02-22