我在尝试在失败的命令和重新连接后尝试运行命令时,我对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
}
当我使用超低c标签和ACR122U读取器测试此代码时,Authenticate命令(tryRunultralighCauthentIcateCommand(作为结果{d5 43 01}作为结果(即超时(。但是,如果我使用ACR1222L读取器运行相同的代码,并且它与预期的相同标签(即命令成功(。此外,如果我强迫我的程序等待2秒(带有thread.sleep(2000((重新连接后,它也可以按预期与ACR122U读取器一起使用(但这显然不是解决方案(。
>在任何失败命令带有任何标签后,我都会得到相同的行为。例如,如果我尝试使用错误的密码对超轻质EV1进行身份验证,请重新连接,然后运行任何命令,它将与ACR1222L读取器一起使用,但会在ACR122U上使用Code {D5 43 01}失败(除非我睡觉我的程序以使我的程序睡觉重新连接后2秒(。
我尝试断开连接而没有重置标签(card.disconnect(false((,而根本不重新连接(在这种情况下,我会在失败命令后获得CRC错误{D5 43 02}。
(。我缺少什么吗?或其他任何解决问题的方法,除了在重新连接之后睡2秒钟?
这是ACS驱动程序的限制/设计;它的工作原理。我还没有找到解决这个问题的方法。