小编Dan*_*iel的帖子

Pyserial write() 挂起

我需要使用串行端口与某些设备进行通信。我知道这个设备参数(boudrate 等)。我也知道这个设备会一直等到它收到一个换行符(我不知道 unix 或 windows 类型),然后用 ASCII 发回一些东西。

问题是,当我想写任何东西时,脚本会挂起。没有错误发生,只是以后什么都没有发生。无法打印任何内容,甚至无法关闭端口。

我该如何解决?

它不适用于真正的基本脚本。当然,这不是一个完整的代码,只是一个示例来说明什么不起作用。

可悲的是,我没有找到任何有效的解释或答案。

我正在使用 Ubuntu 16.04

谢谢你的帮助!

import serial

ser = serial.Serial(
port="/dev/NameOfDevice",
baudrate=115200,
bytesize=8,
parity='N',
stopbits=1,
timeout = 0)

ser.open()
print('Port was opened')

ser.write(b'\r\n') #this is a line where it stops working. Different inputs were tried, nothing works.
print('Does it works?')
Run Code Online (Sandbox Code Playgroud)

python pyserial python-3.6 ubuntu-16.04

5
推荐指数
1
解决办法
2559
查看次数

标签 统计

pyserial ×1

python ×1

python-3.6 ×1

ubuntu-16.04 ×1