2

I'm successfully reading data from my NFC tags with the py532lib, using the i2c connection, put out by Hubcitylabs 5 years ago. https://github.com/HubCityLabs/py532lib/blob/master/py532lib/i2c.py

Unfortunately, after running for about 15 minutes, the system crashes with the error:

OSError: Error 24 Too Many Open Files: '/dev/i2c-1'

Here's the portion of code I have written, that's using the library. Anyone have an idea what I need to add in order to actually close out the files? I've done some reading and it sounds like it's leaving open file descriptors (maybe?).

def nfc_list(self):
    Mifare().set_max_retries(5)
    uid = Mifare().scan_field()
    if uid:
        print(uid)
        """Grab the entire output of the NFC mobule from the I2C channel."""
        self.nfc_read = Pn532_i2c().read_mifare().get_data() #Store it in our variable.
        Pn532_i2c().reset_i2c()
        #print('nfc_read = ' + str(self.nfc_read))
    else:
        self.nfc_read = '' #empty out the array
        Pn532_i2c().reset_i2c()
        #print('no tag found')
    self.bus.close()

This thing has been sitting to the side on my desk for a few months now because I just got tired of getting nowhere with it. Any help is greatly appreciated.

goldilocks
  • 60,325
  • 17
  • 117
  • 234
Bobby Hill
  • 41
  • 5

1 Answers1

3

I had the same problem with the mfrc522 library.

I also tried to close the bus from my own code (like you) but it didn't work out.

So I decided to read the source code and I saw the 'Close' function which closes opened bus (Basically the code was able to close that bus from inside) and then I added that function to the end of the reading function, then everything was working just fine.

So you can try to look for the close function or make your own in the source code of the library.

MatsK
  • 2,882
  • 3
  • 17
  • 22
Lunatogi
  • 31
  • 2