Implementation of Open CNC Control System Based on Windows Multi-thread

<

Implementation of Computer Application Based on Windows Multi-threaded Open CNC Control System Zhang Zheng, Ma Shugen, Cao Binggang (Department of Mechanical and Electrical Engineering, School of Mechanical and Electrical Engineering, Xi'an Jiaotong University, Xi'an 710049, China) How to use multi-threading mechanism to realize multi-task of CNC system and multi-task Coordination and synchronization issues. At the same time, the serial communication problem between the upper computer (Windows) and the lower computer (DOS) of the CNC machine tool is also discussed. The main control system has been used in the transformation experiment of a CNC machine tool and achieved good results.

1 Introduction In the existing CNC system, most systems are based on DOS environment, and its comprehensive performance is weaker than Windows environment, especially interface, human-computer interaction capability, multi-tasking and openness. Therefore, the development of the main control system based on this paper is based on an open CNC machine tool architecture CNC software architecture. The architecture (shown) was proposed to address the deficiencies of closed systems. Under this structure, the process software runs on a Host-PC, and the generated device motion information is transmitted from the serial port to the complete digital machine tool.

The control software of the main control system was compiled with VC++, and the experimental results were verified, and satisfactory results were obtained. The main control system can support the machining of gears and complex surfaces, which greatly simplifies the preparation of process software.

0, Zhang Zheng (972-) male, Shaanxi Sanyuan, Ph.D. student, the main research direction of CNC technology, robot remote control. The measurement data of the L. piece is compared. The system error cMliShM in the process of processing is called to process the ei new number tf. The latest number of bookmark4 uses VC++ to develop the Windows-based open CNC main control system interface. For example, the main functions of the system: assembly of automatic processing files; manual editing of automatic processing files; machine position adjustment; machine tool origin setting; offline simulation path; online real-time simulation of the path; digital machine status display.

2 multi-threading technology in the main control system Each Windows application is a process, and the thread is responsible for executing the code contained in the process address space. In fact, a single process can have multiple threads that execute code "simultaneously" in the process's address space. The operating system allocates CPU time slices for each individual thread in a round-robin fashion, objectively making all threads nearly simultaneously.

At the same time, the system decides which thread to call and how long to schedule based on the priority of all active threads. The system assigns a priority to each thread, from the lowest 0 to the highest 31. Regardless of what the low-level thread is doing, the high-level thread will always preempt the low-level thread.

2.1 Thread Priority Setting The priority of a thread in Windows is determined by the process it is in and its priority relative to that process. When a thread is created, its priority is the priority class of the process in which it is located. For example, the initial priority of a process's main thread of a REALTIME-PRIORITY-CIASS is 24. However, the thread priority can be changed by setting the thread's priority relative to the process.

This way, several threads in an application can be set to different priorities. For example: used in the upper and lower computer communication thread: in the time display thread, use); / can set the priority of the thread to 16 Table 1 gives the system according to the priority class of the process and the relative priority of the thread The combination of levels determines the basic priority of the thread.

Table 1 shows how the system determines the thread's basic priority thread relative priority process priority class idle normal high real-time 2.2 thread in the main control system of the main control system: display year, month and day and Beijing time. For example, on Monday, January 21, 002, Beijing automatically recorded threads. In the automatic processing, the data received from the lower computer is stored in a text file. This allows you to save complete machining data and record the machining process. After the processing is completed, the processing accuracy can be further improved according to the document and the actual zero.

The trace is drawn on the interface according to the three views, which is beneficial for the operator to grasp the processing progress and the actual processing situation.

Finally verify the correctness of the automatic machining program. This can detect errors and avoid losses.

Serial communication thread. The thread is responsible for sending the automatic processing data or machine tool adjustment data to the lower computer through the serial port, and also reading the machine state data transmitted from the lower computer from the serial port and displaying it on the interface.

The priorities of the various threads described above are listed in the priority of several threads in the master system of Table 2 in Table 2.

Thread display time thread automatic record thread online simulation thread offline simulation thread serial communication thread priority 23 coordination and synchronization between threads In an environment where several threads run in parallel, it is important to synchronize the activities of different threads. Windows mainly provides five kinds of synchronization threads. In this main control system, the critical sections and events are mainly used for thread synchronization.

A critical section is a small piece of code that requires exclusive access to certain shared data prior to execution. The critical section allows only one thread to gain access to a certain data area at a time. By using critical sections, it is ensured that access to the data structure can be coordinated between threads. If a thread has taken ownership of a critical section, other threads that want to gain access will be put to sleep. When a thread that owns ownership gives up ownership, the system only wakes up one thread that is waiting, gives it ownership, and lets other threads continue to sleep. For example, the use of a program segment in an online simulation thread: the use of a program segment in the main thread: the online simulation thread and the main thread can be synchronized to access the global variable strSimuOnlineX.

Events are most often used after a process has been initialized, signaling another thread to complete the rest of the work. The initialization thread starts the initialization after setting the event to a no signal state. When the initialization is complete, the thread sets the event to have a signal state, and the worker thread wakes up to perform the remaining necessary work.

In the main control system, the following events are mainly defined: rote-eventStart is used to indicate that the main thread initialization has been completed, automatic processing starts, and an automatic recording thread can be started. When the event is written to the file, there is a signal. There is a signal to wait for this time in the automatic recording thread. When the main thread starts automatic processing, and the first set of data is sent to the lower machine, the statement can be used to start the automatic recording thread to start recording. Due to space limitations, the specific application of other events will not be discussed.

3 Serial communication between Windows and DOS 3.1 Hardware basis of serial communication RS-232-C is an interface standard for binary exchange between data terminal equipment (DTE) and data communication equipment (DCE), which can be used to realize the connection between two microcomputers. Direct communication at close range. To achieve two-machine connection, just connect the serial port or parallel port of the two microcomputers in a certain way with appropriate cables.

9-pin in the main control system, the 9-pin three-wire connection is used.

RS-232-C is only an interface standard for serial communication between computers, and its electrical characteristics are implemented by a device called a Universal Asynchronous Receiver/Transmitter (UART) in a computer.

DOS serial communication DOS and BIOS provide function calls that support serial asynchronous communication. These function calls can be used to design a simple serial asynchronous communication program. The interrupt control mode is the most received/transmit control method for serial communication. In the DOS environment in which the lower PC runs, an interrupt-based approach is adopted.

Windows serial communication Under Windows, the serial port is used as a system resource and is managed by the device driver. The user cannot directly program the serial port hardware port as in DOS. Windows regards the serial port and other communication devices such as modems and fax machines as files in a unified manner. The operation and operation of opening, closing, reading and writing of the serial port are also required due to the combination of Windows thread programming, event-driven and other new technologies. Therefore, the serial communication programming under Windows is complicated.

The serial communication session starts by opening the serial port by calling CreateFileC) function, then setting the serial port baud rate, data bit, parity bit, stop bit and other parameters and timeout parameters, and finally selecting a working mode to read and write serial. mouth. In Windows, serial communication is both polling and event-driven.

Queries are the most straightforward and easy to understand technology. However, the query takes up a lot of CPU time and is inefficient. The event-driven I/O mode refers to the fact that a thread performs I/O operations by monitoring a group of events in a communication resource. This method is similar to the interrupt operation mode under DOS, and is highly efficient. The event-driven communication method is used in the main control system. In the main control system, a CSerialPort class is established to implement initialization and read and write operations of the serial port.

3.4 Windows and DOS serial communication The serial communication between the two operating systems is not difficult, as long as the correct hardware connection is established between the two, and then the respective communication programs are written separately, and according to the same communication protocol settings, Can communicate. This is the communication implementation of the host computer and the lower computer of the main control system, and the communication rate reaches 4 conclusions. The practicability of the main control system has been verified by experiments and achieved good results.

(Finish)

CNC Aluminium Products

Aluminum Profile,Aluminum Extrusion Cnc,Aluminum Machined Parts,Cnc Aluminum Profile

Guangyuan Aluminum , https://www.guangyuan-alum.com