Windows 7 中的串口输出缓冲区大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7881061/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 18:20:35  来源:igfitidea点击:

Serial port output buffer size in Windows 7

windowswinapiserial-portserial-communication

提问by dreamlayers

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.

Unix 串口有一个大的输出缓冲区。只要缓冲区中有空间,Write 调用就会立即返回。当没有足够的空间时,阻塞写入会等待缓冲区被清空到某个低级别。

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 SetupCommfunction lets me specify recommended sizes for input and output buffers. However, the output buffer size doesn't seem to change any behaviour, and GetCommPropertiesalways sets the dwCurrentTxQueue field to zero. The only thing SetupComm can do is increasing the size of the input buffer.

在 Windows 7 SP1 中,内置 16550 串行端口的行为就像没有输出缓冲区一样。似乎写块直到数据从端口输出。如果有缓冲区,它甚至比设备管理器中设置的 16 字节还要小(在 COM1 的高级设置中)。该SetupComm功能让我指定推荐的尺寸输入和输出缓冲器。但是,输出缓冲区大小似乎没有改变任何行为,并且GetCommProperties始终将 dwCurrentTxQueue 字段设置为零。SetupComm 唯一能做的就是增加输入缓冲区的大小。

采纳答案by Harry Johnston

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

SetupComm 的文档特别允许设备驱动程序忽略请求的值。

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

最好的办法是使用重叠 I/O 并自己处理缓冲。