Today, debugging an MFC network program, the bug bothered the day, and finally resolved before the end of the call.
In general, we need to use the host computer to remotely control the machine car ahead. The keyboard key response of the MFC app on the PC is as follows: When the button is pressed, the system sends a message to the app, and when the button is lifted, another message is sent to the app. Our project is the use of keyboard keys, when the "up" arrow key, the host computer through the socket to the industrial computer to send a forward command, when the "upward" direction key, the upper computer through the socket to the industrial computer to send a forward stop command. As a result, when we quickly "press and lift" the up button, the robot is still moving forward, need to press the forward button again to continue to control, this is a very serious bug. At first, we thought there was a problem with the message response mechanism of Windows, and it was not allowed to press and hold the button quickly, otherwise it might ignore the raised message or treat the raised message as a pressed message. Later found that this is not the problem, the speed of the person's hands at a faster pace will not affect the Windows message processing, CPU execution speed is fast. Finally, it is found that the problem is here, because the message response function is pressed and lifted inside there are network send function send (these two send belong to the same socket). When pressed and lifted too fast, these two send functions may be problematic or cause problems with the receive function on the receiving end, so we have added a half-second delay before the send call in the "lifted" message response function to resolve the error.