如何重新连接到 IsoDep 标签? [英] How can I reconnect to IsoDep tag?

查看:71
本文介绍了如何重新连接到 IsoDep 标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一些 apdu 命令从 android 手机发送到 nfc 标签并获得答案.使用的技术类型是 IsoDep.一切正常,但有时,当发送命令之间的时间过长时,标签会切换到禁用状态,之后每次重新连接都会失败.

I'm trying to send some apdu commands from android phone to the nfc tag and get answers. The type of used technology is IsoDep. Everything works fine, but sometimes, when the time between sending commands is too large, the tag switches to the disabled state and after that every reconnection fails.

我的代码:

public byte[] transferCommand(byte[] command) throws Exception {
        byte[] result = null;
        if (iso == null)   {
            iso = IsoDep.get(tag);
            iso.connect();
        }
        if (!iso.isConnected()) {
            try {
                iso.close();
                iso.connect();
                result = iso.transceive(command);
            } catch (Exception ex) {
                iso.close();
            }
        }            
        return result;
    }

有人可以帮我吗?非常感谢.

Could anybody help me please? Thank so much.

推荐答案

connect 和相关命令只是管理到标签的逻辑连接.也就是说:它们授予您的线程和应用程序对标记对象的独占访问权限.他们不会对物理标签连接做任何事情.(至少据我所知,距离我上次阅读 NfcService 代码已经有一段时间了).

The connect and related commands are just managing a logical connection to the tag. That is: They grant your thread and application exclusive access to the tag object. They don't do anything with the physical tag connection. (At least as far as I know, it's been a while since I last read the NfcService code).

因此,一旦标签停止响应您的请求,连接和重新连接将无济于事.在这种情况下,您所能做的就是物理移除标签并再次将其呈现给阅读器.

Therefore connecting and reconnecting will not help you once a tag stops to answer to your requests. All you can do in this case is to physically remove the tag and present it to the reader again.

如果您遇到超时问题,请尝试通过在标记对象上调用 setTimeout 来提高超时值.

If you run into timeout problems try raising the timeout value by calling setTimeout on the tag object.

这篇关于如何重新连接到 IsoDep 标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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