def main(): """Main Write Tag Function""" # CID and UID to be written CID = 77 UID = 1234567890 try: # Try to open RFID device using default vid:pid (ffff:0035) rfid = RfidHid() except Exception as e: print(e) exit() # Initialize device print('Initializing device...') rfid.init() sleep(2) print('Done!') print('CID:UID to be written: %s:%s' % (CID, UID)) print('Please hold a tag to the reader until you hear two beeps...\n') uid_temp = None while True: payload_response = rfid.read_tag() if payload_response.has_id_data(): uid = payload_response.get_tag_uid() # Avoid processing the same tag (CID/UID) more than once in a row if uid != uid_temp: uid_temp = uid rfid.write_tag_from_cid_and_uid(CID, UID) sleep( 0.1) # you cannot immediately read after a write operation payload_response_w = rfid.read_tag() # Write verification if payload_response_w.get_tag_cid( ) == CID and payload_response_w.get_tag_uid() == UID: print('Write OK!') print('uid: %s' % payload_response_w.get_tag_uid()) print('customer_id: %s' % payload_response.get_tag_cid()) print('CRC Sum: %s' % hex(payload_response.get_crc_sum())) rfid.beep(2) else: print('Write ERROR!') rfid.beep(3) else: uid_temp = None sleep(0.1)
def main(): """Main Read Tag Function""" try: # Try to open RFID device using default vid:pid (ffff:0035) rfid = RfidHid() except Exception as e: print(e) exit() # Initialize device print('Initializing device...') rfid.init() sleep(2) print('Done!') print('Please hold a tag to the reader until you hear a beep...\n') id_temp = None while True: payload_response = rfid.read_tag() if payload_response.has_id_data(): uid = payload_response.get_tag_uid() # Avoid processing the same tag (CID/UID) more than once in a row if uid != id_temp: id_temp = uid print('uid: %s' % uid) print('customer_id: %s' % payload_response.get_tag_cid()) print('CRC Sum: %s' % hex(payload_response.get_crc_sum())) w26 = payload_response.get_tag_w26() if w26: print('W26: facility code = %d, card number = %d' % w26) print('') rfid.beep() else: id_temp = None sleep(0.1)