Synchronous and asynchronous communication and blocking and non-blocking [original]

Source: Internet
Author: User
I. Hardware-level synchronization and Asynchronization
1. Asynchronous Communication
In asynchronous communication, there are two conventions between the CPU and peripherals:
(1) character format-character encoding format and specification. Each serial character consists of the following four parts:
(1) 1 start position, low level;
(2) 5-8 data bits;
(3) one parity bit;
(4) 1--2 termination bits (Stop bits) are high;
(2) baud rate
The baud rate refers to the number of digits transmitted in binary data per unit of time, measured in BIT/second.
Important symbols and parameters of the transmission speed.
For example, if the data delivery rate is 120 bits/s, the Transmission baud rate is 120.
Note: The transmission speed of asynchronous communication is generally between 50 and 19200.

2. synchronous communication
In asynchronous communication, each character uses the start and end positions as the start and end signs of the character, which takes some time. In order to increase the transmission speed of the data block, we must try to remove these marks, synchronous communication is adopted.
The synchronous communication speed is up to 500. However, its hardware circuit is complicated.

3. Comparison of advantages and disadvantages
1) asynchronous communication is simple, and the clock between the two sides can allow a certain error. Synchronous communication is complex, and the allowable clock error between the two parties is small.
2) communication efficiency: Low asynchronous communication and high synchronous communication.
3) synchronous communication removes the synchronization bit of each byte, which increases the transfer-to-center ratio and improves the transmission efficiency.
4) synchronous communication allows users to transmit meaningless binary data, that is, when there is no information to be transmitted, extra characters are required because there is no gap in synchronous transmission.

2. Software-level synchronization and Asynchronization
1. synchronous communication:
Generally, a single thread is used. Read operations and write operations are in the same thread. Read operations are not performed, while write operations are not performed. In this case, the hardware is in half duplex mode.

2. Asynchronous Communication
Multithreading is generally used. Read operations and write operations are performed in different threads at the same time. When read or write operations are completed, Event Notifications are used, and the hardware is in full duplex mode.
The overlapped structure must be defined for asynchronous serial port operations, and the hevent must be set up by itself. Two overlapped structures must be defined. One is used to read and the other is used for writing, and two events must also be created, put them into overlapped. hevent.
Generally, we write data in the main thread, because we can control the write, and we do not know when the data will arrive during reading, so we need to create a thread to read the data, in this thread, We cyclically use readfile to read the serial port and waitcommevent to detect the line status.

3. Software-level blocking and non-blocking Modes
1. Blocking Mode:
The Block Mode waits until the I/O operation is completed and the control is not handed overProgramGenerally, you can set a timeout structure. If the timeout time is reached, the system returns timeout. You can use multi-threaded technology to process the timeout.

2. Non-Blocking Mode
After I/O operations are performed in non-blocking mode, the system will return immediately, regardless of whether the read/write operation is successful or not, before I/O operations, you can use some asynchronous models (such as the select model in socket communication) to check whether the current status of the communication port is readable or writable.

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.