这个库有问题: https://code.google.com/p/python-xbee/
xbee.wait_read_frame()
函数没有超时。
我正在测试信号的所有串口,但如果我不能尝试,那就没办法了。
Python是否有可能在不编辑库的情况下升级此功能? 或者图书馆内有小变化?
ports_available = []
for port in range(0,20):
try:
ser = serial.Serial(port, 9600)
ports_available.append(port)
ser.close()
except:
pass
print(ports_available)
for port in ports_available:
ser = serial.Serial(port, 9600)
bee = ZigBee(ser)
bee.at(command=b"MY")
print(bee.wait_read_frame()) #<----------
ser.close()
答案 0 :(得分:1)
看起来您需要使用documentation第3页中描述的异步模式。除非数据帧包含接收它的串行端口的参数,否则它可能会很棘手。如果它没有,您将无法将数据连接到接收它的端口。
import serial
import time
from xbee import XBee
serial_port = serial.Serial('/dev/ttyUSB0', 9600)
def print_data(data): """
This method is called whenever data is received
from the associated XBee device. Its first and
only argument is the data contained within the
frame.
"""
print data
xbee = XBee(serial_port, callback=print_data)
while True:
try:
time.sleep(0.001)
except KeyboardInterrupt:
break
xbee.halt()
serial_port.close()