ACR122U CONNECTION

Asked by Rafael on 2016-09-16

How can I know the status of my ACR122U connection automatically, without restarting the program?

Thanks!!

Question information

Language:
English Edit question
Status:
Solved
For:
nfcpy Edit question
Assignee:
No assignee Edit question
Solved by:
Stephen Tiedemann
Solved:
2016-09-19
Last query:
2016-09-19
Last reply:
2016-09-19

What do mean by connection status? Tag presence? Then there's https://nfcpy.readthedocs.io/en/latest/modules/tag.html#nfc.tag.Tag.is_present.

Rafael (hibara94) said : #2

No, I think you have not understood me. When I plug in or connect my reader ACR122U on my computer, the program shows 'ACR122U connected' and when disconnecting show 'No connected reader'.

Sorry, I do not know very well python.

Thanks!!

The following snippet would continuously look for a reader and print tags when connected.

import nfc
import time

def print_tag(tag):
    print(tag)
    return True

while True:
    try:
        with nfc.ContactlessFrontend("usb") as clf:
            print("reader found, waiting for tags")
            while clf.connect(rdwr={'on-connect': print_tag}):
                pass
    except IOError:
        print("no reader, wait 1 sec")
        try:
            time.sleep(1)
        except KeyboardInterrupt:
            break

Rafael (hibara94) said : #4

Thanks very much!!