[ACR122U命令重新连接后会失败,除非我等待2秒钟

问题描述 投票:1回答:1

当命令失败并重新连接后,尝试运行命令时,ACR122U阅读器出现问题。例如,以下面的代码检测连接标签的类型:

private CardTerminal terminal; //ACR1222L or ACR122U
...
private void detectTagType(timeout: Long)
{        
    terminal.waitForCardPresent(timeout);
    Card card = terminal.connect("*")
    // Check the ATR bytes for ultralight values
    if (isUltralight(card.getATR().getBytes()))
    {
        try
        {
            // Runs the native GET_VERSION command (0x60)
            byte[] version = getDesfireVersion(card);
            // Check the version bytes for EV1 values
            if (isUltralightEV1(version))
            {
                // Is an ultralight ev1
            }
            else
            {
                // Another tag
            }
        }
        catch (MyNFCException exception)
        {
            // Possible UltralightC since it does not support the GET_VERSION command            
            // Reconnect to tag to wake up from failed command
            card.disconnect(true)
            Card cardC = terminal.connect("*") 

            // The code works if I add Thread.sleep(2000); here            

            // Try running the AUTHENTICATE command (0x1A) as explained here http://stackoverflow.com/questions/11897813/distinguish-mifare-ultralight-from-mifare-ultralight-c
            if (tryRunUltralighcAuthenticateCommand(cardC))
            {
                // Is an ultralight C
            }
            else
            {
                // Unkonwn tag
            }
        }
}

// The following methods run the corresponding native commands wrapping them 
// as described here https://stackoverflow.com/questions/42542610/authenticating-ultralight-ev1-with-pc-sc-reader/42563617#42563617. 
// (Wrapping with them with the InCommunicateThru and the correct header depending on the reader, 
// i.e. {0xE0, 0x00, 0x00, 0x24, 0x00} for the ACR1222L and {0xFF, 0x00, 0x00, 0x00, 0x00} for the ACR122U)

private byte[] getDesfireVersion(Card card) throws MyNFCException 
{
    // Runs the GET_VERSION command and returns the bytes returned by the tag. 
    // If the tag does not support the command raises a MyNFCException 
}

private boolean tryRunUltralightcAuthenticateCommand(Card card)
{
    // Runs the Ultralight C AUTHENTICATE command (0x1A) and returns true if it succeeds and false if it fails
}

[当我使用Ultralight C标签和ACR122U阅读器通过AUTHENTICATE命令(tryRunUltralighccAuthenticateCommand)测试此代码时,结果为{D5 43 01}(即超时)。但是,如果我使用ACR1222L阅读器和相同的标签运行相同的代码,则它可以按预期工作,即命令成功。此外,如果我在重新连接后强制我的程序等待2秒钟(使用Thread.sleep(2000)),它也可以按预期与ACR122U阅读器一起使用(但这显然不是解决方案)。

任何带有任何标签的命令失败后,我都会得到相同的行为。例如,如果我尝试使用错误的密码对Ultralight EV1进行身份验证,请重新连接,然后运行任何命令,它将与ACR1222L阅读器配合使用,但将在ACR122U上失败,并显示代码{D5 43 01}(除非我为重新连接后2秒)。

我尝试断开连接而不重设标签(card.disconnect(false))并且完全不重新连接(在这种情况下,失败的命令后会出现CRC错误{D5 43 02})。

我缺少什么吗?或除了每次重新连接后将我的线程休眠2秒之外,其他解决此问题的方法?

java nfc mifare apdu pcsc
1个回答
0
投票

这是ACS驱动程序的限制/设计;它是如何工作的。我还没有找到解决这个问题的方法。

© www.soinside.com 2019 - 2024. All rights reserved.