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

How can I make read_passive_target wait indefinitely until a tag becomes available? #43

Open xetum opened 3 years ago

xetum commented 3 years ago

Other libraries have this possibility. I don't see how in this one. Thanks

FoamyGuy commented 3 years ago

You can put it inside of a loop such as in the simpletest example here: https://github.com/adafruit/Adafruit_CircuitPython_PN532/blob/master/examples/pn532_simpletest.py

If if it does not find a card it will just keep retrying until one is in range.

The relavent code in that example is at the bottom:

print("Waiting for RFID/NFC card...")
while True:
    # Check if a card is available to read
    uid = pn532.read_passive_target(timeout=0.5)
    print(".", end="")
    # Try again if no card is available.
    if uid is None:
        continue
    print("Found card with UID:", [hex(i) for i in uid])
xetum commented 3 years ago

Yes I know, I was trying to do it without the polling loop, as with other libraries

El dom., 4 oct. 2020 20:01, foamyguy notifications@github.com escribió:

You can put it inside of a loop such as in the simpletest example here: https://github.com/adafruit/Adafruit_CircuitPython_PN532/blob/master/examples/pn532_simpletest.py

If if it does not find a card it will just keep retrying until one is in range.

The relavent code in that example is at the bottom:

print("Waiting for RFID/NFC card...")while True:

Check if a card is available to read

uid = pn532.read_passive_target(timeout=0.5)
print(".", end="")
# Try again if no card is available.
if uid is None:
    continue
print("Found card with UID:", [hex(i) for i in uid])

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/adafruit/Adafruit_CircuitPython_PN532/issues/43#issuecomment-703292403, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB3DJB6L5J2JY465JWYNZ4DSJCZ7BANCNFSM4SD2SLHA .

FoamyGuy commented 3 years ago

https://github.com/adafruit/Adafruit-PN532/blob/d988fb4a28e54efe4de638883ce00858064ddf5f/Adafruit_PN532.h#L173

In the arduino library there is a comment that mentions using a timeout of 0 will make it wait forever.

Did you try setting timeout=0 in the CircuitPython one? Maybe it will work the same.

xetum commented 3 years ago

Ok, I'll try

El dom., 4 oct. 2020 21:05, foamyguy notifications@github.com escribió:

https://github.com/adafruit/Adafruit-PN532/blob/d988fb4a28e54efe4de638883ce00858064ddf5f/Adafruit_PN532.h#L173

In the arduino library there is a comment that mentions using a timeout of 0 will make it wait forever.

Did you try setting timeout=0 in the CircuitPython one? Maybe it will work the same.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/adafruit/Adafruit_CircuitPython_PN532/issues/43#issuecomment-703300914, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB3DJBZ65AZ76XRA6OYEEGLSJDBQBANCNFSM4SD2SLHA .

xetum commented 3 years ago

No, timeout=0 does polling. I think it could be added to the library, even more so the arduino version does blocking. Regards, Francesc

El dom., 4 oct. 2020 21:12, Francesc Oller Teijon francesc.oller@upc.edu escribió:

Ok, I'll try

El dom., 4 oct. 2020 21:05, foamyguy notifications@github.com escribió:

https://github.com/adafruit/Adafruit-PN532/blob/d988fb4a28e54efe4de638883ce00858064ddf5f/Adafruit_PN532.h#L173

In the arduino library there is a comment that mentions using a timeout of 0 will make it wait forever.

Did you try setting timeout=0 in the CircuitPython one? Maybe it will work the same.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/adafruit/Adafruit_CircuitPython_PN532/issues/43#issuecomment-703300914, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB3DJBZ65AZ76XRA6OYEEGLSJDBQBANCNFSM4SD2SLHA .