Bilgiler > RFID Okuyucu_Kaydedici
RFID Okuyucu_Kaydedici
import mfrc522from os import unameimport timefrom time import sleepstr2=''from machine import Pinbuzzer=Pin(13,Pin.OUT)#__Kullanici var mi kontrol et_______def usercontrol(kartid): file=open("usr.txt","r") for f in file: if f.count(kartid)>0: print('kayitli kullanici') return True break return False ##___tum kayitlari yazdir_________def yazdir(): file1 = open("cay.txt","r") for line in file1: print(line,end='') file1.close()#_____uyari tonu cal_Normaldef ot(): buzzer.value(1) time.sleep(0.1) buzzer.value(0) #_____titrek uyari tonu cal__Hatadef titrekot(): i=10 while i>0: i=i-1 buzzer.value(1) time.sleep(0.02) buzzer.value(0) time.sleep(0.02)#___kac kayit var_______def kayitsayisi(usrid): f=open('cay.txt','r') cnt=0 for line in f: if line.count(usrid)>0: cnt=cnt+1 print(cnt) f.close() return(cnt)#____kaydı dosyaya ekle_______def tofile(data): text_file = open("cay.txt", "a") n = text_file.write(data+'\n') print('{} karakter dosyaya eklendi'.format(n)) text_file.close() return(kayitsayisi(data)) #____RFID kart oku__________def do_read(): if uname()[0] == 'WiPy': rdr = mfrc522.MFRC522("GP14", "GP16", "GP15", "GP22", "GP17") elif uname()[0] == 'esp8266': rdr = mfrc522.MFRC522(0, 2, 4, 5, 14) else: raise RuntimeError("Unsupported platform") print("") print("Place card before reader to read from address 0x08") print("") try: while True: (stat, tag_type) = rdr.request(rdr.REQIDL) if stat == rdr.OK: (stat, raw_uid) = rdr.anticoll() if stat == rdr.OK: print("New card detected") print(" - tag type: 0x%02x" % tag_type) print(" - uid : 0x%02x%02x%02x%02x" % (raw_uid[0], raw_uid[1], raw_uid[2], raw_uid[3])) print("") str2=str(raw_uid[0])+str(raw_uid[1])+str(raw_uid[2])+str(raw_uid[3])+str(raw_uid[4]) return(str2) if rdr.select_tag(raw_uid) == rdr.OK: key = [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF] if rdr.auth(rdr.AUTHENT1A, 8, key, raw_uid) == rdr.OK: print("Address 8 data: %s" % rdr.read(8)) rdr.stop_crypto1() else: print("Authentication error") else: print("Failed to select tag") except KeyboardInterrupt: print("Bye")#_____Ana Program__________while True: msg=do_read() if usercontrol(msg): ot() print(msg) print('Kullanicinin kayit sayisi:{}'.format(tofile(msg))) sleep(0.6) else: print('boyle bir kullanici yok') titrekot() sleep(0.3)
***