C language-written interface program

Source: Internet
Author: User

In communication, the standard serial port must have a lot of handshake signal and state information in order to keep the operation safe and reliable. This is because each computer in the communication has a different CPU speed (which causes "wrong frames") and the transmitter sends data faster than the receiver receives (this can cause "overshoot"). To solve this problem, we use a simple handshake signal, that is, the transmitter sends only half a byte (low 4 bits) of data each time, while the other half byte (high 4 bits) is used to transmit information. We can do the following simple coding for the bits of information (4 bits high):

0H: Sending a new half byte of data

1 h: Resend the last transmitted error data

2 h: End of file name

3 h: End of File

This way, each time the transmitter sends a byte, it waits for the receiving machine to send the loopback signal, which is the byte sent by the transmitter. When the transmitter receives the loopback signal, it compares it to the byte just sent, and if the same, sends a new half byte, or resend it. The new data is differentiated from the old data by the bits of information. Here is what I write in the C language Control serial port program. Take a file-sending program as an example, introduce the use of C language to achieve the control of the interface.

Related Article

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.