Windows 中的非标准通信波特率

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1870726/
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 13:33:49  来源:igfitidea点击:

Non-standard comport baudrates in windows

windowsserial-port

提问by Matt

Do the windows built in com port drivers support non-standard baudrates? (actually does windows have a built in driver for com1 & 2?)

Windows 内置的 com 端口驱动程序是否支持非标准波特率?(实际上,windows 是否有用于 com1 和 2 的内置驱动程序?)

The reason I ask is I'm having trouble getting a reliable connection to a device that uses the unusual baudrate 5787. The device & PC talk briefly, then seem to loose the dialogue, and then get it again. Once a long message is sent, it gets lost at the other end, a short time later the dialogue is back. This sounds to me like the classic baudrate mismatch. Not quite close enough to be reliable though but close enough that some data gets through.

我问的原因是我无法与使用异常波特率 5787 的设备建立可靠连接。设备和 PC 短暂交谈,然后似乎失去对话,然后又重新获得。一旦发送了一条长消息,它就会在另一端丢失,不久之后对话又回来了。这听起来像经典的波特率不匹配。虽然不够接近可靠,但足够接近某些数据可以通过。

If I use an inexpensive PCI serial board it works without problems. It's only computers that use on board serial I've found don't work properly.

如果我使用便宜的 PCI 串行板,它可以毫无问题地工作。我发现只有使用板载串行的计算机无法正常工作。

回答by Matt

Baudrates in a PC are controlled by a UART and a crystal. The crystal frequency determines what baudrates the serial port can generate. The baudrate is often generated by a divide by 16 counter. The crystal frequency for a standard PC is normally 1.8432 MHz. Dividing that by 16 gives you 115200 which is usually the maximum the com port can do.

PC 中的波特率由 UART 和晶体控制。晶振频率决定了串口可以产生的波特率。波特率通常由除以 16 的计数器生成。标准 PC 的晶振频率通常为 1.8432 MHz。除以 16 得到 115200,这通常是 com 端口可以做的最大值。

Inside the UART is a DLAB register. This further divides the clock. So essentially, to get 5787 baud you're talking about dividing 115200 by 5787 which gives you 19.906687... It's close to 20 you'd load the DLAB register with 20. 115200 / 20 gives you 5760. Therefore you're probably getting 5760 baud out of the PC com port. That's probably enough of a difference to cause the issue that you're seeing.

UART 内部是一个 DLAB 寄存器。这进一步分频时钟。所以基本上,要获得 5787 波特率,您正在谈论将 115200 除以 5787 得到 19.906687……接近 20,您需要使用 20 加载 DLAB 寄存器。115200 / 20 为您提供 5760。因此您可能会得到PC com 端口的波特率为 5760。这可能足以导致您看到的问题。

回答by Rob Pearce

No, the difference from 5760 to 5787 is nowhere near enough to explain any sort of problems. UARTs identify the start of a byte from the leading edge of the start bit, then sample the data in the middle of each bit. This means they are tolerant to errors in Baud rate up to the point where the predicted middle is an edge. That's a half bit error in one full byte, because each byte has a stop bit so there's a re-synchronise event per byte. On half bit in ten bits (8 data, one start, one stop) is 5%. The difference from 5760 to 5787 is only 0.5% so miles inside the safe region.

不,从 5760 到 5787 的差异远不足以解释任何类型的问题。UART 从起始位的前沿识别一个字节的开始,然后在每个位的中间采样数据。这意味着它们可以容忍波特率的错误,直到预测的中间是边缘。这是一个完整字节中的半位错误,因为每个字节都有一个停止位,因此每个字节都有一个重新同步事件。十位中的半位(8 个数据,一个开始,一个停止)是 5%。从 5760 到 5787 的差异只有 0.5%,所以在安全区域内的英里数。