Concrete realization of VC realize CNC engraving machining process
by:Transon2020-04-27
Program using VisualC++ multithreaded programming to implement the operation on the CNC engraving machine solid and dynamic requirements.
Thread refers to a separate process, is the basic unit of the system resources allocation processor time.
Thread mechanism makes the system with functions of multitasking.
PCNC general execution process for software system: read after processing of NC file & rarr;
Decoding & rarr;
Track interpolation calculation & rarr;
Servo control, so that a basic machine cycle, before the last an NC statement is not running, will continue the cycle.
If the application is only one thread that is the user interface thread, once the program execution simulation, it will monopolize the CPU run forever till the end, could not accept and handle user news and events.
Won't be able to achieve the requirements of real-time and multithreading can solve this problem.
Can be divided into VisualC++ threads in the user interface thread (
UserInterfaceThread)
And the worker thread (
WorkerThread)
。
The characteristics of the user interface thread is a separate message queue, has its own window interface can respond to user input events and news.
Worker threads are used for processing background tasks, only by the function body, do not process the window messages.
After using multithreading, the user interface thread is mainly used to display the current instruction, update the status parameters (
Coordinates X, Y, Z axis, axis feed speed, processing time, etc. )
And accept user input commands.
Will implement the simulation program in a worker thread.
This thread busy work, but the user thread & other
Free & throughout;
Can respond to user input events and news at any time.
Between the user thread and worker thread through the event object Cevent is responsible for communication between threads.
Set up & other;
Pause the simulation & throughout;
And & other
Start the simulation & throughout;
Two buttons, when press & other
Pause the simulation & throughout;
After the program suspend users can observe instructions and the corresponding state;
Press & other;
Start the simulation & throughout;
And then begin to execute breakpoint.
The implementation of specific methods are as follows: in & other;
Pause the simulation & throughout;
Button click event response function in setting the stop events have signal, & other;
Start the simulation & throughout;
Button click event response function of set start events have signal, the working process in the corresponding event if it has any signals in the loop body detection, to perform the corresponding procedures.
Work need to do is to define the two events to stop and start events, creating a worker thread, and establish a worker thread control function of the body.
The program flow is shown in figure 2.
The user interface thread and worker thread state parameter and image buffer first address to pass through a global variable.
User interface thread first establish image buffer, the buffer after the initialization, through global variables will first address buffer and draw the window handle of the image is passed to the work process.
Work process after decoding data into the image data, constantly refresh buffer, call MFC class library of CDC BitBlt (
)
To redraw the screen, forming processing animation process.
When redrawing the screen to join the delay, delay step walk by each instruction from the sum and the corresponding interpolation speed of the decision.
Through proportional delay can more accurately for the actual processing time.
State parameter under the refresh is by the WINDOW of the Timer Timer implementation, to set a time after the WM - issued by the Timer Timer
The TIMER system messages to the user interface thread message queue, by its corresponding message processing function OnTimer to refresh status parameters.
We are here to help you! If you close the chatbox, you will automatically receive a response from us via email. Please be sure to leave your contact details so that we can better assist