gpt4 book ai didi

java - ACR122u直接通讯无响应

转载 作者:行者123 更新时间:2023-11-30 11:16:40 24 4
gpt4 key购买 nike

我正在尝试通过发送直接命令使用 java 访问我的 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) + "...");

请问有大佬知道是什么原因造成的吗

非常感谢!

最佳答案

终于,我找到了解决方案。我会回答我自己的问题,以防其他人遇到同样的问题。

错误是我只在这里发送消息。使用 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...

关于java - ACR122u直接通讯无响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24758072/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com