我被 Python 包中的 wait_for_edge 函数困住了RPi http://sourceforge.net/p/raspberry-gpio-python/wiki/Inputs/。
我为 GPIO 下降添加了多个事件检测,只要回调函数不包含类似命令,一切都会正常工作
os.system("mpc pause")
然后脚本崩溃并显示错误消息:“RunetimeError:错误#5等待边缘”
有谁知道这个错误消息想说什么?或者哪里可以查到类似的东西?
具体来说,这段代码有效:
def next(channel):
print "In next"
GPIO.add_event_detect(buttonnext,GP.FALLING,callback=next,bouncetime=200)
os.system("mpc play")
try:
GPIO.wait_for_edge(buttonstop, GP.FALLING)
os.system("mpc stop")
except KeyboardInterrupt:
GPIO.cleanup()
os.system("mpc stop")
GPIO.cleanup()
但这段代码没有:
def next(channel):
print "In next"
os.system("mpc next")
GPIO.add_event_detect(buttonnext,GP.FALLING,callback=next,bouncetime=200)
os.system("mpc play")
try:
GPIO.wait_for_edge(buttonstop, GP.FALLING)
os.system("mpc stop")
except KeyboardInterrupt:
GPIO.cleanup()
os.system("mpc stop")
GPIO.cleanup()
按下连接到端口按钮停止的按钮后,它会崩溃。
超级 hacky,但是在 os.system 调用之后,如果您取消绑定事件然后立即重新绑定它,它似乎可以工作。
def next(channel):
print "In next"
os.system("mpc next")
GPIO.remove_event_detect(buttonnext)
GPIO.add_event_detect(buttonnext,GP.FALLING,callback=next,bouncetime=200)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)