PN532仿真卡无法被Android手机读取 [英] PN532 emulated card not read by an Android phone

查看:158
本文介绍了PN532仿真卡无法被Android手机读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将 Arduino UNO elechouse的库 SPI 连接的> PN532 模块.

I am using Arduino UNO with elechouse's library and a PN532 module connected through SPI.

我正在尝试使用该库中的 emulate_tag_ndef 示例来模拟卡,但是当我尝试使用 NFC Tools应用程序在上读取模拟卡时>三星Galaxy S7 ,我得到一个空序列号,却没有得到 Ndef 消息,类似于

I am trying to emulate a card using the emulate_tag_ndef example in that library, but when I try to read the emulated card with the NFC Tools app on my Samsung Galaxy S7, I get an empty serial number and I don't get the Ndef message similarly to this.

当我尝试根据 Github 上所链接问题的下方文章更改库中的命令数组时,我的手机根本无法检测到仿真卡.

When I try to change the command array in the library according to the post lower on the linked issue on Github, then the emulated card cannot be detected by my phone at all.

PN532 适用于所有其他 NFC 模式(读/写,对等).

The PN532 works in all other NFC modes (read/write, peer-to-peer) all right for me.

推荐答案

就像我所做的那样取消一些注释,它应该可以工作.

just uncomment some stuff like I did and it should work.

void setup()
{
Serial.begin(115200);
Serial.println("------- Emulate Tag --------");

message = NdefMessage();
message.addUriRecord("http://www.elechouse.com");
messageSize = message.getEncodedSize();
if (messageSize > sizeof(ndefBuf)) {
  Serial.println("ndefBuf is too small");
  while (1) { }
}

Serial.print("Ndef encoded message size: ");
Serial.println(messageSize);

message.encode(ndefBuf);

// comment out this command for no ndef message
nfc.setNdefFile(ndefBuf, messageSize);

// uid must be 3 bytes!
nfc.setUid(uid);

nfc.init();
}

void loop(){
// uncomment for overriding ndef in case a write to this tag occured
nfc.setNdefFile(ndefBuf, messageSize); 

// start emulation (blocks)
nfc.emulate();

// or start emulation with timeout
if(!nfc.emulate(1000)){ // timeout 1 second
  Serial.println("timed out");
}

// deny writing to the tag
// nfc.setTagWriteable(false);

if(nfc.writeOccured()){
   Serial.println("\nWrite occured !");
   uint8_t* tag_buf;
   uint16_t length;

   nfc.getContent(&tag_buf, &length);
   NdefMessage msg = NdefMessage(tag_buf, length);
   msg.print();
}

这篇关于PN532仿真卡无法被Android手机读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆