Skip to content

spi.py OSError (9) Bad File Descriptor #16

@kbknapp

Description

@kbknapp

I have a function that is called when the navigation rocker is pushed to the right:

    def update_display(self, line):
        print('Updating display')
        lcd = self.__cad.lcd
        lcd.home()
        lcd.set_cursor(0, 1)
        lcd.write(' ' * pifacecad.lcd.LCD_WIDTH)
        lcd.set_cursor(0, 1)
        print('Writing {}'.format(line))
        lcd.write(line)

The switch event listener is set up like so:

# ROCKER_RIGHT = 7
listener = pifacecad.SwitchEventListener(chip=cad)
listener.register(ROCKER_RIGHT, pifacecad.IODIR_ON, platypi.next_option)
listener.activate()

On the fifth (5th) time I press the rocker right I ALWAYS get the following error:

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python3.4/threading.py", line 921, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.4/threading.py", line 869, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/lib/python3.4/site-packages/pifacecommon/interrupts.py", line 339, in handle_events
    function(event)
  File "platypi.py", line 58, in next_option
    self.update_display(os.path.basename(self.__options[self.__index]))
  File "platypi.py", line 78, in update_display
    lcd.home()
  File "/usr/lib/python3.4/site-packages/pifacecad/lcd.py", line 251, in home
    self.send_command(LCD_RETURNHOME)  # set cursor position to zero
  File "/usr/lib/python3.4/site-packages/pifacecad/lcd.py", line 411, in send_command
    self.control_port.register_select_pin.value = 0
  File "/usr/lib/python3.4/site-packages/pifacecommon/mcp23s17.py", line 358, in value
    self.chip.write_bit(v, self.bit_num, self.address)
  File "/usr/lib/python3.4/site-packages/pifacecommon/mcp23s17.py", line 201, in write_bit
    old_byte = self.read(address)
  File "/usr/lib/python3.4/site-packages/pifacecommon/mcp23s17.py", line 143, in read
    return self._pyver_read(address)
  File "/usr/lib/python3.4/site-packages/pifacecommon/mcp23s17.py", line 147, in _py3read
    op, addr, data = self.spisend(bytes((ctrl_byte, address, 0)))
  File "/usr/lib/python3.4/site-packages/pifacecommon/spi.py", line 74, in spisend
    ioctl(self.fd, SPI_IOC_MESSAGE(1), transfer)
OSError: [Errno 9] Bad file descriptor

Just for curiosity sake, I added a print(self.fd) in spi.py which prints "4"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions