def read_uid(self): PN532_HSU = Pn532Hsu( Pn532Hsu.RPI_MINI_UART ) #Creo interfaz. El argumento indica el puerto serial al que esta conectado el PN532 lector = Pn532( PN532_HSU ) #Creo el objeto encargado de interpretar la información recibida lector.begin() if ( not lector.getFirmwareVersion() ): #Este método se usa exclusivamente para verificar si la RPI detecta el dispositivo print( "ERROR. Compruebe la conexión del dispositivo a la RPI. Vuelva a intentarlo" ) # Solo entra en esta condición si no se reconoce PN532 sys.exit() leido, uid = lector.readPassiveTargetID( pn532.PN532_MIFARE_ISO14443A_106KBPS) while (not leido): leido, uid = lector.readPassiveTargetID( pn532.PN532_MIFARE_ISO14443A_106KBPS) uid = binascii.hexlify(uid).decode('utf-8').upper() return uid
def read_uid(self): PN532_HSU = Pn532Hsu(Pn532Hsu.RPI_MINI_UART) nfc = Pn532(PN532_HSU) nfc.begin() nfc.SAMConfig() print("Esperando tarjeta...") success, uid = nfc.readPassiveTargetID( pn532.PN532_MIFARE_ISO14443A_106KBPS) while (not success): success, uid = nfc.readPassiveTargetID( pn532.PN532_MIFARE_ISO14443A_106KBPS) id = uid.hex() print("Detectado\nUID en hexadecimal: ") return id
from pn532pi import Pn532 from pn532pi import Pn532I2c from pn532pi import Pn532Spi from pn532pi import Pn532Hsu # Set the desired interface to True SPI = False I2C = False HSU = True if SPI: PN532_SPI = Pn532Spi(Pn532Spi.SS0_GPIO8) nfc = Pn532(PN532_SPI) elif HSU: PN532_HSU = Pn532Hsu(0) nfc = Pn532(PN532_HSU) elif I2C: PN532_I2C = Pn532I2c(1) nfc = Pn532(PN532_I2C) _prevIDm = bytearray(b'\x00' * 8) _prevTime = 0 def millis(): return int(round(time.time() * 1000)) def setup():
from pn532pi import Pn532, pn532 from pn532pi import Pn532Hsu from pn532pi import Pn532I2c from pn532pi import Pn532Spi SPI = False I2C = False HSU = True if SPI: PN532_SPI = Pn532Spi(Pn532Spi.SS0_GPIO8) nfc = Pn532(PN532_SPI) # When the number after #elif set as 1, it will be switch to HSU Mode elif HSU: PN532_HSU = Pn532Hsu(Pn532Hsu.RPI_MINI_UART) nfc = Pn532(PN532_HSU) # When the number after #if & #elif set as 0, it will be switch to I2C Mode elif I2C: PN532_I2C = Pn532I2c(1) nfc = Pn532(PN532_I2C) # We can encode many different kinds of pointers to the card, # from a URL, to an Email address, to a phone number, and many more # check the library header .h file to see the large # of supported # prefixes! # For a http:#www. url: url = "google.com" ndefprefix = pn532.NDEF_URIPREFIX_HTTP_WWWDOT
from pn532pi import Pn532, pn532 from pn532pi import Pn532I2c from pn532pi import Pn532Spi from pn532pi import Pn532Hsu # Set the desired interface to True SPI = False I2C = False HSU = True if SPI: PN532_SPI = Pn532Spi(Pn532Spi.SS0_GPIO8) nfc = Pn532(PN532_SPI) # When the number after #elif set as 1, it will be switch to HSU Mode elif HSU: PN532_HSU = Pn532Hsu('/dev/ttyUSB0') nfc = Pn532(PN532_HSU) # When the number after #if & #elif set as 0, it will be switch to I2C Mode elif I2C: PN532_I2C = Pn532I2c(1) nfc = Pn532(PN532_I2C) def setup(): nfc.begin() versiondata = nfc.getFirmwareVersion() if (not versiondata): print("Didn't find PN53x board") raise RuntimeError("Didn't find PN53x board") # halt