Python PySerial readline函数使用错误

时间:2022-09-06 12:44:54

I'm using a script importing PySerial to read from COM4

我正在使用导入PySerial的脚本从COM4读取

messages I would like to intercept end with a couple of #

我希望截取的消息以几个结尾#

so I tried to use

所以我试着用

bus.readline(eol='##')

where bus is my connection.

巴士是我的连接。

I expected to read like:

我希望读起来像:

  1. *#*3##
  2. *#*3##
  3. *#*3##

Unfortunalyy I found also

不幸的是,我也找到了

  1. *#*1##*1*1*99##

that I expected to read spleetted into 2 lines

我希望读到2行

  1. *#*1##
  2. *1*1*99##

Clearly readline is not working but why?

显然,readline不起作用,但为什么呢?

1 个解决方案

#1


The readline() method in pyserial reads one character at a time and compares it to the EOL character. You cannot specify multiple characters as the EOL. You'll have to read in and then split later using string.split() or re.split()

pyserial中的readline()方法一次读取一个字符并将其与EOL字符进行比较。您不能将多个字符指定为EOL。您必须先读入然后使用string.split()或re.split()进行拆分

#1


The readline() method in pyserial reads one character at a time and compares it to the EOL character. You cannot specify multiple characters as the EOL. You'll have to read in and then split later using string.split() or re.split()

pyserial中的readline()方法一次读取一个字符并将其与EOL字符进行比较。您不能将多个字符指定为EOL。您必须先读入然后使用string.split()或re.split()进行拆分