adafruit / Adafruit_CircuitPython_PN532

CircuitPython driver for the PN532 NFC/RFID Breakout and PN532 NFC/RFID Shield
MIT License
91 stars 47 forks source link

SPI read_passive_target timeout #24

Closed tgikal closed 5 years ago

tgikal commented 5 years ago

To address the issue described in https://github.com/adafruit/Adafruit_CircuitPython_PN532/issues/19: Modified the _wait_ready function, by avoiding re-declaring the with statement each iteration of the while loop.

ladyada commented 5 years ago

nice, did you try this on raspi only or also on some circuitpy hardware?

tgikal commented 5 years ago

Unfortunately the only things I have that will run circuitpython are Raspberry Pis.

I'm still pretty new to submitting PRs, so sorry if it looks weird.

ladyada commented 5 years ago

@caternuson wanna review by checking on a samd?

caternuson commented 5 years ago

Thanks. Looks good. I recreated what I think is the original issue by doing this:

>>> pn532.read_passive_target(timeout=5)
bytearray(b'&)3~')
>>> pn532.read_passive_target(timeout=5)
>>>

where for the first read, the card was sitting on the reader, so could be read right away. For the second read, I put the card on the read after ~2 secs, and got nothing. With the updated code, both seem to work:

>>> pn532.read_passive_target(timeout=5)
bytearray(b'&)3~')
>>> pn532.read_passive_target(timeout=5)
bytearray(b'&)3~')
>>> 
tgikal commented 5 years ago

Yes, that's basically how I encountered the error as well, setting the timeout to a long value and trying to scan a tag somewhere after the initial call. Without looking harder into the adafruit_bus_device.spi_device module and possibly one of it's imports, I assume something is being reset in the __exit__ call with makes.