4

Unix serial ports have a large output buffer. Write calls return immediately as long as there's space in the buffer. When there isn't enough space, a blocking write waits until the buffer is emptied to some low level.

In Windows 7 SP1, the built-in 16550 serial port behaves as if there's no output buffer. It seems writes block until the data is output from the port. If there is a buffer, it's even smaller than the 16 bytes set in Device Manager (in Advanced Settings for COM1). The SetupComm function lets me specify recommended sizes for input and output buffers. However, the output buffer size doesn't seem to change any behaviour, and GetCommProperties always sets the dwCurrentTxQueue field to zero. The only thing SetupComm can do is increasing the size of the input buffer.

dreamlayers
  • 173
  • 1
  • 6
  • Machines haven't been equipped with a serial port for a long time. Is this a real port or is it actually an emulator? Look at the driver in Device Manager. – Hans Passant Oct 24 '11 at 19:58
  • 2
    Yes, it's a real serial port on a PC motherboard. That's what I meant by "built in 16550 serial port". 16550 is a type of UART chip that built in ports are typically compatible with. – dreamlayers Oct 25 '11 at 21:08

1 Answers1

1

The documentation for SetupComm specifically permits the device driver to ignore the requested values.

Your best bet is to use overlapped I/O and handle the buffering yourself.

Harry Johnston
  • 35,639
  • 6
  • 68
  • 158
  • The documentation also says "For example, the function can succeed even though the driver does not allocate a buffer, as long as some other portion of the system provides equivalent functionality." I guess that's just an example however, and not a guarantee. Thanks for the overlapped I/O idea. – dreamlayers Oct 25 '11 at 21:05
  • In Windows 7 there is a sequence of mouse clicks on various icons which will display the buffer size of a given Com Port. I can't remember that sequence at this moment. I know I did it once before. I asked about this in SuperUser and got no response. When I asked in this site, a user with reputation of over 41,000 instantly scolded me for it, so I withdrew the question. We have an app which is misbehaving, and this knowledge (i.e., com port buffer size) from Win'7 itself, not our own app, would help us a lot. Thanks if anyone ever picks up this message. – User.1 Feb 07 '13 at 15:19
  • @User.1: there probably isn't any generic way to determine the actual size of the transmit buffer. You would need to look at the documentation (if any) for the specific device driver being used. – Harry Johnston Feb 08 '13 at 03:24