Read Tag

Asked by Rafael

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:
Last query:
Last reply:
Revision history for this message
Stephen Tiedemann (stephen-tiedemann) said :
#1

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()

Revision history for this message
Rafael (hibara94) said :
#2

Thank you very much!!