【发布时间】:2009-07-07 17:16:43
【问题描述】:
我有一个连接到我的计算机的 Arduino,它运行一个循环,每 100 毫秒通过串行端口将一个值发送回计算机。
我想制作一个 Python 脚本,每隔几秒钟从串口读取一次,所以我希望它只看到从 Arduino 发送的最后一个东西。
你如何在 Pyserial 中做到这一点?
这是我尝试过的代码,但它不起作用。它按顺序读取行。
import serial
import time
ser = serial.Serial('com4',9600,timeout=1)
while 1:
time.sleep(10)
print ser.readline() #How do I get the most recent line sent from the device?
【问题讨论】:
标签: python serial-port arduino pyserial