yannay
yannay

Reputation: 41

uart buffer is not read

I am trying to read binary data from a serial device in c on linux. The problem is, that sometimes there are chars in the driver's internal buffer, but polling (with select(2)) returns saying the device is not ready to be read.

I have read and re-read the man of termios and all the related man and searched over the internet. I believe I set all the flags correctly (namely VTIME, VMIN) and unset ICANON. I tried using the function "tcmakeraw", as well, but it didn't solve the problem.

Do you guys have any ideas about what should I do?

Kind regards & Thanks in advance Yannay

Upvotes: 0

Views: 1425

Answers (2)

shodanex
shodanex

Reputation: 15406

You should show us the code. I would start with using cfmakeraw on the serial port. Once you have things working in raw mode, you can make modification and see how it works. Here is a list of question or things you could check :

  • after modifying the attribute, using for example cfmakeraw, do you call tcsetattr(...) to apply your change ?

  • How do you prove there is still data in the driver receive buffer ?

  • do you check your system call for errors ?

  • what is the result of stracing your program ?

Edit based on your comments : Your protocol "guarantee" .... => check your assumption ! Unchecked, crystal clear guarantee are a good coandidate for "impossible error"

Basically : either select is broken, or your serial driver. Reason for serial driver being broken is a hardware fifo not being full enough to trigger un interrupt, or loosing an interrupt.

Upvotes: 1

Jé Queue
Jé Queue

Reputation: 10653

What happens when you read directly (not through C) /dev/ttyS0 (or equiv) after you setserial your parameters. Are you able to get the needed data outside of the select()?

Upvotes: 0

Related Questions