Assume that computer A and computer B communicate through RS232 serial port
A and B negotiate to use the software handshake protocol (DCB. foutx = true) and define xonchar/xoffchar, for example, xonchar = 1,
Xoffchar = 2.
Now, a sends 2 characters to B, and B sends a string "helloworld" to A. Can a receive the string "helloworld? No.
After B sends character 1 to A, a will receive the string "helloworld ".
Q: Why does a send xoffchar to B? Or does B send xoffchar to?
For example, there are a lot of books in Lisi. Now I have a one-book copy passed to Michael. Michael suddenly wants to go to the toilet and pause for a while.
Zhang San said to Li Si: "Suspend !", When Li Si heard it, he stopped and sent the book to Zhang San.
"Michael" is the receiver of the communication, and "Li Si" is the sender of the communication.
The transmission direction of xoffchar is the receiving end --> the sending end
When Michael Jacob came back from the restroom, he said, "I'm back. Let's start ". Therefore, Li Si passed the rest of the book to Zhang San.
.
Similarly, the xonchar transmission direction is also the receiving end --> the sending end.
Q: Who will keep the characters that have not been successfully sent after the sender receives xoffchar?
A: the operating system.
Writefile () is used for sending information through the serial port. If it is in the overlap mode, after the sender receives xoffchar, writefile () will return faile,
Getlasterror () = error_io_pending.
If it is not in the overlap mode, the program will stop at writefile () and wait until the sending is successful. Of course, the timeout settings must be taken into account.
Next, we will go deep into the overlap principle of writefile.