Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
NFC reader code help
#1
I have the following python code which continuously listens for NFC chip presence and when detected it prints the UID (ident)

from nfc import ContactlessFrontend
from time import sleep

def connected(tag):
    ident = ''.join('{:02x}'.format(ord(c)) for c in tag.identifier)
    print(ident)
    return False

clf = ContactlessFrontend('usb')
while True:
    clf.connect(rdwr={'on-connect': connected})
    sleep(1)
This works well. However, the problem I face is that if a user holds the NFC tag down then the script reads the same "ident" value over and over again. I want to solve this by possibly temporarily storing the value of "ident" so that it doesn't print if the value is the same as last scanned for at least X seconds before it is allowed to re-print the same UID. Is someone able to help me modify the code above to do this please?

Thank you.
Reply
#2
Either ignore a tag if it is the same as the last tag (report tag immediately) or once you identify a tag continue looping until there is no tag, then return the previous tag (report tag when removed). You may have to configure the device to timout instead of wait for a tag. I am not familiar with the nfc library. You'll probably want to decrease your wait. 1 second is a really long time.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Having strange results from an RFID HID card reader - I'm stuck orbisnz 1 380 Mar-28-2022, 08:20 AM
Last Post: Larz60+
  Thoughts on interfacing with a QR code reader that outputs keystrokes? wrybread 1 626 Oct-08-2021, 03:44 PM
Last Post: bowlofred
  csv.reader(): Limit the number of columns read in Windows Pedroski55 9 2,502 Jan-23-2021, 01:03 AM
Last Post: pjfarley3
  Closing Files - CSV Reader/Writer lummers 2 1,493 May-28-2020, 06:36 AM
Last Post: Knight18
  csv reader kgiles 3 3,676 Nov-05-2019, 09:04 AM
Last Post: perfringo
  G code reader luisfelipepc 2 2,718 Aug-13-2018, 02:56 AM
Last Post: ichabod801
  Python code for gcode reader and representation ralmeida 1 4,454 Jul-31-2018, 09:20 AM
Last Post: DeaD_EyE
  AttributeError: module 'csv' has no attribute 'reader' python1234 2 22,950 Jun-08-2018, 06:13 AM
Last Post: python1234
  PDf reader jorgelameira 2 2,911 Mar-24-2018, 02:02 PM
Last Post: Larz60+
  csv.reader vs csv.dictReader mepyyeti 3 16,511 Mar-20-2018, 08:31 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020