ACR122u direct communication no response

南楼画角 提交于 2019-12-19 10:25:25

问题


I'm trying to access my ACR122u with java by sending direct command. The weird thing is i don't get any response and no errors.. This is my code:

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) + "...");

Is there anyone who knows the cause of this situation?

Many thanks in advance!


回答1:


Finally, i have the solution. I will answer my own question in case there are other people with the same problem.

The fault was that i only send the message here. With new CommandAPDU() you already define the Class,INS, P1, P2. Besides that you don't need to define the Lc because javac will do this for us. With transmitControlCommand you do need to define the Lc. So with this knowledge the new (working) code is:

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...


来源:https://stackoverflow.com/questions/24758072/acr122u-direct-communication-no-response

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!