#!/usr/bin/python3 # Programme qui interroge le module SL031 # toutes les 0.5 s et affiche l'UID de # l'éventuel badge présent (une seule fois par présentation). import serial import array import time import binascii def clear_input(ser): while ser.inWaiting()>0: ser.read() cards = [ "b'568a836a'" ] # Ouvrir le port ser = serial.Serial(port="com1", baudrate=9600) clear_input(ser) tag_found = False while True: # Selectionner la carte Mifare ser.write(bytes.fromhex('BA0201B9')) # Réponse if ser.read()==b'\xbd': rep = ser.read(ser.read()[0]) # Lire la fin de la réponse if rep[0]==1 and rep[1]==0 and tag_found==False : print("UID="+str(binascii.hexlify(rep[2:6]))) uid = str(binascii.hexlify(rep[2:6])) tag_found = True if uid in cards: print ('accès autorisé') else: print ('accès non autorisé') elif rep[1]==1 : # No tag tag_found = False clear_input(ser) time.sleep(0.5) ser.close()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question