Butterfly valve airtightness detection and control based on PLC and PC free port communication
2026-04-06 05:45:14··#1
[Abstract] This paper introduces the implementation method of communication between a PC and an S7-200 PLC under freeport mode in VB6.0 environment. Combined with the development example of a gas leak test system for a butterfly valve for an optical experiment table, the key technologies of VB and PLC communication are analyzed, and brief explanations of important parts of the communication are also provided .Keywords : VB6.0; PLC; Freeport mode; Mscomm IntroductionWith the rapid development of programmable logic controller (PLC) technology, PLCs have been increasingly widely used in various industrial control fields in China. Siemens' S7-200 series small PLCs hold a significant position in the Chinese market due to their powerful functions, stable operation, and high cost-effectiveness. Their integrated communication interface provides users with robust communication capabilities. Based on different protocols, the PLC can communicate with various devices through the interface to form a network, enabling data transmission and control functions. The S7-200 series PLC supports freeport protocols, providing users with numerous conveniences. This paper mainly studies the implementation of freeport communication between the S7-200 PLC and a PC in the VB6.0 environment, and illustrates this with a development example of a safety valve detection and control system. 1. System Hardware Composition [align=center] Figure 1 Schematic diagram of the butterfly valve monitoring system[/align] The system mainly consists of an industrial computer, PLC, printer, and electrical control cabinet, as shown in Figure 1. To improve the reliability and flexibility of the control system, a PLC programmable logic controller is used. The selected PLC is the Siemens S7-200 series PLC, with the central processing unit being a Siemens S7-200 series CPU226. This CPU integrates two RS-485 communication ports, offering high cost-effectiveness and meeting all system requirements. One end of the 485 bus connects to the PLC's communication port PORT1, and the other end connects to the PC's RS-232 serial port via an RS-485/232 level converter, enabling the PC to send command frames to the PLC and receive response frames. The system has 6 stations and 12 sensors; due to the limited number of switch control points, expansion modules EM221 and EM231 are required. 2. Control Content and Requirements The system adopts distributed control. The industrial PC acts as the host computer, primarily responsible for monitoring and management functions such as data processing, communication with the PLC, and error correction. The PLC acts as the slave computer and is the core of the control, connected to the industrial PC via an RS485 interface. The information is input to the host computer, and the host computer sends the data and instructions to the PLC. The PLC receives the information from the host computer and responds, controls the opening and closing of the solenoid valve in real time, collects and monitors the pressure in real time, and feeds back the relevant data of each channel status to the host computer. The management program generates a database, which can perform statistics, reports, printing, etc. on the data. The design task of this control system needs to achieve the following objectives: (1) It can monitor the pressure change in the butterfly valve cavity and can manually set and automatically control the pressure value in the cavity. (2) It can control the system in automatic and manual modes. (3) The content displayed on the field display interface mainly includes: the pressure value, the current detection status, real-time fault alarm and historical fault alarm, etc. (4) The communication adopts the RS-485 bus communication mode, so that the PLC can communicate with the remote PC and realize the purpose of controlling the opening and closing of the solenoid valve through the PC to control the pressure. The PC also communicates with other systems, thus making the entire production process of the factory an organic whole. 3 PC and PLC Communication Basics 3.1 PLC Freeport Communication Commands The so-called freeport communication mode is a communication method based on RS-485 hardware. It allows users to define some simple and basic communication protocol settings, such as data length, parity check, etc. The communication function is completely controlled by the user program [1]. The relevant commands used in the freeport mode are XMT and RCV commands [2], which are used to send and receive data respectively. Each of these two commands corresponds to a data buffer, which can be determined by the user in the programming. For example, VB100 is a data storage area starting from VB100. The buffer format of XMT is shown in Figure 2. However, it should be noted that the freeport protocol is only effective when the PLC is in RUN mode. If it is in STOP mode, the PLC will automatically return to PPI mode (provided that PPI mode is used). 3.2 Mscomm Control To enable communication between the PC and the lower-level PLC, Windows provides the Mscomm control for user use. It encapsulates communication-related content; we only need to set its relevant properties and program its events accordingly in the VIII platform. Some important properties of the Mscomm control are shown in Table 1. Regarding the Mscomm control, there is only one event: the OnComm event. The OnComm event is generated whenever an error or event occurs during communication, and the CommEvent property returns different error or event values: [align=center]Table 1 Mscomm Control Properties[/align] The corresponding digital values allow for event processing. In the communication process described in this article, the ComEvReceive value is mainly used. This value is generated when there is data in the receive buffer, and then the Input value is processed accordingly. 4. Communication between PC and PLC on the VB6.0 Platform Visual Basic 6.0, manufactured by Microsoft, is a visual programming language development system for the Windows environment. It is widely used in engineering due to its powerful graphical design capabilities, simple programming language, and ease of learning and use. We used it for the development of communication with the PLC. The PLC I/O allocation table is shown in Table 2, listing only four stations. Based on the actual project requirements, we developed the corresponding PLC communication program. Due to space limitations, only a portion of the program is listed. However, it is important to note that in programming, in addition to setting the relevant registers, the program should also judge the received commands and select the appropriate program to run. Furthermore, since the PLC's communication port is an RS-485 communication port, which is a half-dual upper communication port, the XMT and RCV commands cannot be run simultaneously. [align=center]Table 2 I/O Allocation Table[/align] PLC Interrupt Program LDB= SMB86, 16#20 LPS MOVB 10, SMB34 ATCH INT1, 10 AB= 'K', VB301 AB= 'C', VB302 AB= '0', VB303 S Q0.0, 1 LRD AB= 'G', VB301 AB= 'C', VB302 AB= '0', VB303 R Q0.0, 1 LRD AB= 'K', VB301 AB= 'P', VB302 AB= '0', VB303 S Q0.1, 1 LRD AB= 'G', VB301 AB= 'P', VB302 AB= '0', VB303 R Q0.1, 1 LPP NOT RCV VB300, 0 5 VB Communication Programming Visual Basic development includes two parts: interface design and program development. 5.1 Human-Machine Interface Design The human-machine interface serves as an intermediary between the user and the computer, and is the window to the software product. The first consideration for the human-machine interface is how to better meet the user's usage requirements and operating habits. The design of the human-machine interface should consider the comprehensiveness of the interface functions and the ease of operation. The most frequently used functions should be arranged in the main interface as much as possible. If there are multiple functional modules, the independent modules can be represented by separate interfaces and bidirectionally connected to the main interface. As shown in Figure 3, the interface of this system includes status monitoring, identity login, parameter setting, report query, printing, alarm and event display. [align=center] Figure 3 Human-Machine Interface[/align] When designing the VB communication interface for the safety valve airtightness detection and control system, the important property of the Mscomm control is set as follows: InputMode property: comlnputModeBinary, read data in binary mode, because the data returned from the PLC includes bytes with ASCII code values exceeding 128. Settings property: 9600, n, 8, 1, selects a baud rate of 9600bps, no parity check, 8 data bits, and 1 stop bit. This setting must match the PLC settings for normal communication. RThreshold property: 1, triggers the ComEvReceive constant of the OnComm event when one character is received. 5.2 Communication Programming The following is a list of code snippets for receiving events in VB communication: If MSComm1.CommEvent = comEvReceive Then S1 = MSComm1.Input If (S1 = Chr(&H1B)) And (Len(SCOMS) > 5) Then SCOMS = "" Else If S1 <> Chr(&HD) Then SCOMS = SCOMS & S1 Else Call MYSAVE(SCOMS) End If End If End If Variable allocation in VB communication: SCOMS = Trim(SCOMS) 'Received 20 fields SCOMS = Right(SCOMS, 20) vh5 = Trim(Mid(SCOMS, 8, 4)) 'Store pressure value (string) yld1 = CCLng(vh5) vh6 = Trim(Mid(SCOMS, 12, 1)) 'Automatic signal zdd1 = vh6 vh7 = Trim(Mid(SCOMS, 13, 1)) 'Inflation signal cqd1 = CCLng(vh7) vh8 = Trim(Mid(SCOMS, 14, 1)) 'Exhaust signal ending statement In practice, the free-port communication mode is adopted, and VB6.0 is used as the development tool to conveniently realize the communication between the S7-200 PLC and the host PC, realizing the control of the butterfly valve's airtightness detection. Field debugging and operation show that this is a very effective and reliable communication method. This communication method can also be applied to other related communication scenarios and has certain universal significance. References: 1 Zhang Weijun, Suo Shiwen, et al. Application of PLC in Automated Warehouse Control System. Mechanical Design and Manufacturing, 2004 (2), 55. 2 Siemens Ltd. Siemens SIMATICS 7-200 Programmable Controller System Manual, 2000, 9-140. 3 Fan Yizhi, Chen Liyuan. Visual Basic and RS-232 Serial Communication Control. Beijing: Tsinghua University Press, 2002, 59-65. Author Biography: Li Lei (1978-), male, master's student, native of Shandong, research direction: power electronics and electric drive. Mailing address: P.O. Box 468, Taiyuan University of Science and Technology, Taiyuan, Shanxi Province, 030024, China. Tel: 13099062062. Email: [email protected]