0

我正在使用 Arduino Uno 和 adaFruit PN532 板。目标是能够创建当前在 NFC Shield 范围内的 MiFare 卡列表。

我无法找出编写此逻辑的最佳方法,因为电路板似乎每个循环只能检测到一张卡。

我可以在板上放两张​​牌,它可以同时看到它们,但每个循环只能看到一张。那么我将如何创建当前范围内的当前列表

我的循环:

 void loop()
{

  Serial.println("--------------------Loop begin-------------------");
  uint8_t success;
  uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };  // Buffer to store the returned UID
  uint8_t uidLength;                        // Length of the UID (4 or 7 bytes depending on ISO14443A card type)

  uint8_t index =0;  
  // Wait for an ISO14443A type cards (Mifare, etc.).  When one is found
  // 'uid' will be populated with the UID, and uidLength will indicate
  // if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight)
  success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);

   if (success) {

    // Display some basic information about the card
    Serial.println("Found an ISO14443A card");
    Serial.print("  UID Length: ");Serial.print(uidLength, DEC);Serial.println(" bytes");
    Serial.print("  UID Value: ");
    nfc.PrintHex(uid, uidLength);
    Serial.println("");

  }

   Serial.println("************************Loop END*********************");
}

当两张卡都在范围内时,这是串行监视器:

--------------------循环开始--------

找到一张 ISO14443A 卡
UID 长度:4 字节
UID 值:0x13 0x99 0x1C 0xD4

************************循环结束************************

--------------------循环开始-------------------
找到一个 ISO14443A 卡
UID 长度:4 字节
UID 值:0x13 0x34 0x27 0xD4

************************循环结束************************

4

1 回答 1

0

您需要在循环之外的一些状态(类似于具有 ID 和长度字段的结构数组)来存储您的(可能是多个)UID。查看 readPassiveTargetID的代码,我认为如果有多个卡 ID,则返回哪个卡 ID 可能有点随机。

我想您需要继续阅读 ID,检查数组以查看您之前是否看过它,如果没有,则将其存储。然后在一段时间后(或数组溢出,或其他一些触发器),您可以打印出您“最近”看到的 ID,并将数组重置为空(例如,通过清除长度字段)

于 2014-09-04T09:24:05.323 回答