这是一个(好评如潮的)开源项目。只要看看源代码,例如如果你使用MFRC522.cpp的MIFARE_Read函数
MFRC522::StatusCode MFRC522::MIFARE_Read( byte blockAddr, ///< MIFARE Classic: The block (0-0xff) number. MIFARE Ultralight: The first page to return data from.
byte *buffer, ///< The buffer to store the data in
byte *bufferSize ///< Buffer size, at least 18 bytes. Also number of bytes returned if STATUS_OK.
) {
MFRC522::StatusCode result;
// Sanity check
if (buffer == NULL || *bufferSize < 18) {
return STATUS_NO_ROOM;
}
// Build command buffer
buffer[0] = PICC_CMD_MF_READ;
buffer[1] = blockAddr;
// Calculate CRC_A
result = PCD_CalculateCRC(buffer, 2, &buffer[2]);
if (result != STATUS_OK) {
return result;
}
// Transmit the buffer and receive the response, validate CRC_A.
return PCD_TransceiveData(buffer, 4, buffer, bufferSize, NULL, 0, true);
} // End MIFARE_Read()
你可以看到函数PCD_TransceiveData被调用并检查这个函数的来源:
/**
* Executes the Transceive command.
* CRC validation can only be done if backData and backLen are specified.
*
* @return STATUS_OK on success, STATUS_??? otherwise.
*/
MFRC522::StatusCode MFRC522::PCD_TransceiveData( byte *sendData, ///< Pointer to the data to transfer to the FIFO.
byte sendLen, ///< Number of bytes to transfer to the FIFO.
byte *backData, ///< NULL or pointer to buffer if data should be read back after executing the command.
byte *backLen, ///< In: Max number of bytes to write to *backData. Out: The number of bytes returned.
byte *validBits, ///< In/Out: The number of valid bits in the last byte. 0 for 8 valid bits. Default NULL.
byte rxAlign, ///< In: Defines the bit position in backData[0] for the first bit received. Default 0.
bool checkCRC ///< In: True => The last two bytes of the response is assumed to be a CRC_A that must be validated.
) {
byte waitIRq = 0x30; // RxIRq and IdleIRq
return PCD_CommunicateWithPICC(PCD_Transceive, waitIRq, sendData, sendLen, backData, backLen, validBits, rxAlign, checkCRC);
} // End PCD_TransceiveData()
您可以调用PCD_TransceiveData 或PCD_CommunicateWithPICC 函数。
更新
您为参数设置了 0 个值:“backData”、“backLen”和“validBits”。
validBits 可以为空。
backData 和 backLen 必须定义为字节。
更新2
如果您查看库 support protocols 它支持 ISO/IEC 14443-3(A 型)而不支持 ISO/IEC 14443-4(B 型)。
如果你看看Android HCE documentation:
具体来说,Android 4.4 支持模拟基于
NFC-Forum ISO-DEP 规范(基于 ISO/IEC 14443-4)和
处理应用协议数据单元 (APDU),如
ISO/IEC 7816-4 规范。 Android 要求仅模拟 ISO-DEP
在 Nfc-A(ISO/IEC 14443-3 A 型)技术之上。支持
Nfc-B(ISO/IEC 14443-4 Type B)技术是可选的。的层次感
所有这些规格如图3所示
在这篇文章中:HCE support for ISO/IEC 14443-3 Type B?
查看现场设备,一些设备使用 A 型用于 HCE 和
有些似乎使用 B 型。所以基本上是设备制造商
决定是使用 A 型还是 B 型。 Android API 不提供任何手段
让应用开发者对此施加影响。
因此,如果您的设备模拟 ISO/IEC 14443-3(A 类)或 ISO/IEC 14443-4(B 类),您必须检查其他 Android NFC 设备。您可以在其他安卓设备上使用NfcTagInfo application 来检查。