The Xon\xoff principle of serial-port handshake protocol Some people may not understand, look at the following example you should be able to understand.
Suppose pc A and PC B communicate via RS232 serial port
A and B are negotiated using the Software Handshake Protocol (DCB.FOUTX = TRUE), defining XonChar \ XoffChar such as XonChar = 1,
XoffChar = 2.
Now, a sends the character 2 to B, and B sends the string "HelloWorld" to a. A can you get the string "HelloWorld"? No, I can't.
After B sends the character 1 to a, a will receive the string "HelloWorld".
Question: is a to B hair xoffchar? or b to a hair XoffChar?
For example, Li Four has a lot of books, now a laptop to Zhang San, Zhang San suddenly to go to the toilet, want to Li four pause a while, so
Zhang San said to John Doe: "Pause." When John Doe heard, he stopped to pass the book to Zhang San.
"Zhang San" is the receiving end of the communication, "John Doe" is the transmitting end of the communication.
The transmission direction of the XoffChar is the receive-to-send
When Zhang San came back from the toilet, he said to John Doe, "I'm back, let's go." So, John Doe to the rest of the book a copy of a copy of the pass to Zhang San
。
In the same way, the transmission direction of the XonChar is also receive-and-send.
Issue: After the sender receives the XoffChar, who has not yet sent the successful characters to be kept.
Answer: Operating system.
The serial port sends the message to use WriteFile (), if is the overlap way, after the sender receives the XoffChar, WriteFile () will return Faile,
GetLastError () = = error_io_pending.
If the non-overlap way, the program will stop at WriteFile (), wait for the send to succeed, and of course, take into account the timeout setting.
The next step is to go deep into the WriteFile overlap principle.