从 Arduino 读取行的 PySerial 延迟 [英] PySerial delay in reading line from Arduino

查看:33
本文介绍了从 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天全站免登陆