我正在读取 RFID 卡并尝试比较 ID,因为一旦卡通过读卡器,读卡器实际上会多次读取它,所以我需要丢弃重复项。
更新:以下代码获取卡 ID
uint32_t IndentifyTag(Adafruit_PN532 rfidReader)
{
uint8_t tagID[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID
uint8_t tagIDLength; // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
uint32_t cardid = tagID[0];
boolean success = rfidReader.readPassiveTargetID(PN532_MIFARE_ISO14443A, &tagID[0], &tagIDLength);
if (success) {
// Display some basic information about the card for testing
Serial.println("Found an ISO14443A card");
Serial.print(" UID Length: "); Serial.print(tagIDLength, DEC); Serial.println(" bytes");
Serial.print(" UID Value: "); rfidReader.PrintHex(tagID, tagIDLength);
if (tagIDLength == 4)
{
// Mifare Classic card
cardid <<= 8;
cardid |= tagID[1];
cardid <<= 8;
cardid |= tagID[2];
cardid <<= 8;
cardid |= tagID[3];
Serial.print("Mifare Classic card #");
Serial.println(cardid);
}
Serial.println("");
}
return cardid;
}
在 switch 语句的情况下,我正在测试标签是否相等,如下所示:
uint32_t priorTag = 0000000;
tag = IndentifyTag(entryRFIDReader);
if (tag == priorTag)
{
Serial.println("These tags are the same!!!");
}
if (tag != priorTag)
{
Serial.println("I got here!");
tagCount += 1;
}
priorTag = tag;
SSerial.println("tagCount = "); Serial.println(tagCount);
问题是,即使读卡器一次读取同一张卡 3 或 4 次,它们也永远不会相等,因此 tagCounter 正在计算被骗者。tag 和priorTag 都是uint32_t 类型,因此应该与== 相当,但它在这种情况下不起作用。
找到一张 ISO14443A 卡 UID 长度:4 个字节 UID 值:0x92 0x77 0x88 0xBB Mifare 经典卡 #7833787 我去那里! 标签计数 = 1 找到一张 ISO14443A 卡 UID 长度:4 个字节 UID 值:0x92 0x77 0x88 0xBB Mifare 经典卡 #7833787 我去那里! 标签计数 = 2 找到一张 ISO14443A 卡 Mifare 经典卡 #7833787 我去那里! 标签计数 = 3 找到一张 ISO14443A 卡 Mifare 经典卡 #7833787 我去那里! 标签计数 = 4