0

Adding interrupt callback for gpio pin P9_24 like this

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

this Birdemke class is being called from server using bottle. Calls startReadingValue() to add and calls pauseReadingValue() to make program unresponsive for rising edge. When removing event detect sometimes program is giving AttributeError at line self.count += 1 that count variable is not defined and segmentation fault error at Gpio.remove_event_detect("P9_24") line [after changing adding line on top of self.count if hasattr(self,'count')].

Upol Ryskulova
  • 25
  • 1
  • 10
  • is it possible you just need to initialize `self.count` in the constructor instead of `startReadingLines`? also the `readValueFromSensor` doesn't take an instance argument so `self` would give a `NameError` before an `AttributeError` could happen – Tadhg McDonald-Jensen Feb 25 '16 at 16:40
  • You might want to reword your post into a more specific question – Pseudonym Feb 25 '16 at 17:14
  • hi Tadhg I changed code to correct form, actually I did typing mistake when asked this question. In my source code it was the way you said. Thanks. – Upol Ryskulova Feb 26 '16 at 08:05
  • hi Pseudonym I did not want to post so many lines of code here. If you advice way of solution I can try it and tell you back about result.Thanks – Upol Ryskulova Feb 26 '16 at 08:09

0 Answers0