2014-02-24 94 views
3

我陷入了Python包 RPi中的wait_for_edge函數。 我添加了多個事件檢測落下的GPIO的,並且只要回調函數包含不喜歡Raspberry Pi RPi.GPIO錯誤與威脅回調

os.system("mpc pause") 

然後腳本錯誤消息就死機COMAND一切正常:「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() 

它推動連接到端口buttonstop按鈕後崩潰。

+0

這可能聽起來很愚蠢,但嘗試重新啓動Pi。幾次GPIO引腳有這樣的奇怪的錯誤對我來說,重新啓動修復它 – DeadChex

+0

不幸的是,重新啓動沒有幫助。我注意到os命令是在腳本崩潰之前完成的。 – Thorsten

回答

1

超級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) 
+0

哇它的工作。但爲什麼? – Thorsten

+0

我會冒險說GPIO驅動程序本身就是越野車。也許更熟悉Python GPIO驅動程序的人可以肯定地說,但顯然,它在系統和python之間的行爲不正確。我必須爲我的GPIO電池監視器找到某種類型的解決方案,並且我遇到了這個確切的問題。在Google上搜索並看到你的帖子後,我知道這不僅僅是我。所以,不斷嘗試,我(骯髒)像這樣解決它。希望有一天我們會得到一個適當的解決方案。 – Hal