[IGSTK-Developers] Serial Port Flushing

David Gobbi dgobbi at atamai.com
Thu Jul 28 14:27:28 EDT 2005


Hi Luis,

I'm surprised about your comment that a "flush" is required after 
writing to the serial port, because as far as I know (and I've been 
working with RS232 devices for about 10 years now, including 4 kinds of 
tracking devices and three operating systems) a "write" to the serial 
port is all that is required.  I can't help but be suspicious.

Here is the UNIX doc for the tcsadrain() function (note that there is a 
tcflush() but it clears the buffers instead of writing them):

tcdrain(int fd) waits until all output written to the object referred to 
by fd has been transmitted.

As you can see, it only says that it "waits until the output has been 
transmitted", it does not say "this function call is required before the 
data will be transmitted".   My understanding is that the data 
transmission starts as soon as the write() function is called, and 
proceeds at whatever baud rate has been set.

However, adding a "tcdrain" after every "write" will not hurt anything, 
all it means is that the application (and eventually just the tracking 
thread) will be put to sleep until all characters have been written.

 - David









More information about the IGSTK-Developers mailing list