I've written a big program which uses multiple serial ports and udp & tcp sockets. Everything works functionally as expected, but the serial port writes block until the data has been sent (reading is fine as I check the number of bytes available before trying to read). I thought the serial port write was supposed to be buffered by the OS!

I'm using an embedded linux machine, and a win32 machine, which both exhibit the same problem. I have to get the writes to be faster (i.e. non-blocking) for linux. Does anyone know how to configure the ports, or something to achieve this??


8 Years
Discussion Span
Last Post by dougy83
Featured Replies
  • 1

    asynchronous write to a file by [ICODE]aio_write[/ICODE] [url]http://www.freebsd.org/cgi/man.cgi?query=aio_write&apropos=0&sektion=2&manpath=FreeBSD+7.0-stable&format=html[/url] is POSIX.1, and should work on linux. Read More


Hi again,

I probably could have been more concise in my previous question; the question I was asking was:

How do you make serial port writes non-blocking in linux?



Thanks Ancient Dragon. I've already tried that as an interim solution, which works, but I wouldn't say it's that great; I was kinda hoping that someone knew some way of forcing the file operations (write in particular) to non-blocking.

It still takes a couple of ms to write ~18 bytes (which is better than original 6-9ms), I'm assuming it's due to me having to use the semaphore which always causes a context switch. And now I have 17 extra threads (one for each port object), but I guess this isn't a problem.


Thanks vijayan121!

aio_write() looks promising. I've compiled the prog with the func (had to link in librt) OK, but I'll have to wait until Monday to test it out. I hope the linux I'm running implements it properly.

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.