Multi-threading technology to solve the application design of real-time performance of open CNC system


The auxiliary threads created in this system can be roughly divided as shown in the following table.

Table thread creation and priority setting

2

4 multi-threaded implementation

In the Windows operating system, multi-threaded implementations need to call a series of API functions, such as CreateThread, ResumeThread, etc., which is cumbersome and error-prone. Using the TThread class in the new generation RAD development tool C++ Builder, you can easily implement multi-threaded programming, especially for the Windows series operating system whose system development language is C. It has unparalleled advantages in other programming languages.

4.1 Thread creation

Although the TThread object is used in C++ Builder to illustrate the concept of thread, the TThread object itself is not complete. You need to create a new subclass under TThread and overload Execute to use the thread object.

In the C++ Builder IDE environment, select the menu File|New, select Thread Object in the New column, press OK, enter the name of the TThread object subclass CoordinateDisplyThread in the pop-up dialog box, and automatically create a TThread subclass of CoordinateDisply. At the same time, a unit named CoordinateDisplyThread is created in the editor.

4.2 Thread implementation

In the code you create, the Execute() function is where the code for the task to be implemented in the thread is located. The CoordinateDisplayThread.h file is included in the original Unit1.cpp code. When used, dynamically create a TCoordinateDisplay object, the specific execution code is the code overloaded by the Execute () method.

Since the functions that need to be executed when the thread added in Execute() is called to call the VCL component, and the VCL objects are not thread-safe, their properties and methods can only be accessed in the main thread, so use the Synchronize() function to coordinate The display function is wrapped. The coordinate display function needs to declare: void_fastcall Function().

The following shows the implementation steps of the coordinate display thread, CoordinateDisplayThread, as an example to illustrate the specific method of thread implementation. The implementation of other threads needs to be modified according to the specific situation.

Add the following statement to the CoordinateDisplayThread::Execute() function in the CoordinateDisplayThread.cpp file to achieve consistency in X, Y, and Z coordinate display function calls.

First, use the switch statement to determine which axis of the uniaxial motion changes its coordinate position:

2

Previous page next page

Smart Night Light

Guangdong Smart Street Lighting Co., Ltd , https://www.fldlight.com

Posted on