For UART communication on Raspberry Pi one can write a program in Python with the pyserial package or a program in C. Pyserial requires Threading for non-blocking UART, while C libraries allow to use a single core CPU. Thus for Raspberry pi Zero only C program can achieve the non-blocking UART. Is this correct?
Asked
Active
Viewed 770 times
2 Answers
5
This is not correct. Even single core CPUs are capable of running multiple processes giving them short time window to run and then switching to next process. Also both Python and C programs are capable of using the same services from system so you can achieve the same from both.
Mariusz Zieliński
- 386
- 2
- 8
-
1"Also both Python and C programs are capable of using the same services from system so you can achieve the same from both." -> This is not exactly true; there are some restrictions on python due to its nature, e.g., to do with threading. – goldilocks Jan 11 '19 at 16:09
1
You can easily implement non-blocking UART in Python without threads using in_waiting:
in_waiting
Getter: Get the number of bytes in the input buffer
Just don't read more bytes than in_waiting tells you are available, and your code will never block.
Dmitry Grigoryev
- 27,928
- 6
- 53
- 144