I won't write much in detail, but a memo
For those who want to read NFC in Python
I was in trouble because the ʻon-connectfunction was executed all the time the NFC was in contact. It's not good to putSleep`, and the solution memo that I got by wandering the sea of the net
import nfc
def on_connect(tag):
    print(tag)
def on_release(tag):
    print("[*] released:")
def main():
    try:
        with nfc.ContactlessFrontend('usb') as clf:
            while clf.connect(rdwr={
                'on-connect': on_connect,
                'on-release': on_release,
            }):
                pass
    except IOError:
        print("NFC reader connection Error")
        sys.exit(0)
if __name__ == '__main__':
    main()
This will execute ʻon_connect () only once when the reader and NFC contact, and execute ʻon_release () when they are released.
I saw an infinite number of people who were in trouble if only ʻon-releasewas not executed, or if they didn't entersleep` and kept being called.
I would be happy if I could rescue such a person
Recommended Posts