From: Bernhard Kuemel on 30 May 2010 11:01 Hi clc! Can I write(2) much data (512K) to /dev/ttyS0 on Linux without blocking? I want to be able to abort/flush the write if the microcontroller which receives the data reports an error [2]. At first I planned to write byte wise, but select_tut recommends against this [1] ... although at 115200 bps this might be acceptable. Actually, I don't care if the program completes in 47s or 53s and uses a little more or less user/system time. But I wouldn't want all 512K be transmitted if an error occurs somewhere in the middle although I have tried to prevent any harm if it still happened. If I write byte wise, how long could write() block once the buffer filled up? Until a character has been transmitted, or is there a hysteresis? Also I could try to abort/flush the write if a signal handler receives the error. I would, however, like to keep the program simple, for the moment. Would these issues be different on other Unices? Thanks, Bernhard [1] 6. Never read/write only in single bytes at a time unless you are really sure that you have a small amount of data to process. It is extremely inefficient not to read/write as much data as you can buffer each time. The buffers in the example below are 1024 bytes although they could easily be made larger. [2] The microcontroller receives the data and programs it into a BIOS flash rom chip. If an error occurs during a write it will report that by sending an error code through the serial connection.
From: Rainer Weikusat on 30 May 2010 11:28 Bernhard Kuemel <bernhard(a)bksys.at> writes: > Can I write(2) much data (512K) to /dev/ttyS0 on Linux without blocking? > I want to be able to abort/flush the write if the microcontroller which > receives the data reports an error [2]. The simple way to do this is to let someone else block, eg fork a process for the write and kill that upon receiving an error from the microcontroller. That's not maximally efficient, but you wrote that you wouldn't care about that, but easy to implement and reliable (it is always possible to forcibly terminate a process).
From: Scott Lurndal on 30 May 2010 17:55 Rainer Weikusat <rweikusat(a)mssgmbh.com> writes: >Bernhard Kuemel <bernhard(a)bksys.at> writes: >> Can I write(2) much data (512K) to /dev/ttyS0 on Linux without blocking? >> I want to be able to abort/flush the write if the microcontroller which >> receives the data reports an error [2]. > >The simple way to do this is to let someone else block, eg fork a >process for the write and kill that upon receiving an error from the >microcontroller. That's not maximally efficient, but you wrote that >you wouldn't care about that, but easy to implement and reliable (it >is always possible to forcibly terminate a process). Actually, I've used flavors of Unix where it _isn't_ possible to forcibly terminate a process - usually processes writing to a serial or parallel port where the driver uses uninterruptable blocking; only a reboot (or repair of the condition causing the blockage) would terminate the process. That said, there are very few uninterruptable waits left in linux. As for the OP, whether you write one byte or 512k bytes, the write may block (for example, if you've conditioned the serial port to use hardware (RTS/CTS) flow control, or DSR drops). scott
From: Lew Pitcher on 30 May 2010 18:40 Warning: Lew Pitcher, who posts to this newsgroup, is a domain thief. Read the full story at http://www.lewpitcher.ca
From: Bernhard Kuemel on 30 May 2010 19:10 Rainer Weikusat wrote: > Bernhard Kuemel <bernhard(a)bksys.at> writes: >> Can I write(2) much data (512K) to /dev/ttyS0 on Linux without blocking? >> I want to be able to abort/flush the write if the microcontroller which >> receives the data reports an error [2]. > > The simple way to do this is to let someone else block, eg fork a Ok. Out of curiosity ... what's the way to use nonblocking writes? select_tut(2) recommends not to write single bytes at a time. So I try to write 512K. Doesn't work, because the transmit queue only fits 8K (or whatever) and I get EAGAIN. select(2) says the write will not block, but it still won't work, because the queue is still only 8K. So either by trial and error or by finding out (how?) how big the queue is, I write 8K. After one byte is sent, select tells me I can write again, but writing 8K fails because there is only 1 byte free in the queue. So I either keep busy trying to write 8K until the queue is empty or I write only 1 byte each time. Doesn't sound so great. These are only assumptions of which some may be wrong. Bernhard
|
Next
|
Last
Pages: 1 2 3 Prev: Our customer websites are modern, fresh and accessible. Next: We are here for all your events! |