我正在写一个代码,用来发送订单给一个avr。我发送了几个信息,但在每次写入之间,我必须等待一个答案(我必须等待机器人到达坐标系上的一个点)。当我在文档中阅读时,readline()
至少应该一直阅读到超时,但是只要我发送第一个坐标,readline()就会自动返回:
SerialException: device reports readiness to read but returned no data (device disconnected?)
当我把一个sleep()
放在write()
循环中的每个for
之间时,一切正常。我试图使用inWaiting()
,但仍然不起作用。下面是我使用它的一个例子:
for i in chemin_python:
self.serieInstance.ecrire("goto\n" + str(float(i.x)) + '\n' + str(float(-i.y)) + '\n')
while self.serieInstance.inWaiting():
pass
lu = self.serieInstance.readline()
lu = lu.split("\r\n")[0]
reponse = self.serieInstance.file_attente.get(lu)
if reponse != "FIN_GOTO":
log.logger.debug("Erreur asservissement (goto) : " + reponse)
此方法允许您分别控制收集每行所有数据的超时,以及等待其他行的不同超时。
这里有一个snipet如何在python中使用serial
相关问题 更多 >
编程相关推荐