Closed nick-hills closed 11 years ago
You need to enable interrupts first when using just pifacecommon. I appreciate that this probably needs better documentation, I did not realise so many people were using it. Also be careful, the function enable_interrupts()
is scheduled to change in the next version of pifacecommon v4.0.0. Make sure you read the change log.
#!/usr/bin/python
import pifacecommon.core
import pifacecommon.interrupts
import os
import time
def print_flag(event):
print ("You pressed button" + event.pin_num)
pifacecommon.core.init()
port = pifacecommon.core.GPIOB
pifacecommon.interrupts.enable_interrupts()
listener = pifacecommon.interrupts.PortEventListener(port)
listener.register(0, pifacecommon.interrupts.IODIR_ON, print_flag)
listener.activate()
Running this stripped down test code, the subject error occurs.
!/usr/bin/python
import pifacecommon.core import pifacecommon.interrupts import os import time
def print_flag(event): print ("You pressed button" + event.pin_num)
pifacecommon.core.init() port = pifacecommon.core.GPIOB listener = pifacecommon.interrupts.PortEventListener(port)
listener.register(0, pifacecommon.interrupts.IODIR_ON, print_flag)
listener.activate()
results in:
Process Process-1: Traceback (most recent call last): File "/usr/lib/python3.2/multiprocessing/process.py", line 267, in _bootstrap self.run() File "/usr/lib/python3.2/multiprocessing/process.py", line 116, in run self._target(_self._args, *_self._kwargs) File "/usr/lib/python3/dist-packages/pifacecommon/interrupts.py", line 207, in watch_port_events gpio25 = open(GPIO_INTERRUPT_DEVICE_VALUE, 'r') # change to use 'with'? IOError: [Errno 2] No such file or directory: '/sys/devices/virtual/gpio/gpio25/value'