1 Introduction
Siemens S7-200 PLCs are widely used in industrial control due to their small size, high reliability, and powerful communication capabilities. The S7-200 PLC's cost-effective freeport communication protocol enables flexible and convenient human-machine interfaces. Currently, there are two main methods for S7-200 PLCs to receive computer instruction data: the first method uses the PLC's built-in RCV instruction to receive computer data; the second method uses the PLC's "receive character interrupt" mode, defining a pointer in SMB2 (freeport receive character buffer) and using the pointer to receive data.
While using the "RCV" instruction to receive data is simple, receiving large amounts of data sequentially each time significantly reduces data transmission efficiency. In a mechatronics control system in our laboratory, the human-machine interface (HMI) design requires that the interface can write different instruction data to the PLC, such as QB0, QB1, QB2, sensor sampling period, a judgment instruction, AQ0, and AQ1. If a single instruction write from the host computer only controls the start of QB0.3 , then all 9 bytes of data need to be sent to write to QB0. Since the PLC receives data using the "RCV" instruction, the 9 bytes of data must be stored sequentially. This causes excessive delays in the data transmission line, reducing data transmission efficiency and even leading to errors. Clearly, this method of receiving large amounts of data using "RCV" is unsuitable.
Using the "receive character interrupt" method provided by the PLC, a pointer is defined for SMB2 (free port receive character buffer) to receive data. If only a single pointer is defined, the effect is the same as the "RCV" instruction. However, because this method is more flexible, this paper designs a multi-address pointer method for receiving data. When the computer writes data to the PLC, only the pointer identification code and corresponding data are written to complete the write instruction from the host computer to the slave computer. Different codes correspond to different addresses. Compared with the previous use of the "RCV" instruction, this effectively reduces the amount of data written and improves communication efficiency. This paper designs this scheme in the serial communication between the PLC and the host computer; no other similar articles have used this approach.
2-pointer discrimination
In freeport communication between a PLC and a computer, to eliminate the large data flow caused by "RCV" or single-pointer data reception from the computer, this paper stipulates that when the computer sends an instruction to the PLC, the first byte is always the mode code, and the instruction data begins from the second byte. When the PLC receives data, when the first data enters the "freeport receive character buffer" SMB2, the PLC first receives the pointer discrimination code through the "selection pointer". By comparing the value of the received code, it determines what type of data the instruction data corresponds to. After the determination, an address pointer is defined to receive and store the content of this type of data. Different pointer discrimination codes correspond to different address pointers. Therefore, the instruction data sent by the computer each time it writes an instruction to the PLC consists of two parts: the first part is the pointer discrimination code, and the second part is the instruction data content. The pointer discrimination process is that the PLC receives the discrimination code and performs a value comparison. The significance of pointer discrimination is that by receiving the mode code through a general pointer, multiple pointers are defined using different mode codes to complete the reception and storage of different types of instruction data.
3 Specific Application Schemes
In the design of an electro-hydraulic servo control system for this laboratory, the host computer's human-machine interface (HMI ) is programmed using VB6.0, and the slave computer uses free-port communication. The HMI design requirements are: the interface should be able to write different instruction data to the PLC, such as QB0, QB1, QB2, sensor sampling period, AQW0, and AQW2. The PLC should periodically send the monitored data (including digital and analog quantities from the PLC) from variable memories VB1 to VB21 to the host computer using the XMT instruction within a timer interrupt. Since the host computer writes various types of instruction data to the PLC, including timer interrupt settings, status bit values, and outputs from analog expansion modules, this paper selects a mode that allows different types of instruction data to be received and stored using multiple pointers. Table 1 shows a partial address allocation table for the PLC program in this design, to illustrate the specific implementation method of the multi-address pointer scheme in conjunction with the PLC program.
SBR_0 subroutine initialization:
Network 1: Define interrupt events in subroutines.
Pointer-based discrimination is used in the INT_0 character reception interrupt event:
Network 1: Pointer code reception is stored in VB22.
Network 2: Start pointer 1, receives data and writes it to VB24, used to start/stop XMT (0 to start, 1 to stop).
Network 3: Start pointer 2, receive data and write to VB26, VB27, VB28, used to write to QB0, QB1, QB2.
Network 4: Start pointer 3, receive data to write the timer interrupt setting SMB34.
Network 5: Start pointer 4, receive data and assign it to the PLC analog output AQW0.
Network 6: Start pointer 5, receive data and assign it to the PLC analog output AQW2.
In the INT_1 timer interrupt event, the PLC sends monitoring data:
Network 1: The data received by VB24 controls the "start/stop" action of XMT, which in turn controls the PLC to send data to the computer.
4 Key Points to Note
In this design, when the PLC receives data, the first byte, the "pointer identifier," is entered into SMB2. During an interrupt event, the value of this pointer identifier is also stored in the first memory address corresponding to each pointer. Therefore, when each pointer receives data, the instruction data content begins from the second byte onwards. The first byte always corresponds to the pointer identifier; otherwise, data transmission errors will occur. In PLC programming, it is necessary to reserve the first memory address for each pointer to store its identifier.
Therefore, each time the host computer writes an instruction to the PLC, the first data content is a pointer code, which can be directly assigned by the host computer program; from the second data onwards, it is the host computer's control instruction.
5 Conclusion
This design has been successfully applied to the human-machine interface of a laboratory mechatronics control system. The system operates stably, significantly reducing data transmission unrelated to host computer operation commands. It can accurately and efficiently write host computer command data to the target address, effectively solving the latency caused by large amounts of data transmission in serial communication.