Prospects for description: In the movement of the control motor, on the one hand, need from the serial port signal movement for motor rotation, on the other hand the motor movement should be feedback after the completion of a signal to tell PC movement has been completed, can receive next movement signals, if no this feedback signal detection, can cause the loss of sports instruction, therefore, motor motion control algorithm should be: 1. Send the movement instruction; 2. Receive feedback signal; So circulates, until the stop condition,
At present, Step 1, I use the MSCOMM control used in serial communication, send motor specified movement signal: m_mscomm. Put_Output (COleVariant (hexdata));//here will hexdata movement data input serial port, and motor sports
Step 2, from a serial port receives the feedback signal, I use the event handling mechanism, firstly defines the global event: HANDLE hEvent=CreateEvent (NULL, FALSE, FALSE, NULL); When a serial port receives the motor feedback signal, setting events as a signal: SetEvent (hEvent); And wait in the program: WaitForSingleObject (hEvent, INFINITE);
Hence my motor cycle control for: the while (1) { M_mscomm. Put_Output (COleVariant (hexdata));//send the movement instruction The WaitForSingleObject (hEvent, INFINITE);//waits to receive feedback signal }
description: But the reality is not as I imagined, send sports instruction first, and then wait for receiving feedback signal, after receiving and sending movement instruction, so cycle, makes the motor constantly move forward, I would like to ask, how can I modify to achieve such a motor motion control mode,
CodePudding user response:
To create a manual reset event, debugging debugging
CodePudding user response:
First take a look at your command have it sent to the serial port, received treatment etc, is estimated to be a deadlock
CodePudding user response:
The operation of the first to send signals to an array, the first serial signal sent the first running, set the timer, if the timer time haven't received the feedback (XXX), if you receive send the next command
On a serial port to send and receive can refer to this article, http://blog.csdn.net/cvbtvbwu/article/details/24694739