def _connect(self): Logger.info('Rfid: Search devices...') try: devs = pynfc.list_devices() Logger.info('Rfid: Found %d devices' % len(devs)) if not devs: Logger.error('Rfid: No devices found, will retry later.') return None, None dev = devs[0] Logger.info('Rfid: Device %r using driver %r' % ( dev.device, dev.driver)) nfc = dev.connect(target=False) return dev, nfc except: return None, None
from time import sleep, time import pynfc def print_targets(targets): for target in targets: nai = target.nti.nai print 'atqa:', map(hex, nai.atqa) print 'sak:', nai.sak print 'uid:', ' '.join(map(hex, nai.uid[:nai.uidlen])) dev = pynfc.list_devices()[0] nfc = dev.connect(target=False) # Manual polling. nmt_targets = (nfc.NMT_ISO14443A, nfc.NMT_ISO14443B) while True: print '==== select passive' targets = [] for nmt in nmt_targets: targets.extend( nfc.list_passive_targets(nmt, nfc.NBR_UNDEFINED)) print_targets(targets) ''' # NFC library polling mod_targets = ( pynfc.Modulation(nmt=nfc.NMT_ISO14443A, nbr=nfc.NBR_106), pynfc.Modulation(nmt=nfc.NMT_ISO14443B, nbr=nfc.NBR_106), )
# GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. import pynfc, pycrypto1, py14443a, sys def hex_dump(string): """Dumps data as hexstrings""" return ' '.join(["%0.2X" % ord(x) for x in string]) ### NFC device setup devs = pynfc.list_devices() if not devs: print "No readers found" sys.exit(1) dev = devs[0] # Connect to the reader print "Connect to reader:", nfc = dev.connect(target=False) print bool(nfc) # Set tup the various connection fields print "Easy Framing False:", nfc.configure(nfc.NDO_EASY_FRAMING, False) print "Field Down:", nfc.configure(nfc.NDO_ACTIVATE_FIELD, False) print "CRC False:", nfc.configure(nfc.NDO_HANDLE_CRC, False) print "Parity True:", nfc.configure(nfc.NDO_HANDLE_PARITY, True) print "Field Up:", nfc.configure(nfc.NDO_ACTIVATE_FIELD, True)
# but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. import pynfc, pycrypto1, py14443a, sys def hex_dump(string): """Dumps data as hexstrings""" return ' '.join(["%0.2X" % ord(x) for x in string]) ### NFC device setup devs = pynfc.list_devices() if not devs: print "No readers found" sys.exit(1) dev = devs[0] # Connect to the reader print "Connect to reader:", nfc = dev.connect(target = False) print bool(nfc) # Set tup the various connection fields print "Easy Framing False:", nfc.configure(nfc.NDO_EASY_FRAMING, False) print "Field Down:", nfc.configure(nfc.NDO_ACTIVATE_FIELD, False) print "CRC False:", nfc.configure(nfc.NDO_HANDLE_CRC, False) print "Parity True:", nfc.configure(nfc.NDO_HANDLE_PARITY, True) print "Field Up:", nfc.configure(nfc.NDO_ACTIVATE_FIELD, True)