Share this

Implementation of PC-PLC serial communication in metallographic cutting machine

2026-04-06 06:02:06 · · #1
Abstract: This paper takes the PC-PLC control system of a large metallographic sample cutting machine as the application background. Based on the serial communication protocol between PC and PLC, it explains in detail the command frame and response frame formats of communication between OMRON CPM2AH series PLC and computer. The serial communication between PC and PLC is realized by using the MSComm control in VB6.0, and the corresponding data communication program is given. Keywords: PC-PLC; control system; serial communication; MSComm control Abstract: This paper considers a PC-PLC control system of a large metallographic specimen cutter as the background. Based on the PC and PLC serial communication protocol, it explains the order frame and response frame of communication between the PLC and the computer. Using VB MSComm control, it realizes the serial communication between the PC and the PLC. Finally, the data communication procedure is provided. Key words: PC-PLC; control system; serial communication; MSComm control 0 Introduction Programmable logic controllers (PLCs) have advantages such as ease of use, high reliability, and strong anti-interference ability, and are therefore widely used in industrial control. However, most small and medium-sized PLCs have poor display functions and inconvenient human-machine interaction. In practical control systems, PLCs are usually combined with personal computers (PCs) to complement each other's advantages, greatly improving the cost-effectiveness of the control system. The key to realizing a PC-PLC control system is to achieve reliable data communication between the two. This paper focuses on the PC-PLC-based control system for a large metallographic specimen cutting machine developed by our research group. Under the Windows environment, a serial communication program between the computer and the OMRON CPM2AH PLC was designed using the MSComm control in Visual Basic 6.0. This achieves reliable communication between the PC and the PLC, enabling real-time equipment monitoring and information management of the large metallographic specimen cutting machine. 1. Control Scheme for the Large Metallographic Specimen Cutting Machine To address the shortcomings of domestic metallographic specimen cutting equipment, such as a small cutting range (cutting diameter ≤ 100mm), low automation level, and inability to directly sample large parts, our research group designed an automatic control system for a large metallographic specimen cutting machine based on PC-PLC. This system uses frequency conversion speed regulation for a three-phase asynchronous motor, allowing the cutting blade speed to be steplessly adjustable from 0 to 3400 r/min. The cutting blade speed can be set according to the specimen material. A stepper motor drives a worm gear to swing the arm, achieving the Z-axis feed (i.e., vertical feed) of the cutting blade. Two other stepper motors drive the worktable in the X-axis (left-right) and Y-axis (back-forward) directions via lead screws and nuts. The system has four cutting modes: constant speed cutting, three-step forward/one-step backward cutting, layer-by-layer cutting, and continuous cutting. In this system, the PLC acts as the lower-level machine, using sensors to collect and monitor information from motors, frequency converters, and other related objects. After processing the input information and integrating the information obtained by the acquisition unit, it feeds back to control the monitored objects and sends the information to the upper-level PC. On the other hand, the PLC receives control commands from the PC, analyzes and judges the input and operation commands, performs comprehensive processing, and outputs control signals to control the cutting machine. The upper-level computer monitors the PLC, sends control information, and can also receive information collected by the PLC, providing fault alarms and parameter displays for the monitored objects. The system has functions such as cutting mode selection control, system start, stop, and pause control, cutting status display, cutting speed display, and accident alarm display. 2. Hardware Configuration of PC-PLC Serial Communication The communication between the PC and the PLC adopts an asynchronous serial method using an RS-232C interface. To connect the CPM2AH to a PC, first connect it to an RS-232C adapter via the CPM2AH's external port. The RS-232C adapter used is model CPM1-CIF01, and its mode setting switch is set to "OFF". Then, connect it to the computer's serial port via an XW2Z-500S cable. The cable wiring is shown in Figure 1. [align=center] Figure 1 RS-232C Cable Wiring Diagram[/align] 3 MSComm Communication Control in VB After comparing various visual programming languages, VB6.0, which is simple to learn and efficient, was chosen as the programming language for the host computer. It provides a dedicated MSComm control for serial communication. This control has very complete serial data sending and receiving functions. Asynchronous serial communication can be easily achieved by simply setting and monitoring the properties and events of the MSComm control. It has many attributes, and the following are descriptions of some of the commonly used main attributes: CommPort: Sets and returns the communication connection port number; Settings: Sets initialization parameters, setting or returning four parameters in string form: baud rate, parity, data bits, and stop bits; PortOpen: Sets and returns the status of the communication connection port, and can also open and close the port; InputMode: Sets and returns the data type retrieved by the Input property, i.e., determines whether data is received in binary or text mode; CommEvent: Generates an OnComm event when a communication error or event occurs, and the CommEvent property stores the numerical code of the error or event. The MSComm control provides two ways to handle communication: one is event-driven, which is a very effective method for handling serial port interactions; the other is polling, where after each key function of the program, the value of the CommEvent property can be read to query communication events and errors, and corresponding actions can be taken. 4 Serial Communication Protocol The PLC initializes the serial communication interface by setting certain units in the DM area of ​​the data storage, and selects the host computer connection communication mode. The selected communication protocol is 9600 baud, 7 data bits, 2 stop bits, and even parity. The PC's serial port COM2 is selected as the communication port with the PLC. The communication between the PC and PLC uses a master-slave response mode, with the PC always having transmission priority and issuing read/write commands to the PLC as needed; the PLC passively responds to commands from the host PC. The PC and PLC are initialized first, setting their communication format (mainly including baud rate, parity, data bits, and stop bits), and the communication format must be consistent. When sending commands from the host computer, the format of the command data written in the program is shown in Figure 2. [align=center]Figure 2 Command Frame Format[/align] Where: @ is the frame start marker; IP2 and IP1 are the PLC node identifier codes, two-digit decimal numbers, used to specify the PLC communicating with the host computer. Corresponding to the host computer, the PLC can set its own communication node code in DM; ID2 and ID1 are two-byte command codes; CT is the text content, used to set specific command parameters; F2 and F1 are two-byte frame checksums (FCS), which are the bitwise XOR results of the ASCII codes of all characters from the start character "@" to the end of the text; the characters "*" and "/" indicate the end of the command. After the command frame is successfully transmitted, the PLC immediately sends a response frame to the PC, as shown in Figure 3. [align=center]Figure 3 Response Frame Format[/align] Where: @ is the frame start marker; TP2 and TP1 are PLC node identifiers for communication with the host; ID2 and ID1 are two-byte command codes; E2 and E1 are command end status codes, 00 indicates normal end, 01 indicates failure to complete in RUN mode; CT is the text content, generated only when a read data command is received; P2 and P1 are two-byte frame checksums (FCS), which are the result of bitwise XORing of the ASCII codes of all characters from the start marker "@" to the end of the text; the characters "*" and "/" indicate the end of the command. 5 PC-PLC Serial Communication Programming In the communication process between the PC and PLC, the PC takes priority, sending a command to the PLC to start communication, and the PLC automatically returns a response. When reading data, the PC sends a read data command to the PLC through the serial port, the PLC responds and prepares the data, and then the PC can read the required data by reading the serial port again. When writing data, the PC sends a write command and data to the PLC through the serial port, and the PLC receives it. The data transmission process is shown in Figure 4. [align=center] Figure 4 Data Communication Flowchart[/align] The following is a partial communication program: (1) Serial Port Initialization Private Sub Form_load () MSComm1.CommPort=2 'Select COM2 port for communication MSComm1.Settings="9600, E, 7, 2" 'Set the communication format, 9600 baud, even parity, 7 data bits, 2 stop bits MSComm1.InputLen=0 'Read all data in the buffer MSComm1.InputMode=ComInputModeBinaiy 'Set the communication format to unary MSComm1.PortOpen=True 'Open the port End Sub (2) Data Sending Program Private Sub Send_Click () Dim outarr As Byte MSComm1.Output= Outarr 'Send data End Sub (3) Data Receiving Program Private Sub MSComm1_OnComm () Dim buffer As Variant 'Data read from the buffer is received by a Variant variable. Dim inarr As Byte. Select Case MSComm1.CommEvent. 'After the ComEvReceive event is triggered, the data is stored in the corresponding array, and the working status display subroutine is called. Case ComEvReceive inarr = MSComm1.Input. End Select. End Sub . 6. Conclusion This paper utilizes the MSComm control in VB6.0 to design serial communication between a PC and a PLC, thereby realizing remote real-time monitoring and data management of a large metallographic specimen cutting machine. Actual operation proves that the PC-PLC control system of the cutting machine is stable and reliable, easy to operate, and has advantages such as flexibility, strong real-time performance, and high performance-price ratio. It not only enables the cutting of workpieces up to 150mm in diameter but also improves sample preparation efficiency, showing broad application prospects. The author's innovation lies in applying PC-PLC serial communication technology to a large metallographic specimen cutting machine, organically combining the powerful control function of the PLC with the efficient information management function of the PC, thus realizing remote real-time monitoring and data management of the cutting machine. A serial communication program was designed using the MSComm control in the visual high-level programming language VB6.0. The program is concise yet powerful. Experiments have shown that the system can directly sample large parts with a diameter of 150mm, placing it in a leading position in the domestic industry. References: [1] Li Jie. Research on large metallographic sample cutting machine based on PLC control [D]. Baoding: Hebei Agricultural University, 2004, 6 [2] Yang Yonggang, Yang Jidong. Design and research of serial communication between PLC and host computer [J]. Machinery and Electronics, 2004, 8: 68-70 [3] Xiao Yingwang, Xu Baoguo. Implementation of serial communication program between PLC and host computer [J]. Instrumentation and Analysis Monitoring, 2003, 4: 8-10 [4] OMRON-CPM2AH series programming manual [Z]. Shanghai Omron Automation Systems Co., Ltd., 1999 [5] Li Yan, Guo Zongren, Wang Zhikai, Li Peng. Serial communication method and program design between PLC and computer [J]. Control Engineering, 2002, 9 (3): 84-86 [6] Tian Hongfang, Li Yinghong. Serial communication between PLC and host computer [J]. Microcomputer Information, 2001, 17(3): 36-37
Read next

CATDOLL Ava Soft Silicone Head

You can choose the skin tone, eye color, and wig, or upgrade to implanted hair. Soft silicone heads come with a functio...

Articles 2026-02-22