【问题标题】:RS232 transfert, python interprets my data as new line feed and cariage returnRS232 transfert,python 将我的数据解释为换行符和回车符
【发布时间】:2017-08-22 09:53:29
【问题描述】:

我目前正在使用微控制器来设置 ASIC 和我的 PC 之间的通信。 ASIC通过SPI向微控制器发送数据,微控制器通过UART(RS232)向PC发送数据。

我正在使用 python 来“记录”数据(通过 UART 连续发送)。请注意,使用的 python 程序不是由我编写的,而是由我无法联系到的其他人编写的。而且,我对python没有任何经验。

这是我通过 UART 发送数据的示例:(程序正在计数)

255 -> start byte
0 -> 1 bytes of data
0 -> 1 bytes of data
0 -> 1 bytes of data
8 -> 1 bytes of data
0 -> stop byte

255
0
0
0
9
0

255
0
0
0
13 ->This is what I don’t want. I’m sending 10 but that 13 is added by python
10
0
255

255
0
0
0
11
0
...

如上所示,当一个字节的数据为10时,重新编码/添加一个13。根据我读到的关于回车和换行的内容,我猜这个错误与 python 解释我的数据有关。我试过阅读“串行”驱动程序(或我读过的任何东西),但找不到任何东西来禁用这种“我的数据解释”。

你们中有人知道我应该看哪里吗?如果不够清楚,请询问更多细节。

【问题讨论】:

    标签: python serial-port newline carriage-return


    【解决方案1】:

    我通过更改解决了这个问题: OutputFile = open(filename, "w") 到 OutputFile = open(filename, "wb")

    【讨论】:

      猜你喜欢
      • 2020-09-09
      • 1970-01-01
      • 2012-06-17
      • 2023-04-10
      • 1970-01-01
      • 2015-09-28
      • 1970-01-01
      • 1970-01-01
      • 2017-06-28
      相关资源
      最近更新 更多