PySerial API认为com端口在write()期间仍处于打开状态,为什么?

时间:2011-06-01 07:18:58

标签: python serial-port blocking pyserial

我使用PySerial(用于串行通信的Python API)通过蓝牙将AT命令发送到诺基亚手机。

import serial
com = serial.Serial()
com.port = 19
com.timeout = 0 #also tried a timeout value greater than 0.
try:
    com.open()
    # at this point I turn off the phone.
    com.write("AT\r\n")
    print com.readlines()
except SerialException, e:
    print e

在我打开()com之后,我关掉手机。然后,我写(“AT \ r \ n”)。此时,功能块和运行时挂起。

你有解决方案吗?

2 个答案:

答案 0 :(得分:0)

如果超时设置为0,则取消激活超时参数,read()/readlines()将成为阻止呼叫。呼叫者将被阻止,直到设备应答为止。 尝试为串行连接com = serial.Serial(timeout=0.5)设置非零超时值。

如果它仍然挂起,问题应该在蓝牙堆栈中。

答案 1 :(得分:-1)

实际上,你要找的是writeTimeout而不是timeout参数。我知道,迟到的回答,但我仍然需要它,我想我不是唯一一个。