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.