为什么 PySerial 脚本使用 115200 波特而不是 19200 波特?

Why does PySerial script work with 115200 baud and not 19200 baud?

我有一个 Arduino 程序 运行 将串口波特率设置为 19200。我想使用 PySerial 库提取串口数据。然而,PySerial 似乎只在波特率为 115200 时才工作。

这是我的 Arduino setup() 的样子:

void setup() {
  // put your setup code here, to run once:
  Serial.begin(19200);
  XBee.begin(19200);// was 9600
}

这是设置为 19200 时 PySerial 代码的样子:

with serial.Serial('COM19', 19200) as ser:
    x = ser.read(8)          # 6 works for reading in 2 variables
    print(x)

输出:

b'\xf3\xea\xf6\xea\xea\xf8'

b'\xf8\xf6\xf3\xfc\xfc\xfc'

这是设置为 115200 时 PySerial 代码的样子:

with serial.Serial('COM19', 115200) as ser:
    x = ser.read(8)          # 6 works for reading in 2 variables
    print(x)

输出:

b'70\r\n72'

b'72\r\n70'

有谁知道为什么它只适用于 115200 而不是 19200?或者我可以做些什么来将该数据类型转换为十进制数?

谢谢

波特率取决于设备。它实质上决定了设备之间的数据速率。您需要查看 XBee 型号的数据表以确定兼容的波特率。通常,9600 和 115200 是常用的,因为非标准波特率的使用因产品而异。