Serial Communication handshake protocol-Xon/xoff Method

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.