How bytes received on UART device are stored in some serial Linux devices /dev/ttyS? How to read them?

What is the procedure? Should that device file be closed, when new data is arriving?


How are received bytes stored?

From the user space's point of view, they are not stored at all.

How to read them?

If you mean only to read them, simply cat /dev/ttyS... will do. Some more information as to how to deal with serial interfaces can be seen in multitude of answers and comments in this page and in the internet in general withing seconds of searching. Some ideas: serial, screen, minicom, cutecom and similar tools. This question here is rather interesting.

What is the procedure?

Rather straight-forward:

  1. Open device
  2. Wait for data
  3. Close when finished

/dev/ttyS* are character devices, they do not behave as regular files in your file system, and hence you don't need to flush them or close and reopen them to get new information "written" to them. The point of having dev-files is to have a way to communicate between user space and kernel space.

A little bit more detailed, the process is: Data will come to the hardware, the serial interface, as electrical pulses. The hardware will transform the electrical pulses to digital signals and tranfer them to the HAL (Hardware Abstraction Layer)/Kernel driver or controller in charge to govern the hardware. This will be translated to bytes according to baud rate and protocol used and buffered to further process. The kernel will then empty the buffer into the character device, visible from user space as a node in /dev folder.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.