带有威胁回调的 Raspberry Pi RPi.GPIO 错误 [英] Raspberry Pi RPi.GPIO error with threated callback

查看:32
本文介绍了带有威胁回调的 Raspberry Pi RPi.GPIO 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm getting stuck with the wait_for_edge function in the Python package RPi. I added multiple event detections for falling gpio's and everything works fine as long as the callback functions contain not a comand like

 os.system("mpc pause") 

然后脚本崩溃并显示错误消息:RunetimeError: Error #5 waiting for edge"有谁知道,这个错误信息想说什么?或者我可以在哪里查找此类内容?

Then the script crashes with the error message: "RunetimeError: Error #5 waiting for edge" Does anybody know, what this error message wants to say? Or where I can look up things like this?

具体来说,此代码有效:

To be specific this code works:

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 的按钮后它崩溃了.

It crashes after pushing the button connected to the port buttonstop.

推荐答案

超级 hacky,但是在 os.system 调用之后,如果您解除绑定事件然后立即重新绑定,它似乎可以工作.

Super hacky, but right after the os.system call, if you unbind the event and then rebind it right after, it seems to work.

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)

这篇关于带有威胁回调的 Raspberry Pi RPi.GPIO 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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