pyupm_pn532 module¶
-
class
pyupm_pn532.
PN532
(*args)[source]¶ Bases:
object
API for the PN532 based NFC/RFID reader/writer.
ID: pn532
Name: NFC/RFID Reader/Writer
Category: rfid
Manufacturer: adafruit
Link:http://www.adafruit.com/products/364
Connection: i2c Identify a card and print out basic infoAdd a URI to an already NDEF formatted ultralight or NTAG2XX tag
C++ includes: pn532.hpp
-
BAUD_MIFARE_ISO14443A
= 0¶
-
CMD_DIAGNOSE
= 0¶
-
CMD_GETFIRMWAREVERSION
= 2¶
-
CMD_GETGENERALSTATUS
= 4¶
-
CMD_INATR
= 80¶
-
CMD_INAUTOPOLL
= 96¶
-
CMD_INCOMMUNICATETHRU
= 66¶
-
CMD_INDATAEXCHANGE
= 64¶
-
CMD_INDESELECT
= 68¶
-
CMD_INJUMPFORDEP
= 86¶
-
CMD_INJUMPFORPSL
= 70¶
-
CMD_INLISTPASSIVETARGET
= 74¶
-
CMD_INPSL
= 78¶
-
CMD_INRELEASE
= 82¶
-
CMD_INSELECT
= 84¶
-
CMD_POWERDOWN
= 22¶
-
CMD_READGPIO
= 12¶
-
CMD_READREGISTER
= 6¶
-
CMD_RFCONFIGURATION
= 50¶
-
CMD_RFREGULATIONTEST
= 88¶
-
CMD_SAMCONFIGURATION
= 20¶
-
CMD_SETPARAMETERS
= 18¶
-
CMD_SETSERIALBAUDRATE
= 16¶
-
CMD_TGGETDATA
= 134¶
-
CMD_TGGETINITIATORCOMMAND
= 136¶
-
CMD_TGGETTARGETSTATUS
= 138¶
-
CMD_TGINITASTARGET
= 140¶
-
CMD_TGRESPONSETOINITIATOR
= 144¶
-
CMD_TGSETDATA
= 142¶
-
CMD_TGSETGENERALBYTES
= 146¶
-
CMD_TGSETMETADATA
= 148¶
-
CMD_WRITEGPIO
= 14¶
-
CMD_WRITEREGISTER
= 8¶
-
MIFARE_CMD_AUTH_A
= 96¶
-
MIFARE_CMD_AUTH_B
= 97¶
-
MIFARE_CMD_DECREMENT
= 192¶
-
MIFARE_CMD_INCREMENT
= 193¶
-
MIFARE_CMD_READ
= 48¶
-
MIFARE_CMD_STORE
= 194¶
-
MIFARE_CMD_TRANSFER
= 176¶
-
MIFARE_CMD_WRITE
= 160¶
-
MIFARE_ULTRALIGHT_CMD_WRITE
= 162¶
-
NDEF_URIPREFIX_BTGOEP
= 26¶
-
NDEF_URIPREFIX_BTL2CAP
= 25¶
-
NDEF_URIPREFIX_BTSPP
= 24¶
-
NDEF_URIPREFIX_DAV
= 14¶
-
NDEF_URIPREFIX_FILE
= 29¶
-
NDEF_URIPREFIX_FTP
= 13¶
-
NDEF_URIPREFIX_FTPS
= 9¶
-
NDEF_URIPREFIX_FTP_ANONAT
= 7¶
-
NDEF_URIPREFIX_FTP_FTPDOT
= 8¶
-
NDEF_URIPREFIX_HTTP
= 3¶
-
NDEF_URIPREFIX_HTTPS
= 4¶
-
NDEF_URIPREFIX_HTTPS_WWWDOT
= 2¶
-
NDEF_URIPREFIX_HTTP_WWWDOT
= 1¶
-
NDEF_URIPREFIX_IMAP
= 17¶
-
NDEF_URIPREFIX_IRDAOBEX
= 28¶
-
NDEF_URIPREFIX_MAILTO
= 6¶
-
NDEF_URIPREFIX_NEWS
= 15¶
-
NDEF_URIPREFIX_NFS
= 12¶
-
NDEF_URIPREFIX_NONE
= 0¶
-
NDEF_URIPREFIX_POP
= 20¶
-
NDEF_URIPREFIX_RTSP
= 18¶
-
NDEF_URIPREFIX_SFTP
= 10¶
-
NDEF_URIPREFIX_SIP
= 21¶
-
NDEF_URIPREFIX_SIPS
= 22¶
-
NDEF_URIPREFIX_SMB
= 11¶
-
NDEF_URIPREFIX_TCPOBEX
= 27¶
-
NDEF_URIPREFIX_TEL
= 5¶
-
NDEF_URIPREFIX_TELNET
= 16¶
-
NDEF_URIPREFIX_TFTP
= 23¶
-
NDEF_URIPREFIX_URN
= 19¶
-
NDEF_URIPREFIX_URN_EPC
= 34¶
-
NDEF_URIPREFIX_URN_EPC_ID
= 30¶
-
NDEF_URIPREFIX_URN_EPC_PAT
= 32¶
-
NDEF_URIPREFIX_URN_EPC_RAW
= 33¶
-
NDEF_URIPREFIX_URN_EPC_TAG
= 31¶
-
NDEF_URIPREFIX_URN_NFC
= 35¶
-
RSP_INDATAEXCHANGE
= 65¶
-
RSP_INLISTPASSIVETARGET
= 75¶
-
SAMConfig
()[source]¶ bool SAMConfig(void)
Configures the SAM (Secure Access Module)
configures the SAM (Secure Access Module)
true if successfully configured
-
TAG_TYPE_MIFARE_CLASSIC
= 1¶
-
TAG_TYPE_NFC2
= 2¶
-
TAG_TYPE_UNKNOWN
= 0¶
-
getATQA
()[source]¶ uint16_t getATQA()
return the ATQA (Answer to Request Acknowledge) value. This value is only valid after a successful call to readPassiveTargetID()
ATQA value
-
getFirmwareVersion
()[source]¶ uint32_t getFirmwareVersion()
Checks the firmware version of the PN5xx chip.
Checks the firmware version of the PN5xx chip
the chip’s firmware version and ID
The chip’s firmware version and ID
-
getSAK
()[source]¶ uint8_t getSAK()
return the SAK (Select Acknowledge) value. This value is only valid after a successful call to readPassiveTargetID()
SAK value
-
i2cContext
()[source]¶ mraa::I2c& i2cContext()
provide public access to the class’s MRAA i2C context for direct user access
a reference to the class i2c context
-
inDataExchange
(send, sendLength, response, responseLength)[source]¶ bool inDataExchange(uint8_t *send, uint8_t sendLength, uint8_t *response, uint8_t *responseLength)
Exchanges an APDU with the currently inlisted peer.
exchanges an APDU (Application Protocol Data Unit) with the currently inlisted peer
send: Pointer to data to send
sendLength: Length of the data to send
response: Pointer to response data
responseLength: Pointer to the response data length
true if everything executed properly, false for an error
send: Pointer to data to send
sendLength: Length of the data to send
response: Pointer to response data
responseLength: Pointer to the response data length
-
inListPassiveTarget
()[source]¶ bool inListPassiveTarget()
‘InLists’ a passive target. PN532 acting as reader/initiator, peer acting as card/responder.
‘InLists’ a passive target. PN532 acting as reader/initiator, peer acting as card/responder.
true if everything executed properly, false for an error
-
mifareDebug
(enable)[source]¶ void mifareDebug(bool enable)
enable or disable debugging output for mifare related operations
enable: true to enabloe debug output, false to disable
-
mifareclassic_AuthenticateBlock
(uid, uidLen, blockNumber, keyNumber, keyData)[source]¶ bool mifareclassic_AuthenticateBlock(uint8_t *uid, uint8_t uidLen, uint32_t blockNumber, uint8_t keyNumber, uint8_t *keyData)
tries to authenticate a block of memory on a MIFARE card using the INDATAEXCHANGE command. See section 7.3.8 of the PN532 User Manual for more information on sending MIFARE and other commands.
uid: Pointer to a byte array containing the card UID
uidLen: The length (in bytes) of the card’s UID (Should be 4 for MIFARE Classic)
blockNumber: The block number to authenticate. (0..63 for 1KB cards, and 0..255 for 4KB cards).
keyNumber: Which key type to use during authentication (0 = MIFARE_CMD_AUTH_A, 1 = MIFARE_CMD_AUTH_B)
keyData: Pointer to a byte array containing the 6 byte key value
true if everything executed properly, false for an error Tries to authenticate a block of memory on a MIFARE card using the INDATAEXCHANGE command. See section 7.3.8 of the PN532 User Manual for more information on sending MIFARE and other commands.
uid: Pointer to a byte array containing the card UID
uidLen: The length (in bytes) of the card’s UID (Should be 4 for MIFARE Classic)
blockNumber: The block number to authenticate. (0..63 for 1KB cards, and 0..255 for 4KB cards).
keyNumber: Which key type to use during authentication (0 = MIFARE_CMD_AUTH_A, 1 = MIFARE_CMD_AUTH_B)
keyData: Pointer to a byte array containing the 6 byte key value
1 if everything executed properly, 0 for an error
-
mifareclassic_FormatNDEF
()[source]¶ bool mifareclassic_FormatNDEF(void)
formats a Mifare Classic card to store NDEF Records
true if everything executed properly, false for an error Formats a Mifare Classic card to store NDEF Records
1 if everything executed properly, 0 for an error
-
mifareclassic_IsFirstBlock
(uiBlock)[source]¶ bool mifareclassic_IsFirstBlock(uint32_t uiBlock)
Indicates whether the specified block number is the first block in the sector (block 0 relative to the current sector)
true if it’s the first block, false otherwise Indicates whether the specified block number is the first block in the sector (block 0 relative to the current sector)
-
mifareclassic_IsTrailerBlock
(uiBlock)[source]¶ bool mifareclassic_IsTrailerBlock(uint32_t uiBlock)
indicates whether the specified block number is the sector trailer
true if it’s the trailer block, false otherwise Indicates whether the specified block number is the sector trailer
-
mifareclassic_ReadDataBlock
(blockNumber, data)[source]¶ bool mifareclassic_ReadDataBlock(uint8_t blockNumber, uint8_t *data)
tries to read an entire 16-byte data block at the specified block address.
blockNumber: The block number to read (0..63 for 1KB cards, and 0..255 for 4KB cards).
data: Pointer to the byte array that will hold the retrieved data (if any)
true if everything executed properly, false for an error Tries to read an entire 16-byte data block at the specified block address.
blockNumber: The block number to authenticate. (0..63 for 1KB cards, and 0..255 for 4KB cards).
data: Pointer to the byte array that will hold the retrieved data (if any)
1 if everything executed properly, 0 for an error
-
mifareclassic_WriteDataBlock
(blockNumber, data)[source]¶ bool mifareclassic_WriteDataBlock(uint8_t blockNumber, uint8_t *data)
tries to write an entire 16-byte data block at the specified block address.
blockNumber: The block number to write. (0..63 for 1KB cards, and 0..255 for 4KB cards).
data: The byte array that contains the data to write.
true if everything executed properly, false for an error Tries to write an entire 16-byte data block at the specified block address.
blockNumber: The block number to authenticate. (0..63 for 1KB cards, and 0..255 for 4KB cards).
data: The byte array that contains the data to write.
1 if everything executed properly, 0 for an error
-
mifareclassic_WriteNDEFURI
(sectorNumber, uriIdentifier, url)[source]¶ bool mifareclassic_WriteNDEFURI(uint8_t sectorNumber, NDEF_URI_T uriIdentifier, const char *url)
writes an NDEF URI Record to the specified sector (1..15)
Note that this function assumes that the Mifare Classic card is already formatted to work as an “NFC Forum Tag” and uses a MAD1 file system. You can use the NXP TagWriter app on Android to properly format cards for this.
sectorNumber: The sector that the URI record should be written to (can be 1..15 for a 1K card)
uriIdentifier: The uri identifier code (one of the NDEF_URI_T values
url: the uri text to write (max 38 characters).
true if everything executed properly, false for an error Writes an NDEF URI Record to the specified sector (1..15)
Note that this function assumes that the Mifare Classic card is already formatted to work as an “NFC Forum Tag” and uses a MAD1 file system. You can use the NXP TagWriter app on Android to properly format cards for this.
sectorNumber: The sector that the URI record should be written to (can be 1..15 for a 1K card)
uriIdentifier: The uri identifier code (0 = none, 0x01 = “http://www.”, etc.)
url: The uri text to write (max 38 characters).
1 if everything executed properly, 0 for an error
-
ntag2xx_ReadPage
(page, buffer)[source]¶ bool ntag2xx_ReadPage(uint8_t page, uint8_t *buffer)
read an entire 4-byte page at the specified address
page: The page number (0..63 in most cases)
buffer: Pointer to the byte array that will hold the retrieved data (if any)
true if everything executed properly, false for an error Tries to read an entire 4-byte page at the specified address.
page: The page number (0..63 in most cases)
buffer: Pointer to the byte array that will hold the retrieved data (if any)
-
ntag2xx_WriteNDEFURI
(uriIdentifier, url, dataLen)[source]¶ bool ntag2xx_WriteNDEFURI(NDEF_URI_T uriIdentifier, char *url, uint8_t dataLen)
writes an NDEF URI Record starting at the specified page (4..nn)
Note that this function assumes that the NTAG2xx card is already formatted to work as an “NFC Forum Tag”.
uriIdentifier: The uri identifier code (one of the NDEF_URI_T values
url: The uri text to write (null-terminated string).
dataLen: The size of the data area for overflow checks.
true if everything executed properly, false for an error Writes an NDEF URI Record starting at the specified page (4..nn)
Note that this function assumes that the NTAG2xx card is already formatted to work as an “NFC Forum Tag”.
uriIdentifier: The uri identifier code (0 = none, 0x01 = “http://www.”, etc.)
url: The uri text to write (null-terminated string).
dataLen: The size of the data area for overflow checks.
1 if everything executed properly, 0 for an error
-
ntag2xx_WritePage
(page, data)[source]¶ bool ntag2xx_WritePage(uint8_t page, uint8_t *data)
write an entire 4-byte page at the specified block address
page: The page number to write. (0..63 for most cases)
data: The byte array that contains the data to write. Should be exactly 4 bytes long.
true if everything executed properly, false for an error Tries to write an entire 4-byte page at the specified block address.
page: The page number to write. (0..63 for most cases)
data: The byte array that contains the data to write. Should be exactly 4 bytes long.
1 if everything executed properly, 0 for an error
-
pn532Debug
(enable)[source]¶ void pn532Debug(bool enable)
enable or disable debugging output for pn532 related operations
enable: true to enabloe debug output, false to disable
-
readPassiveTargetID
(cardbaudrate, uid, uidLength, timeout)[source]¶ bool readPassiveTargetID(BAUD_T cardbaudrate, uint8_t *uid, uint8_t *uidLength, uint16_t timeout)
waits for an ISO14443A target to enter the field
cardbaudrate: baud rate of the card, one of the BAUD_T values
uid: Pointer to the array that will be populated with the cards UID, up to 7 bytes
uidLength: Pointer to the variable that will hold the length of the card’s UID.
timeout: the number of milliseconds to wait
true if everything executed properly, false for an error Waits for an ISO14443A target to enter the field
cardBaudRate: Baud rate of the card
uid: Pointer to the array that will be populated with the card’s UID (up to 7 bytes)
uidLength: Pointer to the variable that will hold the length of the card’s UID.
1 if everything executed properly, 0 for an error
-
sendCommandCheckAck
(cmd, cmdlen, timeout=1000)[source]¶ bool sendCommandCheckAck(uint8_t *cmd, uint8_t cmdlen, uint16_t timeout=1000)
Sends a command and waits a specified period for the ACK.
sends a command and waits a specified period for the ACK
cmd: Pointer to the command buffer
cmdlen: the size of the command in bytes
timeout: timeout before giving up (in ms)
true if everything is OK, false if timeout occurred before an ACK was received
cmd: Pointer to the command buffer
cmdlen: The size of the command in bytes
timeout: timeout before giving up
1 if everything is OK, 0 if timeout occurred before an ACK was received
-
setPassiveActivationRetries
(maxRetries)[source]¶ bool setPassiveActivationRetries(uint8_t maxRetries)
sets the MxRtyPassiveActivation byte of the RFConfiguration register. By default the pn532 will retry indefinitely.
maxRetries: 0xFF to wait forever, 0x00..0xFE to timeout after maxRetries. 0x00 means try once, with no retries on failure.
true if everything executed properly, false for an error Sets the MxRtyPassiveActivation byte of the RFConfiguration register
maxRetries: 0xFF to wait forever, 0x00..0xFE to timeout after mxRetries
1 if everything executed properly, 0 for an error
-