Read Tag

Asked by Rafael on 2016-09-16

Hello! As I can do to read different tags at once, without having to restart the program ??

My program is:

import nfc.ndef

def connected(tag):
    print(tag.ndef.message.pretty())

if __name__ == "__main__":
    clf = nfc.ContactlessFrontend("usb:072f:2200")
    print clf
    clf.connect(rdwr={"on-connect": connected})
    clf.close()

THANKSS!!

Question information

Language:
English Edit question
Status:
Solved
For:
nfcpy Edit question
Assignee:
No assignee Edit question
Solved by:
Rafael
Solved:
2016-09-16
Last query:
2016-09-16
Last reply:
2016-09-16

Basically you'll need to loop around clf.connect(). If the connected() function returns True, then clf.connect() will only return when the tag is removed. It returns True unless you press Ctrl-C to send a keyboard interrupt.

import nfc

def connected(tag):
    print(tag)
    if tag.ndef:
        print(tag.ndef.message.pretty())
    return True

clf = nfc.ContactlessFrontend("usb")
while clf.connect(rdwr={"on-connect": connected}):
    print("waiting for tag")
clf.close()

Rafael (hibara94) said : #2

Thank you very much!!