简体   繁体   English

在Android中同时读取多个NFC标签

[英]Reading multiple NFC tags simultaneously in Android

The new 2.3.3 SDK includes improved NFC support, and I'd like to write an app that relies on this. 新的2.3.3 SDK包括改进的NFC支持,我想编写一个依赖于此的应用程序。 Ultimately, I'd like to be able to read data from multiple tags that enter the field simultaneously, but Android only seems to trigger on the first one that enters the field - subsequent ones are ignored. 最后,我希望能够从同时进入该字段的多个标签中读取数据,但Android似乎仅在第一个进入该字段的标签上触发 - 后续的被忽略。

From reading the NFC spec (ISO/IEC 14443-3) for the tags I'm using (Mifare Classic), I should be able to send a 'halt' command to the tag, which will cause it to stop responding, and allow me to read the next tag in the field. 从阅读NFC规范(ISO / IEC 14443-3)我正在使用的标签(Mifare Classic),我应该能够向标签发送'halt'命令,这将导致它停止响应,并允许我要阅读该字段中的下一个标记。 Android doesn't support the halt command directly on any of the TagTechnology subclasses, so I tried sending it myself directly using transceive(new byte[] {0x50, 0x00}) . Android不直接在任何TagTechnology子类上支持halt命令,所以我尝试使用transceive(new byte[] {0x50, 0x00})直接发送它。 This throws an IOException , with the message 'transceive failed'. 这会抛出IOException ,并显示消息“收发失败”。

Admittedly I'm doing all this from the main thread, which I understand is a bad idea, but I just want to test the concept as easily as possible. 不可否认,我正在从主线程中完成所有这些,我理解这是一个坏主意,但我只想尽可能轻松地测试这个概念。

Is it possible to communicate with multiple tags in the field at the same time? 是否可以同时与现场的多个标签进行通信? What am I doing wrong? 我究竟做错了什么?

What you want is unfortunately not possible at the moment, unless you do some pretty advanced hackery, which is almost never a good idea :) 不幸的是,你想要的是不可能的,除非你做一些非常先进的hackery,这几乎不是一个好主意:)

Probably you could halt the card if you send the right bytes in the transceive() , as you're trying to do now. 如果你在transceive()发送正确的字节,你可能会暂停卡,正如你现在要做的那样。 But since the halt (or rather, the HLTA which you're trying to send) is an ISO14443-3A command, this will not work through the MifareClassic interface - which uses an "encrypted" pipe. 但是,由于停止(或者更确切地说,您尝试发送的HLTA)是ISO14443-3A命令,这将无法通过MifareClassic接口 - 它使用“加密”管道。 Directly transmitting over the NfcA interface unfortunately doesn't work with the current stack either. 不幸的是,通过NfcA接口直接传输也不适用于当前的堆栈。

Even if you could get the card to halt, this will not automatically cause the NFC chip in the phone to resume polling for new tags - since you are "going around" the stack. 即使您可以让卡停止,这也不会自动导致手机中的NFC芯片恢复轮询新标签 - 因为您正在“绕过”堆栈。

Depending on my short experience you can not work with multiple tags. 根据我的短暂经验,您无法使用多个标签。 If two tags are in the field you do not receive an ID from the tag, it's binary zero. 如果字段中有两个标记,则表示您没有从标记中收到ID,它是二进制零。 So my guess is that, at this point, you can only access one tag and no more than one can be in the field. 所以我的猜测是,在这一点上,你只能访问一个标签,并且在该字段中只能有一个标签。

Have you had success sending other commands using transceive such as read block (0x30, 0x(block)) or authenticate sector commands? 您是否成功使用收发器发送其他命令,如读取块(0x30,0x(块))或验证扇区命令? Just thinking you might want to be sure you're using transceive correctly in the first place. 只是想你可能想要确保你首先正确使用收发器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM