如何正确删除Beaglebone black中的中断回调

时间:2016-02-25 16:17:41

标签: python segmentation-fault interrupt beagleboneblack gpio

为gpio引脚P9_24添加中断回调,如下所示

   class Birdemke:
        ...
        def __init__(self):
            #initializatioin of variables
            ...
            self.count = 0

        def startReadingValue(self):
            self.count = 0
            Gpio.add_event_detect("P9_24", Gpio.RISING, self.readValueFromSensor, 0)

        def pauseReadingValue(self):
            Gpio.remove_event_detect("P9_24")

        def readValueFromSensor(self):
            self.count += 1
            #reads value from i2c
            ...

这个Birdemke类是从服务器使用瓶子调用的。调用startReadingValue()添加并调用pauseReadingValue()以使程序对上升边缘无响应。当删除事件检测时,有时程序在行self.count += 1给出了AttributeError,未定义计数变量,Gpio.remove_event_detect("P9_24")行的[分段错误错误] [在更改self.count if hasattr(self,'count')之上的添加行之后] 。

0 个答案:

没有答案