gpt4 book ai didi

python - 带有威胁回调的树莓派 RPi.GPIO 错误

转载 作者:行者123 更新时间:2023-11-28 18:44:37 28 4
gpt4 key购买 nike

我被 Python 包中的 wait_for_edge 函数卡住了 RPi .我为下降的 gpio 添加了多个事件检测,只要回调函数不包含像

 os.system("mpc pause") 

然后脚本崩溃并显示错误消息:“RunetimeError: Error #5 waiting for edge”有谁知道这个错误消息想说什么?或者我在哪里可以找到这样的东西?

具体来说,这段代码有效:

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()

按下连接到端口 buttonstop 的按钮后崩溃。

最佳答案

super hacky,但是在 os.system 调用之后,如果您取消绑定(bind)事件然后立即重新绑定(bind)它,它似乎可以工作。

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)

关于python - 带有威胁回调的树莓派 RPi.GPIO 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22000515/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com