ACR122u直接通讯无响应

时间:2014-07-15 12:19:44

标签: java nfc communication acr122

我正在尝试通过发送直接命令来访问我的ACR122u。奇怪的是我没有得到任何回应,没有错误..这是我的代码:

final static int IOCTL_SMARTCARD_ACR122_ESCAPE_COMMAND = 0x003136B0;

.....

List<CardTerminal>  terminals   = null; 
TerminalFactory factory         = TerminalFactory.getDefault();
terminals                       = factory.terminals().list();

CardTerminal terminal   = terminals.get(0);
Card card               = terminal.connect("direct");

CardChannel channel     = card.getBasicChannel();

byte[] commandAPDU      = {(byte) 0xD4, 0x06, 0x63, 0x05, 0x63, 0x0D, 0x63, 0x38 }; 
byte[] responseAPDU     = card.transmitControlCommand(IOCTL_SMARTCARD_ACR122_ESCAPE_COMMAND, commandAPDU );             

System.out.println(bytesToHex(responseAPDU) + "...");

有没有人知道这种情况的原因?

非常感谢提前!

1 个答案:

答案 0 :(得分:1)

最后,我有解决方案。如果有其他人遇到同样的问题,我会回答我自己的问题。

错误是我只在这里发送消息。使用new CommandAPDU(),您已经定义了Class,INS,P1,P2。除此之外,您不需要定义Lc because javac will do this for us。使用transmitControlCommand,您需要定义Lc。因此,有了这些知识,新的(工作)代码就是:

List<CardTerminal>  terminals   = null; 
TerminalFactory factory         = TerminalFactory.getDefault();
terminals                       = factory.terminals().list();

CardTerminal terminal   = terminals.get(0);
Card card               = terminal.connect("direct");

CardChannel channel     = card.getBasicChannel();

//Read register
byte[] commandAPDU1     = {(byte)0xFF,0x00,0x00,0x00,0x08,  (byte)0xD4, 0x06, 0x63, 0x05, 0x63, 0x0D, 0x63, 0x38 }; 
byte[] responseAPDU1    = card.transmitControlCommand(IOCTL_SMARTCARD_ACR122_ESCAPE_COMMAND, commandAPDU1 );                

System.out.println(bytesToHex(responseAPDU1) + "...");
//Response: D5070707059000...