来自Arduino的PySerial读取线延迟 [英] PySerial delay in reading line from Arduino

查看:87
本文介绍了来自Arduino的PySerial读取线延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用具有基本"DigitalReadSerial"设置的arduino uno,如下所示: http://arduino.cc/en/Tutorial/DigitalReadSerial

I'm using an arduino uno with the basic "DigitalReadSerial" setup as outlined here: http://arduino.cc/en/Tutorial/DigitalReadSerial

如果我使用arduino IDE随附的串行监视器,则它会立即显示按该按钮所做的任何更改.

If i use the serial monitor included with the arduino IDE, it immediately displays any changes from pressing the button.

这是我想要的pyserial,根据按钮是否按下而为0或1.(最终触发计时器)

This is what i want in pyserial, either a 0 or a 1 depending on whether the button is pressed. (to eventually trigger a timer)

只是为了测试它,我把它放在一起,不是最漂亮的,但是它似乎读出了按钮状态,但是有20秒的延迟.

just to test it, i threw this together, not the prettiest, but it seems to read out the pushbutton state, but there is a 20second delay.

    import serial
    ser = serial.Serial()
    ser.setPort("COM2")
    ser.baudrate = 9600
    ser.open()
    while 1==1:
        ser.readline()

有人有什么想法吗?

推荐答案

这似乎是一个缓存/同步问题,类似于影响普通文件系统中文件同步的那些问题.直到现在我的arduino/pyserial都遇到了这个问题?

It seems to be a caching/sync problem, similar to those that affects the file sync in common filesystems. I have suffered that problem with my arduino/pyserial... until now?

http://pyserial.sourceforge.net/pyserial_api.html (如果我输入)我程序中的3个刷新命令:ser.flush(),ser.flushInput()和ser.flushOutput()似乎可以正常工作.

From http://pyserial.sourceforge.net/pyserial_api.html, if I put the 3 flush commands: ser.flush(), ser.flushInput() and ser.flushOutput() in my program, it seems to work as expected.

这篇关于来自Arduino的PySerial读取线延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆