Share this

Design and Implementation of CNC Software Based on Windows

2026-04-06 07:22:39 · · #1
Abstract: Windows-based CNC is an inevitable trend in the development of CNC technology. This paper proposes a method for implementing real-time multitasking in the Windows environment, and introduces the architecture and related technologies of CNC software implementation. Practice has proven that these methods and technologies effectively realize real-time multitasking control of CNC systems. The developed CNC software is open. Keywords: Multithreaded, Real-time, Multitasking, CNC System, Interrupt, Object-Oriented 1 Introduction The entry of PCs into the CNC field has greatly enriched the hardware and software resources of CNC systems, facilitating the realization of bus-based, modular, and open CNC systems, giving them a high performance-price ratio. With the development and popularization of Windows systems, developing CNC systems under Windows environments (Windows 95, Windows NT, and Windows Cr) has become a consensus among CNC professionals. In recent years, many domestic manufacturers have developed several Windows-based control systems. Domestic control systems each have their advantages, but from the perspective of CNC system development trends, there are still many areas for improvement. First, new operating systems such as Windows, UNIX, and OS/2 have not been fully utilized. Software development concepts and technologies are lagging behind, consistently at or even below the level of structured programming. New theories and technologies of object-oriented programming have not been fully utilized. Secondly, the CNC system software design suffers from non-standard design, poor reliability and maintainability, and lacks an open, modular software design approach. The system software introduced in this paper utilizes Windows' multi-threading and interrupt mechanisms to solve real-time multi-tasking in CNC software; it employs object-oriented theories and technologies, adopting an open, modular software design approach to make the software open. This system software enables interpolation, servo control, and NC programming to be performed simultaneously, effectively meeting the requirements of CNC systems, and has already been developed into a product with good application results. 2. Overall Design of CNC Software To give the CNC software a distinctly open CNC characteristic and facilitate its assembly, expansion, and maintenance, we adopted an engineering design approach, developing a Windows 32-bit CNC software using object-oriented technologies. The software design follows the principles of modularity, hierarchy, and dynamic configuration. An open control system should adopt a layered architecture. Layering isolates each layer, and communication between layers occurs through standard interfaces, achieving portability and the availability of third-party software; only the corresponding layer needs to be replaced. The first vertical layer of this system is the interface layer, which handles system monitoring and management: input, O processing, display, diagnosis, and monitoring. This interface layer consists of the interface and various callback functions. The callback functions perform event-driven operations on the controls on the interface. The calling of callback functions is managed by the operating system. The second vertical layer of the system is the functional unit layer, including decoding classes, tool compensation classes, interpolation dynamic link libraries, and motion controller classes. The decoding layer interprets CNC instructions into the internal data format of the CNC system. The tool compensation layer performs tool compensation. The interpolation dynamic link library performs data interpolation, generating machining data, speed processing, and auxiliary function device control. The motion controller class performs position servo control. The decoding class and tool compensation class are each composed of multiple software chips. The calling of this functional unit layer is placed in the callback functions. The third vertical layer of the system is the support layer, including the motion controller card, the motion controller device driver, I/O cards, the operating system, and the PC. The motion controller card mainly performs position servo tasks. The motion controller device driver performs direct operations on the motion controller card and I/O cards. The system architecture is shown in Figure 1. The CNC system software employs a foreground/background structure. The foreground program, or real-time interrupt program, performs all real-time functions (interpolation dynamic link library, motion controller class, device driver), primarily interpolation. The background program's main functions are pre-interpolation preparation and scheduling management (including interface decoding and tool compensation). Specifically, it handles CNC program input, decoding, tool compensation, display, and scheduling management between these tasks. The background program structure is multi-threaded, handling multiple tasks. During operation, the foreground program (interrupt service routine) continuously interrupts, working together to complete the part machining task. The position servo task is mainly handled by the motion controller. After the machining program is decoded, tool compensated, and speed processed by the computer, the interpolation command data for the tool center is obtained. The computer stores this interpolation command data and other command data in a buffer in a fixed format. Each time an interrupt occurs, the computer processes this command data accordingly. If an interpolation command exists, the interpolation data is calculated in real-time and entered into the buffer. The motion controller then controls the motor movement of the corresponding axis based on this data. After a frame of instruction data in the computer is read, new interpolation instruction data is automatically calculated during the interpolation interval and filled into the buffer. 3. Implementation Method 3.1 Multi-task Real-time Control Strategy of the Software System The CNC system is a dedicated multi-task computer system. Its control software integrates many advanced software technologies, the most prominent being multi-task parallel processing and real-time processing. • Multi-task Parallel Processing A CNC device is typically used as an independent process control unit in industrial automation production processes. Its software must perform both management and control functions. The system management part includes input, I/O processing, display, and diagnostics. The system control part includes decoding, tool compensation, speed processing, interpolation, and position control. In the actual operation of the CNC device, several tasks must be performed simultaneously. • Real-time Processing In the actual application of industrial automation, CNC software must have real-time performance to meet production requirements. To enable our CNC software to have parallel and real-time processing capabilities, we adopt a control strategy using the Windows 95 multi-threading model and interrupt mechanism. 3.1.1 Windows Multithreaded Model To enable the CNC system software to process multiple tasks in parallel under the Windows environment, multithreading is used to achieve multitasking control. Threads are a key feature of 32-bit operating systems, supporting preemptive multitasking mechanisms and serving as the basic scheduling unit of the operating system. We can place each management and control module in an independent thread, thereby achieving parallel processing operations in the CNC software system. In our CNC software, we have established a main control thread (monitoring and interface thread), a display/panel operation thread, and an automatic machining thread. The preset time slice for the display/panel operation thread is 50ms. The automatic machining thread is started and eliminated by the main thread. By establishing these three threads, the coordinated operation of the entire system can be achieved. The main control thread mainly performs monitoring and interface management, function control, system management, and is responsible for starting and eliminating the automatic machining thread in real time. When the system exits, the display/panel operation thread is eliminated. The main control thread implements its operation flow through Windows message queuing. 3.1.2 Windows Interrupt Mechanism Windows is a non-exclusive multitasking system. Applications receive input and then messages through an application queue. The system continuously retrieves input messages from the application queue and sends them to the corresponding window. Real-time control is difficult in this working mode. However, from another perspective, user keyboard, mouse, and timer inputs are all hardware interrupts, and the device drivers provided by Windows are actually interrupt service routines. Since actual machining has high real-time requirements, interrupt-driven operations must be used to implement real-time tasks. Because interrupts can occur at any time, not limited to the running of the application using the device, interrupt service routines must be in a fixed code segment. In the large-framework EMS memory configuration, only one type of code can guarantee that such interrupt services can be performed at any time. This type of code is the code in the fixed code segment of a dynamic link library (DLL). Therefore, DLLs must be used to implement interrupts. In our system, hardware interrupts are implemented using DLLs, and the operation is reliable. In our software, the automatic machining thread in Figure 2 uses an interrupt mechanism for real-time control. The automatic machining thread mainly performs tasks such as opening NC files, syntax checking, decoding, tool compensation, interpolation, and generating machining data. Among these functions, interpolation must be completed in real time, hence the use of interrupt service routines. The automatic machining thread is started in the callback function. The control flow of the automatic machining thread is shown in Figure 3, and the interrupt service routine control flow is shown in Figure 4. Since dynamic link libraries can be flexibly loaded and unloaded by the application as needed, the system resources occupied will be reduced accordingly. Therefore, the interpolation interrupt service routine is compiled and linked into a dynamic link library for use. 3.2 Object-Oriented Development Technology Because object-oriented software development technology integrates functional abstraction and data abstraction, it better realizes the extensibility and polymorphism of software and makes the software easy to modify. We use an object-oriented method to model the CNC software, describing and implementing it in three layers: system, control unit, and basic classes, making the CNC software assemblable and easily extensible. Basic classes are the result of fine-grained decomposition of the CNC system functions and are the smallest unit constituting an open system. Basic classes constitute the class hierarchy of object-oriented CNC software. Basic classes with standardized interfaces are called software chips. Control units are software entities that perform certain functions, composed of a series of functionally related basic classes. Control units can be nested. A system is a type of CNC system software composed of a series of control units. Our CNC software development includes classes for motion controllers, decoders, and tool compensation. These function as units, respectively performing position servo, decoding, and tool compensation functions. The decoder and tool compensation classes are more complex, consisting of inheritance from multiple software chips. 3.3 Multi-Buffer Technology The motion controller, decoder, tool compensation, and dynamic link library are relatively independent functional units, but they exchange a large amount of data with each other. Therefore, multi-buffer technology is used to implement data exchange. This is to coordinate the operation of different threads and tasks, making each module relatively independent. Multiple data buffers are established in the software. The specific implementation method is as follows: (1) Allocate memory for multiple buffers, establish read and write pointers pointing to the current buffer, and form a circular multiple buffer; (2) Set a flag bit for each memory block as the basis for judging the operation of the buffer; (3) For each buffer read, set the read flag for the buffer and move the current read pointer forward by one buffer; (4) For each buffer written, set the write flag for the buffer and move the current write pointer forward by one buffer; (5) For the buffer where the current operation has not ended, set the operating flag and prohibit other operations. By using this method, the calculations that must be completed in a single interpolation cycle in the system are "averaged" and completed in multiple interpolation cycles, which effectively utilizes the CPU's calculation time and improves the system's working efficiency. 3.4 Interface Implementation Technology The interface of the measurement and control software not only has the functions of general Windows controls, but also must have controls that simulate some physical objects, such as: meter display, knobs, etc. Therefore, LabWindows/CVI tools are used to design the system interface. It is very convenient to design the interface in C language when using LabWindows/CVI. The interface designed for this tool includes header files (*.h) and interface files (*.uir). The *.h files provide callback functions for the interface controls. Applications can implement the required functions within these callback functions. In this system, the display/panel operation thread serves as the callback function for the interface's timer controls. Windows calls the callback functions of the timer controls periodically according to the timer settings. 4. Conclusion In summary, this CNC system software adopts a control strategy combining Windows' multi-threaded model and interrupt mechanism, along with a hierarchical architecture. Utilizing object-oriented technology, multi-buffer technology, and interface implementation technology, it successfully achieves the real-time multi-task control requirements of the CNC system in the Windows environment, effectively realizing the software's extensibility, polymorphism, and reconfigurability, and making the software easy to modify. This design method has been applied to our developed CNC software and has achieved good results. References: 1. Huang Taigui. Microcomputer CNC System. University of Electronic Science and Technology of China Press, 1995. 2. (US) Gate Vima 5.0 Development and User Manual. Mechanical Industry Press, 1998. 3. Wang Hao. Advanced Windows Programming Technology. Tongji University Press, 1997; Wang Yan. Object-Oriented Theory and C++ Practice, Tsinghua University Press, 1995.
Read next

CATDOLL 132CM Wendy(TPE Body with Hard Silicone Head)

Height: 132cm Weight: 28kg Shoulder Width: 36cm Bust/Waist/Hip: 60/58/76cm Oral Depth: 3-5cm Vaginal Depth: 3-15cm Anal...

Articles 2026-02-22