我需要使用pyqtgraph库实时绘制来自xbee的数据。我试过一些例子中的代码,但它要么从示例中绘制随机数据,要么从xbee接收数据,因为我不能使用单个循环来做这两件事,如果我试图将数据从xbee绘制到pyqtgraph它给了我一个错误。继承了没有pyqtgraph实现的代码
import serial
import time
from xbee import ZigBee
serial_port = serial.Serial('/dev/ttyUSB0', 9600)
def print_data(data):
strDatos = data['rf_data']
tempData = strToList(strDatos)
phInc = tempData[0].strip()
tInc = tempData[1].strip()
print "pH: ", phInc, " Temperatura: ", tInc, " Hora: ", time.strftime("%H:%M:%S"), " Fecha: ", time.strftime("%d/%m")
def strToList(strLista):
strLista = strLista.split()
return strLista
zigbee = ZigBee(serial_port, escaped=True, callback = print_data)
while True:
try:
time.sleep(0.001)
except KeyboardInterrupt:
break
zigbee.halt();
serial_port.close()