开发者

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 rega开发者_开发百科rds & Thanks in advance Yannay


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.


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()?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜