Electrical discharge control system based on Modbus protocol
2026-04-06 05:28:03··#1
Abstract: This paper proposes a bus control system based on the Modbus protocol, analyzes the characteristics of the Modbus protocol, introduces its content and communication process, and presents the software implementation method of the system, including the system flowchart and some verification code. Keywords: Modbus, fieldbus, electrical discharge machining, RTU 0. Introduction Due to real-time requirements, most electrical discharge machining equipment in China uses a DOS-based control system. While this system meets the basic requirements of electrical discharge machining, it significantly hinders improvements in human-machine interaction and modern control requirements such as remote communication. Modular structures offer strong scalability, easily meeting the needs of different users and providing a good foundation for further system development. Specialized signal acquisition and detection devices ensure stable and reliable system operation. The application of network technology enables integrated and intelligent information processing. Simultaneously, the development of VB, VC, and various configuration software provides a good development environment for human-machine interfaces and bus control, enabling the design of more rational and user-friendly systems. This paper attempts to apply fieldbus theory to electrical discharge machining tools and ultimately achieve interconnection between devices using the Modbus protocol. [4] Fieldbus is a system used in production sites to realize bidirectional serial multi-node digital communication between microcomputer measurement and control devices. It is also known as an open, digital, multi-point communication underlying control network. [5][6] Fieldbus occupies an important foundational position in the control network of the entire factory. 1. Control System Structure 1.1 Basic System Structure Fieldbus control systems generally use a host computer combined with a lower-level intelligent instrument to realize control functions. In this system, since the detection device of the system is simple and easy to use, a microcontroller is used to read the signal and finally transmit it to the host computer. Generally speaking, the bus system mainly includes transmitters, bus and detection station. In this system, the microcontroller and detection device become intelligent instruments, i.e., transmitters. It is used as a slave, but it is the core component of the system. The host computer, i.e., the detection station, mainly completes the human-machine interaction task and some optimization, complex calculation and control functions. The personalized human-machine interface and the standardized bus structure design can easily expand the control functions of the system. The overall system structure diagram is shown in Figure 1. The system mainly includes a server, a PC, three microcontrollers and related detection devices. [align=center]Figure 1 System Structure Diagram[/align] The main functions of these layers include: 1. The bottom layer is the data acquisition layer, which needs to collect real-time data from the field, such as oil temperature and oil level. Three microcontrollers serve as the core devices of the field control layer, each assigned a unique local address for identification. The microcontroller, also known as the transmitter, is the core device of the entire system. Its main function is to collect real-time data such as gap voltage, liquid level and oil temperature, limit alarm, and manual control box control, automatically realize servo control, automatic fire suppression, fan switching, timed tool lifting, and other functions, and simultaneously output the data to the Modbus fieldbus measurement and control network. 2. The task of the field control layer is to send all processing statuses to the monitoring computer in the control room via double-pole cables to form a fieldbus network. In this network, all transmitted information follows the Modbus protocol. The Modbus fieldbus connects the field transmitters and the detection station into a measurement and control network to realize the monitoring, measurement, and management of electrical discharge machining. 3. The factory monitoring layer is equipped with human-machine interface software, responsible for monitoring all processing parameters (electrical standards), as well as the display of all relevant data and the processing of keyboard input information, etc., and other human-machine interaction processes. The PC acts as the monitoring computer, connected to the remote management center via Ethernet to achieve network operation upwards; the monitoring computer can install Modbus for on-site click operations. 4. The top layer is the remote management layer, which can consist of local area network segments such as Ethernet and .top. It typically includes a server. PCs are connected to the server via Ethernet cards and gateways, or via routers to the wide area network. The server is an external expansion component of the system and can be selected. 1.2 Physical Implementation Currently, Modbus communication can be implemented in three ways: TCP/IP over Ethernet; serial link transmission over various media (wired: EIA/TIA-232-F, EIA-422, EIA/TIA-485-A; fiber optic, wireless, etc.); Modbus PLUS, a high-speed token passing network. The choice of implementation method mainly depends on the position of the connected devices. Generally, a standard RS-232 port is sufficient, but since the RS-232 transmission distance on a computer does not exceed 30m, a RS-485 interface can be used. In addition, the RS-422 port is also a standard serial data interface; Table 1 lists the main differences between them. This system uses isolated RS-485 communication to provide hardware support for Modbus. [align=center]Table 1 Comparison of Wired Media Transmission Performance[/align] The Modbus system is a master-slave network that allows one computer to communicate with one or more slave devices. When communicating on a Modbus network, each controller has its own device address. The master identifies the message sent according to the address and decides what action to take. When transmitting over other networks, messages containing the Modbus protocol are converted into frame or packet structures used on that network. At this time, the controller can act as either a master or a slave device, but not both simultaneously. Depending on the different interfaces of various devices, devices such as printers can also be connected in series on the bus, or these devices can be directly connected to the printer port or USB port of the monitoring computer to achieve communication. The chip selection depends on the received information. For digital signals, common microcontrollers or PIC microcontrollers are suitable. For analog signals, such as gap voltage, a chip with an analog port is required. Cable selection depends on the chosen transmission channel and distance; here, a shielded twisted-pair cable is used. 2. Modbus Protocol The Modbus protocol is an application layer message transmission protocol at layer 7 of the OSI model. It provides client/server communication between devices connected to different types of buses or networks. The Internet has reserved TCP/IP system port 502 for accessing Modbus, and the Modbus protocol has become a popular industrial control transmission standard. 2.1 Protocol Content The Modbus protocol defines a common format for messages, formats, and content. It primarily uses a command/response method. Each command message corresponds to a response message. The command message is sent by the master station, and when the slave station receives it, it sends a corresponding response message. Modbus information frames include station, byte length, function code, operation address, operation data, CRC checksum, etc. There are two effective transmission modes in the Modbus system, namely ASCII (American Standard Code for Information Interchange) and RTU (Remote Terminal Unit) mode. The content format and character length are as follows: [2] Since the RTU mode has fewer transmission bits and is easy to use, the content of this paper adopts the RTU mode. 2.2 Communication process The communication process between Modbus master and slave nodes is roughly as follows: (1) The slave node establishes a connection with the master node through a specific port and waits to receive the request frame signal sent by the master node. (2) The master node selects the appropriate function according to the actual needs, saves the corresponding function code in the function code field of the ADU, saves the necessary parameters and sub-function codes in the data field, and stores the transmission flag, protocol flag, data length, etc. in the flag field, thereby forming a complete data frame and sending it to the slave node. (3) After the slave node detects the error of the received request frame, it decomposes it into basic functional units according to the provisions of the protocol, and completes the specific operation according to the requirements of the function code. Finally, it returns a function response signal. If the request frame or a certain step of the operation is wrong, an error report is returned. Complete error response is a feature of Modbus, which helps the master node to judge the cause of communication error, thereby eliminating it, ensuring reliable communication and improving the success rate of communication. [3] 3. Software Implementation Software implementation includes: initialization keywords, including baud rate setting, data bits, stop bits, parity check mode, etc. The above settings of all masters and slaves on the bus should be completely consistent. Modbus programming mainly needs to handle the generation of check code and the detection of data packet start flag. [3] 3.1 Address Definition The communication program must handle the start flag of data packet well, because every time the master sends data, all slaves will receive the information, but only slaves with the same address will respond. Therefore, address identification is crucial. The Modbus protocol will provide 3.5 frames of idle time between two data packets. During this time, all slaves on the bus should be ready to receive. Once the master sends a data packet, the slave immediately accepts the data. The first frame is the address frame. The slave records the address and determines whether to execute the function. Typically, a 3.5-frame timer is set in the program. The timer doesn't count when there is data on the line, but starts counting once the line is idle, continuing until it stops. At this point, data packets begin to be sent on the line; this first frame is the address frame. It's important to note that the 3.5-frame time is not constant and should be determined based on the transmission rate and frame check method (parity check or no check). [align=center]Table 2 ASCII Mode Transmission Format[/align] [align=center]Table 3 RTU Mode Transmission Format[/align] 3.2 Function Code Definition Both the services requested by the client and the services provided by the server are identified by function codes. Modbus function codes are of three types: common function codes, user-defined function codes, and reserved function codes. Common function codes are defined function codes, guaranteeing their uniqueness, and include existing defined common assigned function codes and unassigned reserved function codes for future use. User-defined function codes have two definition ranges: 65 to 72 and decimal 100 to 110. Users can select and implement a function code without any approval from the Modbus organization. Reserved function codes are those commonly used by some companies for traditional products and are invalid for public use. For ease of use, in this system, we only write three public function codes from the Modbus protocol: 0x06 for writing a single register, 0x13 for reading multiple registers, and 0x17 for reading and writing multiple registers. Taking writing a single register as an example, the flowchart of the request information and response function is as follows: [align=center] Figure 2 System Response Flowchart[/align] In addition, we can extend other functions, such as using the function codes 0x20 for reading file records and 0x21 for writing file records to store relevant system information, such as fault records, used standard queries, and usage status of various devices. 3.3 Generation of Checksums Depending on the transmission mode, the system needs to generate different checksums. ASCII mode uses LRC (Longitudinal Redundancy Check) while RTU uses CRC (Cyclical Redundancy Check). Functions for implementing these two methods can be found in relevant materials. The following is a CRC checksum designed in C language, where Unsigned char* data is a pointer to the message buffer, Unsigned char length is the number of bytes in the message buffer, and the generated return value reg-crc is the returned checksum. [2] unsigned int crc_chk(unsigned char *data, unsigned char length) { int j; unsigned int reg_crc=0xFFFF; while(length——) { reg_crc︿=*data++; for(j=0;j<8;j++) { if(reg_crc&0x01) { reg_crc=(reg_crc>>1)︿0xA001; } else { reg_crc=reg_crc>>1; } } } return reg_crc; } 4. Summary Through the above system, it is hoped that it can be connected with advanced control equipment, thereby improving the speed of system improvement and enhancing the overall performance of the machine tool. The author's innovation lies in applying the widely used Modbus protocol to electrical discharge machining (EDM) machines, achieving excellent machining results and improving the overall automation level of the machine tool. 5. References (1) Zhu Xiaoxiang. Modbus communication protocol and programming. Electronic Engineer, vol.31. No.7 jul. 2005 (2) Delta VFD-M frequency converter user manual (3) Implementation of communication node based on Modbus/TCP protocol. Machine Tool & Hydraulics, 2004. No.12 (4) Yang Dayong. Research on CNC system for electrical discharge machining. Electrical Discharge Machining & Mold, 2003, No.1 (5) Bao Jilong, Ye Ping. Networked development of industrial monitoring system. Microcomputer Information, 2006, No.6-1, P66-68 (6) Yang Xianhui. Fieldbus technology and its application. Beijing: Tsinghua University Press, 2000 (7) Chen Weigang. Development of an industrial Ethernet and fieldbus protocol converter. Journal of Instrumentation, Vol.26, No.5