Operating system receive buffer

Discussion in 'Mac Programming' started by hajiman, Jul 7, 2011.

  1. hajiman macrumors newbie

    Joined:
    Feb 2, 2011
    #1
    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!
     
  2. larkost macrumors 6502a

    Joined:
    Oct 13, 2007
    #2
    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.
     
  3. coxhead andy, Jul 8, 2011
    Last edited: Jul 23, 2011

    coxhead andy macrumors newbie

    Joined:
    Jun 21, 2011
    #3
    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.
     
  4. pilotError, Jul 9, 2011
    Last edited: Jul 9, 2011

    pilotError macrumors 68020

    pilotError

    Joined:
    Apr 12, 2006
    Location:
    Long Island
    #4
    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
     
  5. hajiman thread starter macrumors newbie

    Joined:
    Feb 2, 2011
    #5
    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.
     
  6. pilotError macrumors 68020

    pilotError

    Joined:
    Apr 12, 2006
    Location:
    Long Island
    #6
  7. balamw Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #7
    The linked pl2303 driver is open source and does appear to implement a buffer in the driver.

    kMaxCirBufferSize is apparently 4096.

    B
     
  8. hajiman thread starter macrumors newbie

    Joined:
    Feb 2, 2011
    #8
    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!
     
  9. balamw Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
  10. hajiman thread starter macrumors newbie

    Joined:
    Feb 2, 2011
    #10
    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.
     

Share This Page