1# UART Select Example
2
3(See the README.md file in the upper level 'examples' directory for more information about examples.)
4
5The UART select example is for demonstrating the use of `select()` for
6synchronous I/O multiplexing on the UART interface. The example waits for a
7character from UART using `select()` until a blocking read without delay or a
8successful non-blocking read is possible.
9
10Please note that the same result can be achieved by using `uart_read_bytes()`
11but the use of `select()` allows to use it together with other virtual
12file system (VFS) drivers, e.g. LWIP sockets.
13
14This example can be used to develop applications for non-blocking read and write from/to various sources (UART,
15sockets, ...) where a ready resource can be served without being blocked by a busy resource.
16
17For a more comprehensive example please refer to `system/select`.
18
19## How to use example
20
21### Hardware Required
22
23The example can be run on any ESP32, ESP32-S and ESP32-C series based development board connected to a computer with a single USB cable for communication
24through UART.
25
26### Configure the project
27
28```
29idf.py menuconfig
30```
31
32### Build and Flash
33
34Build the project and flash it to the board, then run monitor tool to view serial output:
35
36```
37idf.py -p PORT flash monitor
38```
39
40(To exit the serial monitor, type ``Ctrl-]``.)
41
42See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.
43
44## Example Output
45
46You can see a similar output after flashing and monitoring the application:
47
48```
49...
50I (276) cpu_start: Pro cpu start user code
51I (294) cpu_start: Starting scheduler on PRO CPU.
52I (0) cpu_start: Starting scheduler on APP CPU.
53I (10295) uart_select_example: Timeout has been reached and nothing has been received
54I (15295) uart_select_example: Timeout has been reached and nothing has been received
55I (20295) uart_select_example: Timeout has been reached and nothing has been received
56```
57
58You can push any key on your keyboard to see the result of a successful detection by `select()` and subsequent
59blocking read (without delay). The following output shows the result of pushing `a` on the keyboard:
60
61```
62...
63I (15295) uart_select_example: Timeout has been reached and nothing has been received
64I (20295) uart_select_example: Timeout has been reached and nothing has been received
65I (20945) uart_select_example: Received: a
66I (25955) uart_select_example: Timeout has been reached and nothing has been received
67...
68```
69