HI,

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

Thanks,
-Doug

Recommended Answers

put the writes in another thread.

Jump to Post

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

Jump to Post

All 5 Replies

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,
Doug.

put the writes in another thread.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.