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
  xml simple reader kucingkembar 2 1,052 Aug-19-2022, 08:51 PM
Last Post: kucingkembar
  Having strange results from an RFID HID card reader - I'm stuck orbisnz 1 1,477 Mar-28-2022, 08:20 AM
Last Post: Larz60+
  Thoughts on interfacing with a QR code reader that outputs keystrokes? wrybread 1 1,468 Oct-08-2021, 03:44 PM
Last Post: bowlofred
  csv.reader(): Limit the number of columns read in Windows Pedroski55 9 5,188 Jan-23-2021, 01:03 AM
Last Post: pjfarley3
  Closing Files - CSV Reader/Writer lummers 2 2,604 May-28-2020, 06:36 AM
Last Post: Knight18
  csv reader kgiles 3 5,338 Nov-05-2019, 09:04 AM
Last Post: perfringo
  G code reader luisfelipepc 2 3,678 Aug-13-2018, 02:56 AM
Last Post: ichabod801
  Python code for gcode reader and representation ralmeida 1 6,243 Jul-31-2018, 09:20 AM
Last Post: DeaD_EyE
  AttributeError: module 'csv' has no attribute 'reader' python1234 2 26,939 Jun-08-2018, 06:13 AM
Last Post: python1234
  PDf reader jorgelameira 2 3,932 Mar-24-2018, 02:02 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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