Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

hajiman

macrumors newbie
Original poster
Feb 2, 2011
10
0
I was wondering how I would go about finding the size of the receive/transmit buffers the operating system allocates to serial communication. I am using a USB to serial adaptor which mounts to /dev/tty.usbserial. I've run into issues where the OS receive buffer gets overrun and crashes the system. I would like to know just how much room I have to work with or also how the buffer can be increased.

Thanks!
 
It is likely that this is done in the driver, not in the OS. What driver are you using, and can you set it there. A quick googling finds a open-source driver that might work.
 
As far as I know Buffer is a memory used to store data temporarily, when it is moved from one place to another but I will try above link hope this is becomes great assistance for every one.
 
Last edited:
Most modern serial hardware is either 16 or 32 bytes. Software may be a different story... It's been quite a while since I used it...

As far as software, the interface (assuming you don't write directly to the UART) should have a call to get the buffer sizes and to set the buffer sizes.

I don't know if this link is useful or not, but...

http://digital.ni.com/public.nsf/allkb/DF626A27C756AC98862565950055D062
 
Last edited:
Most modern serial hardware is either 16 or 32 bytes. Software may be a different story... It's been quite a while since I used it...

As far as software, the interface (assuming you don't write directly to the UART) should have a call to get the buffer sizes and to set the buffer sizes.

I don't know if this link is useful or not, but...

http://digital.ni.com/public.nsf/allkb/DF626A27C756AC98862565950055D062

My understanding is 16 or 32 bytes is the buffer memory on the actual UART peripheral. The OS generally services the peripheral on a periodic basis or in response to an interrupt (e.g. the UART can be setup to generate an interrupt when its buffer becomes half full). The OS then transfers this data to another (typically larger) buffer where the OS read() function actually reads data from.

My USB-to-Serial adapter uses the prolific driver pointed out earlier by larkost.

> should have a call to get the buffer sizes...

Yes, that is what I would think. Finding these calls is my problem.
 
I don't know that there is an OS buffer since talking to the serial port is a pretty low level function.

The linked pl2303 driver is open source and does appear to implement a buffer in the driver.

Code:
port->RXStats.BufferSize    = kMaxCirBufferSize;
port->RXStats.HighWater     = (port->RXStats.BufferSize << 1) / 3;
port->RXStats.LowWater      = port->RXStats.HighWater >> 1;
	        
port->TXStats.BufferSize    = kMaxCirBufferSize;
port->TXStats.HighWater     = (port->RXStats.BufferSize << 1) / 3;
port->TXStats.LowWater      = port->RXStats.HighWater >> 1;

kMaxCirBufferSize is apparently 4096.

B
 
The linked pl2303 driver is open source and does appear to implement a buffer in the driver.



kMaxCirBufferSize is apparently 4096.

B

Thank you! That is what I was looking for.
It is interesting that the variables imply the buffer is a circular buffer which to me means if it is not serviced promptly the data is simply lost (or if poorly implemented, overridden). However, if I don't read from the serial buffer promptly the whole system hangs up every single time.

Just to answer some of the other questions, I use command line project in XCode 4 and develop in C. I use the termios.h to access the POSIX calls in the standard c library to the serial port (open, read, write, ...).

Again, thanks much!
 
May I ask why you don't use the driver Prolific provides?

http://www.prolific.com.tw/eng/downloads.asp?id=31

B

Actually, I do use the prolific driver from their website. I misunderstood the earlier link to open source thinking it was the source code for the driver on the prolific website (It listed PL2303...) which is very similar to the driver name on the prolific website PL2303...

...but I will update to the newest version of the driver which I just noticed on their website following your link.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.