我在python包中遇到了wait_for_edge函数 rpi 。 我添加了多个事件检测,用于下降GPIO,只要回调函数不包含像

的康复一样,一切都很好
 os.system("mpc pause") 
.

然后脚本使用错误消息崩溃:“RunetimeError:错误#5等待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()
.

按下连接到Port ButtonStop的按钮后崩溃。

有帮助吗?

解决方案

super 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)
.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top